Newer
Older
Earl Miles
committed
<?php
/**
Earl Miles
committed
* Defines the base query class, which is the underlying layer in a View.
*/
/**
* Object used to create a SELECT query.
*/
class views_plugin_query extends views_plugin {
Earl Miles
committed
/**
* A pager plugin that should be provided by the display.
*/
var $pager = NULL;
Earl Miles
committed
/**
* Constructor; Create the basic query object and fill with default values.
*/
Earl Miles
committed
function init($base_table, $base_field, $options) {
$this->base_table = $base_table;
$this->base_field = $base_field;
$this->unpack_options($this->options, $options);
Earl Miles
committed
}
Earl Miles
committed
/**
* 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) { }
Earl Miles
committed
Earl Miles
committed
/**
* Let modules modify the query just prior to finalizing it.
*/
function alter(&$view) { }
Earl Miles
committed
Earl Miles
committed
/**
* Builds the necessary info to execute the query.
*/
function build(&$view) { }
/**
* Executes the query and fills the associated view object with according
* values.
Earl Miles
committed
*
Earl Miles
committed
* Values to set: $view->result, $view->total_rows, $view->execute_time,
* $view->pager['current_page'].
*
* $view->result should contain an array of objects.
Earl Miles
committed
*/
function execute(&$view) { }
Earl Miles
committed
/**
* 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.
*/
function add_signature(&$view) { }
Earl Miles
committed
/**
* Get aggregation info for group by queries.
*
* If NULL, aggregation is not allowed.
*/
function get_aggregation_info() { }
Earl Miles
committed
Earl Miles
committed
/**
* Add settings for the ui.
*/
function options_form(&$form, &$form_state) { }
function options_validate(&$form, &$form_state) { }
function options_submit(&$form, &$form_state) { }
function summary_title() {
return t('Settings');
}
Earl Miles
committed
/**
* 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) {
Earl Miles
committed
if (!empty($this->pager) && $this->pager->use_pager()) {
return $this->pager->render($exposed_input);
}
Earl Miles
committed
return '';
}
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
/**
* 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('clauses' => 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);
}
Earl Miles
committed
Earl Miles
committed
/**
* Return info to base the uniqueness of the result on.
*
* @return $cache_info
* A string or array with query unique data or FALSE to deactivate caching
*/
function get_cache_info() {
return FALSE;
}
/**
* Return preview info.
*
* @return $rows
* An array of strings with info to be shown in the preview.
*/
function get_preview_info() {
return array(array('<strong>' . t('Query') . '</strong>', t('No info')));
}