You are here

class views_plugin_query in Views (for Drupal 7) 6.3

Same name and namespace in other branches
  1. 7.3 plugins/views_plugin_query.inc \views_plugin_query

Object used to create a SELECT query.

Hierarchy

Expanded class hierarchy of views_plugin_query

1 string reference to 'views_plugin_query'
views_views_plugins in includes/plugins.inc
Implementation of hook_views_plugins

File

plugins/views_plugin_query.inc, line 10
Defines the base query class, which is the underlying layer in a View.

View source
class views_plugin_query extends views_plugin {

  /**
   * A pager plugin that should be provided by the display.
   */
  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.
   *
   * @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) {
  }
  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(
        '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);
  }

  /**
   * 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'),
      ),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
views_object::$definition property Handler's definition
views_object::$options property Except for displays, options for the object will be held here. 1
views_object::construct function Views handlers use a special construct function so that we can more easily construct them with variable arguments. 6
views_object::destroy function 2
views_object::export_option function 1
views_object::export_options function
views_object::options function Set default options on this object. Called by the constructor in a complex chain to deal with backward compatibility. 1
views_object::option_definition function Information about options for all kinds of purposes will be held here. 13
views_object::set_default_options function Set default options. For backward compatibility, it sends the options array; this is a feature that will likely disappear at some point.
views_object::set_definition function Let the handler know what its full definition is.
views_object::unpack_options function Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
views_object::unpack_translatable function Unpack a single option definition.
views_object::unpack_translatables function Unpacks each handler to store translatable texts.
views_object::_set_option_defaults function
views_plugin::$display property The current used views display.
views_plugin::$plugin_type property The plugin type of this plugin, for example style or query.
views_plugin::$view property The top object of a view. Overrides views_object::$view 1
views_plugin::additional_theme_functions function Provide a list of additional theme functions for the theme information page
views_plugin::theme_functions function Provide a full list of possible theme templates used by this style.
views_plugin::validate function Validate that the plugin is correct and can be saved. 2
views_plugin_query::$pager property A pager plugin that should be provided by the display. 1
views_plugin_query::add_signature function Add a signature to the query, if such a thing is feasible. 1
views_plugin_query::alter function Let modules modify the query just prior to finalizing it. 1
views_plugin_query::build function Builds the necessary info to execute the query. 1
views_plugin_query::execute function Executes the query and fills the associated view object with according values. 1
views_plugin_query::get_aggregation_info function Get aggregation info for group by queries. 1
views_plugin_query::get_cache_info function Return info to base the uniqueness of the result on. 1
views_plugin_query::get_preview_info function Return preview info. 1
views_plugin_query::init function Constructor; Create the basic query object and fill with default values. 1
views_plugin_query::options_form function Add settings for the ui. Overrides views_plugin::options_form 1
views_plugin_query::options_submit function Handle any special handling on the validate form. Overrides views_plugin::options_submit
views_plugin_query::options_validate function Validate the options form. Overrides views_plugin::options_validate
views_plugin_query::query function Generate a query and a countquery from all of the information supplied to the object. Overrides views_plugin::query 1
views_plugin_query::render_pager function Render the pager, if necessary.
views_plugin_query::set_group_operator function Control how all WHERE and HAVING groups are put together.
views_plugin_query::set_limit function Set a LIMIT on the query, specifying a maximum number of results.
views_plugin_query::set_offset function Set an OFFSET on the query, specifying a number of results to skip
views_plugin_query::set_where_group function Create a new grouping for the WHERE or HAVING clause.
views_plugin_query::summary_title function