You are here

class views_data_export_plugin_query_default_batched in Views data export 6.3

Same name and namespace in other branches
  1. 7.4 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_query_default_batched
  2. 7 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_query_default_batched
  3. 7.3 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_query_default_batched

Hierarchy

Expanded class hierarchy of views_data_export_plugin_query_default_batched

File

plugins/views_data_export_plugin_display_export.inc, line 746
Contains the bulk export display plugin.

View source
class views_data_export_plugin_query_default_batched extends views_plugin_query_default {

  /**
   * Executes the query and fills the associated view object with according
   * values.
   *
   * Values to set: $view->result, $view->total_rows, $view->execute_time,
   * $view->current_page.
   */
  function execute(&$view) {
    $display_handler =& $view->display_handler;
    $external = FALSE;

    // Whether this query will run against an external database.
    $query = $this->final_query;
    $count_query = $this->count_query;
    $args = $this->query_args;
    vpr($query);
    $items = array();
    $start = 0;
    if ($query) {
      $replacements = module_invoke_all('views_query_substitutions', $view);
      $query = str_replace(array_keys($replacements), $replacements, $query);
      $count_query = 'SELECT COUNT(*) FROM (' . str_replace(array_keys($replacements), $replacements, $count_query) . ') count_alias';
      if (is_array($args)) {
        foreach ($args as $id => $arg) {
          $args[$id] = str_replace(array_keys($replacements), $replacements, $arg);
        }
      }

      // Detect an external database.
      if (isset($view->base_database)) {
        db_set_active($view->base_database);
        $external = TRUE;
      }
      $start = views_microtime();
      if ($this->pager
        ->use_count_query() || !empty($view->get_total_rows)) {
        $this->pager
          ->execute_count_query($count_query, $args);
      }

      // Let the pager modify the query to add limits.
      $this->pager
        ->pre_execute($query, $args);

      // The $query is final and ready to go, we are going to redirect it to
      // become an insert into our table, sneaky!
      // Our query will look like:
      // CREATE TABLE {idx} SELECT @row := @row + 1 AS weight_alias, cl.* FROM
      // (-query-) AS cl, (SELECT @row := 0) AS r
      // We do some magic to get the row count.
      $display_handler->batched_execution_state->sandbox['weight_field_alias'] = $display_handler
        ->_weight_alias_create($view);

      // Views can construct queries that have fields with aliases longer than
      // 64 characters, which will cause problems when creating the table to
      // insert them into. So we hash the aliases down to make sure they are
      // unique.
      $display_handler->batched_execution_state->sandbox['field_aliases'] = $display_handler
        ->field_aliases_create($view);
      $select_aliases = array();
      foreach ($display_handler->batched_execution_state->sandbox['field_aliases'] as $hash => $alias) {
        $select_aliases[] = "cl.{$alias} AS {$hash}";
      }
      $insert_query = 'CREATE TABLE {' . $display_handler
        ->index_tablename() . '} SELECT @row := @row + 1 AS ' . $display_handler->batched_execution_state->sandbox['weight_field_alias'] . ', ' . implode(', ', $select_aliases) . ' FROM (' . $query . ') AS cl, (SELECT @row := 0) AS r';
      db_query($insert_query, $args);

      // Now create an index for the weight field, otherwise the queries on the
      // index will take a long time to execute.
      $ret = array();
      db_add_unique_key($ret, $display_handler
        ->index_tablename(), $display_handler->batched_execution_state->sandbox['weight_field_alias'], array(
        $display_handler->batched_execution_state->sandbox['weight_field_alias'],
      ));
      $this->pager
        ->post_execute($view->result);
      if ($this->pager
        ->use_pager()) {
        $view->total_rows = $this->pager
          ->get_total_items();
      }
      if ($external) {
        db_set_active();
      }
    }
    $view->execute_time = views_microtime() - $start;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
views_data_export_plugin_query_default_batched::execute function Executes the query and fills the associated view object with according values. Overrides views_plugin_query_default::execute
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::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::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::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
views_plugin_query_default::$distinct property A flag as to whether or not to make the primary field distinct.
views_plugin_query_default::$fields property An array of fields.
views_plugin_query_default::$groupby property A simple array of group by clauses.
views_plugin_query_default::$group_operator property The default operator to use when connecting the WHERE groups. May be AND or OR.
views_plugin_query_default::$has_aggregate property
views_plugin_query_default::$having property An array of sections of the HAVING query. Each section is in itself an array of pieces and a flag as to whether or not it should be AND or OR.
views_plugin_query_default::$header property The table header to use for tablesort. This matters because tablesort needs to modify the query and needs the header.
views_plugin_query_default::$orderby property A simple array of order by clauses.
views_plugin_query_default::$pager property The current used pager plugin. Overrides views_plugin_query::$pager
views_plugin_query_default::$relationships property Holds an array of relationships, which are aliases of the primary table that represent different ways to join the same table in.
views_plugin_query_default::$tables property Holds an array of tables and counts added so that we can create aliases
views_plugin_query_default::$table_queue property A list of tables in the order they should be added, keyed by alias.
views_plugin_query_default::$where property An array of sections of the WHERE query. Each section is in itself an array of pieces and a flag as to whether or not it should be AND or OR.
views_plugin_query_default::add_field function Add a field to the query table, possibly with an alias. This will automatically call ensure_table to make sure the required table exists, *unless* $table is unset.
views_plugin_query_default::add_groupby function Add a simple GROUP BY clause to the query. The caller is responsible for ensuring that the fields are fully qualified and the table is properly added.
views_plugin_query_default::add_having function Add a simple HAVING clause to the query. The caller is responsible for ensuring that all fields are fully qualified (TABLE.FIELD) and that the table and an appropriate GROUP BY already exist in the query.
views_plugin_query_default::add_orderby function Add an ORDER BY clause to the query.
views_plugin_query_default::add_relationship function A relationship is an alternative endpoint to a series of table joins. Relationships must be aliases of the primary table and they must join either to the primary table or to a pre-existing relationship.
views_plugin_query_default::add_signature function Add a signature to the query, if such a thing is feasible. Overrides views_plugin_query::add_signature
views_plugin_query_default::add_table function Add a table to the query, ensuring the path exists.
views_plugin_query_default::add_where function Add a simple WHERE clause to the query. The caller is responsible for ensuring that all fields are fully qualified (TABLE.FIELD) and that the table already exists in the query.
views_plugin_query_default::adjust_join function Fix a join to adhere to the proper relationship; the left table can vary based upon what relationship items are joined in on.
views_plugin_query_default::alter function Let modules modify the query just prior to finalizing it. Overrides views_plugin_query::alter
views_plugin_query_default::build function Builds the necessary info to execute the query. Overrides views_plugin_query::build
views_plugin_query_default::clear_fields function Remove all fields that may've been added; primarily used for summary mode where we're changing the query because we didn't get data we needed.
views_plugin_query_default::compile_fields function
views_plugin_query_default::condition_sql function Construct the "WHERE" or "HAVING" part of the query.
views_plugin_query_default::db_fetch_object function Wrapper method for db_fetch_object().
views_plugin_query_default::db_query function Wrapper method for db_query().
views_plugin_query_default::db_query_range function Wrapper method for db_query_range().
views_plugin_query_default::db_result function Wrapper method for db_result().
views_plugin_query_default::db_set_active function Wrapper method for db_set_active().
views_plugin_query_default::ensure_path function Make sure that the specified table can be properly linked to the primary table in the JOINs. This function uses recursion. If the tables needed to complete the path back to the primary table are not in the query they will be added, but additional…
views_plugin_query_default::ensure_table function Ensure a table exists in the queue; if it already exists it won't do anything, but if it doesn't it will add the table queue. It will ensure a path leads back to the relationship table.
views_plugin_query_default::get_aggregation_info function Get aggregation info for group by queries. Overrides views_plugin_query::get_aggregation_info
views_plugin_query_default::get_cache_info function Return info to base the uniqueness of the result on. Overrides views_plugin_query::get_cache_info
views_plugin_query_default::get_join_data function Retrieve join data from the larger join data cache.
views_plugin_query_default::get_preview_info function Return preview info. Overrides views_plugin_query::get_preview_info
views_plugin_query_default::get_table_info function Get the information associated with a table.
views_plugin_query_default::get_where_args function Get the arguments attached to the WHERE and HAVING clauses of this query.
views_plugin_query_default::init function Constructor; Create the basic query object and fill with default values. Overrides views_plugin_query::init
views_plugin_query_default::mark_table function
views_plugin_query_default::options_form function Add settings for the ui. Overrides views_plugin_query::options_form
views_plugin_query_default::option_definition function Information about options for all kinds of purposes will be held here. Overrides views_object::option_definition
views_plugin_query_default::query function Generate a query and a countquery from all of the information supplied to the object. Overrides views_plugin_query::query
views_plugin_query_default::queue_table function Add a table to the query without ensuring the path.
views_plugin_query_default::set_count_field function Set what field the query will count() on for paging.
views_plugin_query_default::set_distinct function Set the base field to be distinct.
views_plugin_query_default::set_header function Set the table header; used for click-sorting because it's needed info to modify the ORDER BY clause.