entity_views_example_query.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. * @file
  4. * Contains an example for a Views query plugin that could use the data selection tables.
  5. */
  6. /**
  7. * Describes the additional methods looked for on a query plugin if data selection based tables or fields are used.
  8. *
  9. * Only get_result_entities() needs to be present, so results can be retrieved.
  10. * The other methods are optional.
  11. *
  12. * If the table does not contain entities, however, the get_result_wrappers()
  13. * method is necessary, too. If this is the case and there are no relations to
  14. * entity tables, the get_result_entities() method is not needed.
  15. *
  16. * @see entity_views_table_definition()
  17. */
  18. abstract class entity_views_example_query extends views_plugin_query {
  19. /**
  20. * Add a sort to the query.
  21. *
  22. * This is used to add a sort based on an Entity API data selector instead
  23. * of a field alias.
  24. *
  25. * This method has to be present if click-sorting on fields should be allowed
  26. * for some fields using the default Entity API field handlers.
  27. *
  28. * @param $selector
  29. * The field to sort on, as an Entity API data selector.
  30. * @param $order
  31. * The order to sort items in - either 'ASC' or 'DESC'. Defaults to 'ASC'.
  32. */
  33. public abstract function add_selector_orderby($selector, $order = 'ASC');
  34. /**
  35. * Returns the according entity objects for the given query results.
  36. *
  37. * This is compatible to the get_result_entities() method used by Views.
  38. *
  39. * The method is responsible for resolving the relationship and returning the
  40. * entity objects for that relationship. The helper methods
  41. * EntityFieldHandlerHelper::construct_property_selector() and
  42. * EntityFieldHandlerHelper::extract_property_multiple() can be used to do
  43. * this.
  44. *
  45. * @param $results
  46. * The results of the query, as returned by this query plugin.
  47. * @param $relationship
  48. * (optional) A relationship for which the entities should be returned.
  49. * @param $field
  50. * (optional) The field for which the entity should be returned. This is
  51. * only needed in case a field is derived via a referenced entity without
  52. * using a relationship. For example, if the node's field "author:name" is
  53. * used, the user entity would be returned instead of the node entity.
  54. *
  55. * @return
  56. * A numerically indexed array containing two items: the entity type of
  57. * entities returned by this method; and the array of entities, keyed by the
  58. * same indexes as the results.
  59. *
  60. * @see EntityFieldHandlerHelper::extract_property_multiple()
  61. */
  62. public abstract function get_result_entities($results, $relationship = NULL, $field = NULL);
  63. /**
  64. * Returns the according metadata wrappers for the given query results.
  65. *
  66. * This can be used if no entities for the results can be given, but entity
  67. * metadata wrappers can be constructed for them.
  68. *
  69. * @param $results
  70. * The results of the query, as returned by this query plugin.
  71. * @param $relationship
  72. * (optional) A relationship for which the wrappers should be returned.
  73. * @param $field
  74. * (optional) The field of which a wrapper should be returned.
  75. *
  76. * @return
  77. * A numerically indexed array containing two items: the data type of
  78. * the wrappers returned by this method; and the array of retrieved
  79. * EntityMetadataWrapper objects, keyed by the same indexes as the results.
  80. */
  81. public abstract function get_result_wrappers($results, $relationship = NULL, $field = NULL);
  82. }