5 * Defines the base query class, which is the underlying layer in a View.
9 * @defgroup views_query_plugins Views query plugins
11 * A Views query plugin builds SQL to execute using the Drupal database API.
13 * @see hook_views_plugins()
17 * Object used to create a SELECT query.
19 class views_plugin_query extends views_plugin {
21 * A pager plugin that should be provided by the display.
23 * @var views_plugin_pager
28 * Constructor; Create the basic query object and fill with default values.
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);
37 * Generate a query and a countquery from all of the information supplied
41 * Provide a countquery if this is true, otherwise provide a normal query.
43 function query($get_count = FALSE) { }
46 * Let modules modify the query just prior to finalizing it.
49 * The view which is executed.
51 function alter(&$view) { }
54 * Builds the necessary info to execute the query.
57 * The view which is executed.
59 function build(&$view) { }
62 * Executes the query and fills the associated view object with according
65 * Values to set: $view->result, $view->total_rows, $view->execute_time,
66 * $view->pager['current_page'].
68 * $view->result should contain an array of objects. The array must use a
69 * numeric index starting at 0.
72 * The view which is executed.
74 function execute(&$view) { }
77 * Add a signature to the query, if such a thing is feasible.
79 * This signature is something that can be used when perusing query logs to
80 * discern where particular queries might be coming from.
83 * The view which is executed.
85 function add_signature(&$view) { }
88 * Get aggregation info for group by queries.
90 * If NULL, aggregation is not allowed.
92 function get_aggregation_info() { }
95 * Add settings for the ui.
97 function options_form(&$form, &$form_state) {
98 parent::options_form($form, $form_state);
101 function options_validate(&$form, &$form_state) { }
103 function options_submit(&$form, &$form_state) { }
105 function summary_title() {
106 return t('Settings');
110 * Set a LIMIT on the query, specifying a maximum number of results.
112 function set_limit($limit) {
113 $this->limit = $limit;
117 * Set an OFFSET on the query, specifying a number of results to skip
119 function set_offset($offset) {
120 $this->offset = $offset;
124 * Render the pager, if necessary.
126 function render_pager($exposed_input) {
127 if (!empty($this->pager) && $this->pager->use_pager()) {
128 return $this->pager->render($exposed_input);
135 * Create a new grouping for the WHERE or HAVING clause.
138 * Either 'AND' or 'OR'. All items within this group will be added
139 * to the WHERE clause with this logical operator.
141 * An ID to use for this group. If unspecified, an ID will be generated.
143 * 'where' or 'having'.
146 * The group ID generated.
148 function set_where_group($type = 'AND', $group = NULL, $where = 'where') {
150 $groups = &$this->$where;
152 if (!isset($group)) {
153 $group = empty($groups) ? 1 : max(array_keys($groups)) + 1;
156 // Create an empty group
157 if (empty($groups[$group])) {
158 $groups[$group] = array('conditions' => array(), 'args' => array());
161 $groups[$group]['type'] = strtoupper($type);
166 * Control how all WHERE and HAVING groups are put together.
169 * Either 'AND' or 'OR'
171 function set_group_operator($type = 'AND') {
172 $this->group_operator = strtoupper($type);
176 * Returns the according entity objects for the given query results.
178 function get_result_entities($results, $relationship = NULL) {