commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / views / plugins / views_plugin_query.inc
1 <?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 */
43 function query($get_count = FALSE) { }
44
45 /**
46 * Let modules modify the query just prior to finalizing it.
47 *
48 * @param view $view
49 * The view which is executed.
50 */
51 function alter(&$view) { }
52
53 /**
54 * Builds the necessary info to execute the query.
55 *
56 * @param view $view
57 * The view which is executed.
58 */
59 function build(&$view) { }
60
61 /**
62 * Executes the query and fills the associated view object with according
63 * values.
64 *
65 * Values to set: $view->result, $view->total_rows, $view->execute_time,
66 * $view->pager['current_page'].
67 *
68 * $view->result should contain an array of objects. The array must use a
69 * numeric index starting at 0.
70 *
71 * @param view $view
72 * The view which is executed.
73 */
74 function execute(&$view) { }
75
76 /**
77 * Add a signature to the query, if such a thing is feasible.
78 *
79 * This signature is something that can be used when perusing query logs to
80 * discern where particular queries might be coming from.
81 *
82 * @param view $view
83 * The view which is executed.
84 */
85 function add_signature(&$view) { }
86
87 /**
88 * Get aggregation info for group by queries.
89 *
90 * If NULL, aggregation is not allowed.
91 */
92 function get_aggregation_info() { }
93
94 /**
95 * Add settings for the ui.
96 */
97 function options_form(&$form, &$form_state) {
98 parent::options_form($form, $form_state);
99 }
100
101 function options_validate(&$form, &$form_state) { }
102
103 function options_submit(&$form, &$form_state) { }
104
105 function summary_title() {
106 return t('Settings');
107 }
108
109 /**
110 * Set a LIMIT on the query, specifying a maximum number of results.
111 */
112 function set_limit($limit) {
113 $this->limit = $limit;
114 }
115
116 /**
117 * Set an OFFSET on the query, specifying a number of results to skip
118 */
119 function set_offset($offset) {
120 $this->offset = $offset;
121 }
122
123 /**
124 * Render the pager, if necessary.
125 */
126 function render_pager($exposed_input) {
127 if (!empty($this->pager) && $this->pager->use_pager()) {
128 return $this->pager->render($exposed_input);
129 }
130
131 return '';
132 }
133
134 /**
135 * Create a new grouping for the WHERE or HAVING clause.
136 *
137 * @param $type
138 * Either 'AND' or 'OR'. All items within this group will be added
139 * to the WHERE clause with this logical operator.
140 * @param $group
141 * An ID to use for this group. If unspecified, an ID will be generated.
142 * @param $where
143 * 'where' or 'having'.
144 *
145 * @return $group
146 * The group ID generated.
147 */
148 function set_where_group($type = 'AND', $group = NULL, $where = 'where') {
149 // Set an alias.
150 $groups = &$this->$where;
151
152 if (!isset($group)) {
153 $group = empty($groups) ? 1 : max(array_keys($groups)) + 1;
154 }
155
156 // Create an empty group
157 if (empty($groups[$group])) {
158 $groups[$group] = array('conditions' => array(), 'args' => array());
159 }
160
161 $groups[$group]['type'] = strtoupper($type);
162 return $group;
163 }
164
165 /**
166 * Control how all WHERE and HAVING groups are put together.
167 *
168 * @param $type
169 * Either 'AND' or 'OR'
170 */
171 function set_group_operator($type = 'AND') {
172 $this->group_operator = strtoupper($type);
173 }
174
175 /**
176 * Returns the according entity objects for the given query results.
177 */
178 function get_result_entities($results, $relationship = NULL) {
179 return FALSE;
180 }
181 }
182
183 /**
184 * @}
185 */