1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
|
3 |
|
|
/**
|
4 |
|
|
* @file
|
5 |
|
|
* Defines the base query class, which is the underlying layer in a View.
|
6 |
|
|
*/
|
7 |
|
|
|
8 |
|
|
/**
|
9 |
|
|
* @defgroup views_query_plugins Views query plugins
|
10 |
|
|
* @{
|
11 |
|
|
* A Views query plugin builds SQL to execute using the Drupal database API.
|
12 |
|
|
*
|
13 |
|
|
* @see hook_views_plugins()
|
14 |
|
|
*/
|
15 |
|
|
|
16 |
|
|
/**
|
17 |
|
|
* Object used to create a SELECT query.
|
18 |
|
|
*/
|
19 |
|
|
class views_plugin_query extends views_plugin {
|
20 |
|
|
/**
|
21 |
|
|
* A pager plugin that should be provided by the display.
|
22 |
|
|
*
|
23 |
|
|
* @var views_plugin_pager
|
24 |
|
|
*/
|
25 |
|
|
var $pager = NULL;
|
26 |
|
|
|
27 |
|
|
/**
|
28 |
|
|
* Constructor; Create the basic query object and fill with default values.
|
29 |
|
|
*/
|
30 |
|
|
function init($base_table, $base_field, $options) {
|
31 |
|
|
$this->base_table = $base_table;
|
32 |
|
|
$this->base_field = $base_field;
|
33 |
|
|
$this->unpack_options($this->options, $options);
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
/**
|
37 |
|
|
* Generate a query and a countquery from all of the information supplied
|
38 |
|
|
* to the object.
|
39 |
|
|
*
|
40 |
|
|
* @param $get_count
|
41 |
|
|
* Provide a countquery if this is true, otherwise provide a normal query.
|
42 |
b08fce64
|
Assos Assos
|
*
|
43 |
|
|
* @return SelectQuery
|
44 |
|
|
* A SelectQuery object.
|
45 |
85ad3d82
|
Assos Assos
|
*/
|
46 |
|
|
function query($get_count = FALSE) { }
|
47 |
|
|
|
48 |
|
|
/**
|
49 |
|
|
* Let modules modify the query just prior to finalizing it.
|
50 |
|
|
*
|
51 |
|
|
* @param view $view
|
52 |
|
|
* The view which is executed.
|
53 |
|
|
*/
|
54 |
|
|
function alter(&$view) { }
|
55 |
|
|
|
56 |
|
|
/**
|
57 |
|
|
* Builds the necessary info to execute the query.
|
58 |
|
|
*
|
59 |
|
|
* @param view $view
|
60 |
|
|
* The view which is executed.
|
61 |
|
|
*/
|
62 |
|
|
function build(&$view) { }
|
63 |
|
|
|
64 |
|
|
/**
|
65 |
|
|
* Executes the query and fills the associated view object with according
|
66 |
|
|
* values.
|
67 |
|
|
*
|
68 |
|
|
* Values to set: $view->result, $view->total_rows, $view->execute_time,
|
69 |
|
|
* $view->pager['current_page'].
|
70 |
|
|
*
|
71 |
|
|
* $view->result should contain an array of objects. The array must use a
|
72 |
|
|
* numeric index starting at 0.
|
73 |
|
|
*
|
74 |
|
|
* @param view $view
|
75 |
|
|
* The view which is executed.
|
76 |
|
|
*/
|
77 |
|
|
function execute(&$view) { }
|
78 |
|
|
|
79 |
|
|
/**
|
80 |
|
|
* Add a signature to the query, if such a thing is feasible.
|
81 |
|
|
*
|
82 |
|
|
* This signature is something that can be used when perusing query logs to
|
83 |
|
|
* discern where particular queries might be coming from.
|
84 |
|
|
*
|
85 |
|
|
* @param view $view
|
86 |
|
|
* The view which is executed.
|
87 |
|
|
*/
|
88 |
|
|
function add_signature(&$view) { }
|
89 |
|
|
|
90 |
|
|
/**
|
91 |
|
|
* Get aggregation info for group by queries.
|
92 |
|
|
*
|
93 |
|
|
* If NULL, aggregation is not allowed.
|
94 |
|
|
*/
|
95 |
|
|
function get_aggregation_info() { }
|
96 |
|
|
|
97 |
|
|
/**
|
98 |
|
|
* Add settings for the ui.
|
99 |
|
|
*/
|
100 |
|
|
function options_form(&$form, &$form_state) {
|
101 |
|
|
parent::options_form($form, $form_state);
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
function options_validate(&$form, &$form_state) { }
|
105 |
|
|
|
106 |
|
|
function options_submit(&$form, &$form_state) { }
|
107 |
|
|
|
108 |
|
|
function summary_title() {
|
109 |
|
|
return t('Settings');
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
/**
|
113 |
|
|
* Set a LIMIT on the query, specifying a maximum number of results.
|
114 |
|
|
*/
|
115 |
|
|
function set_limit($limit) {
|
116 |
|
|
$this->limit = $limit;
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
/**
|
120 |
|
|
* Set an OFFSET on the query, specifying a number of results to skip
|
121 |
|
|
*/
|
122 |
|
|
function set_offset($offset) {
|
123 |
|
|
$this->offset = $offset;
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
/**
|
127 |
|
|
* Render the pager, if necessary.
|
128 |
|
|
*/
|
129 |
|
|
function render_pager($exposed_input) {
|
130 |
|
|
if (!empty($this->pager) && $this->pager->use_pager()) {
|
131 |
|
|
return $this->pager->render($exposed_input);
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
return '';
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
/**
|
138 |
|
|
* Create a new grouping for the WHERE or HAVING clause.
|
139 |
|
|
*
|
140 |
|
|
* @param $type
|
141 |
|
|
* Either 'AND' or 'OR'. All items within this group will be added
|
142 |
|
|
* to the WHERE clause with this logical operator.
|
143 |
|
|
* @param $group
|
144 |
|
|
* An ID to use for this group. If unspecified, an ID will be generated.
|
145 |
|
|
* @param $where
|
146 |
|
|
* 'where' or 'having'.
|
147 |
|
|
*
|
148 |
|
|
* @return $group
|
149 |
|
|
* The group ID generated.
|
150 |
|
|
*/
|
151 |
|
|
function set_where_group($type = 'AND', $group = NULL, $where = 'where') {
|
152 |
|
|
// Set an alias.
|
153 |
|
|
$groups = &$this->$where;
|
154 |
|
|
|
155 |
|
|
if (!isset($group)) {
|
156 |
|
|
$group = empty($groups) ? 1 : max(array_keys($groups)) + 1;
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
// Create an empty group
|
160 |
|
|
if (empty($groups[$group])) {
|
161 |
|
|
$groups[$group] = array('conditions' => array(), 'args' => array());
|
162 |
|
|
}
|
163 |
|
|
|
164 |
|
|
$groups[$group]['type'] = strtoupper($type);
|
165 |
|
|
return $group;
|
166 |
|
|
}
|
167 |
|
|
|
168 |
|
|
/**
|
169 |
|
|
* Control how all WHERE and HAVING groups are put together.
|
170 |
|
|
*
|
171 |
|
|
* @param $type
|
172 |
|
|
* Either 'AND' or 'OR'
|
173 |
|
|
*/
|
174 |
|
|
function set_group_operator($type = 'AND') {
|
175 |
|
|
$this->group_operator = strtoupper($type);
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
/**
|
179 |
|
|
* Returns the according entity objects for the given query results.
|
180 |
|
|
*/
|
181 |
|
|
function get_result_entities($results, $relationship = NULL) {
|
182 |
|
|
return FALSE;
|
183 |
|
|
}
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
/**
|
187 |
|
|
* @}
|
188 |
|
|
*/ |