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