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