You are here

function views_data_export_plugin_display_export::query in Views data export 7.4

Same name and namespace in other branches
  1. 6.3 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_display_export::query()
  2. 6 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_display_export::query()
  3. 6.2 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_display_export::query()
  4. 7 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_display_export::query()
  5. 7.3 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_display_export::query()

Trick views into thinking that we have executed the query and got results.

We are called in the build phase of the view, but short circuit straight to getting the results and making the view think it has already executed the query.

Overrides views_plugin_display::query

File

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

Class

views_data_export_plugin_display_export
The plugin that batches its rendering.

Code

function query() {
  if (!$this
    ->is_batched()) {
    return parent::query();
  }

  // Make the query distinct if the option was set.
  if ($this
    ->get_option('distinct')) {
    $this->view->query
      ->set_distinct();
  }
  if (!empty($this->batched_execution_state->batch_state) && !empty($this->batched_execution_state->sandbox['weight_field_alias'])) {
    switch ($this->batched_execution_state->batch_state) {
      case VIEWS_DATA_EXPORT_BODY:
      case VIEWS_DATA_EXPORT_HEADER:
      case VIEWS_DATA_EXPORT_FOOTER:

        // Tell views its been executed.
        $this->view->executed = TRUE;

        // Grab our results from the index, and push them into the view result.
        // TODO: Handle external databases.
        $result = db_query_range('SELECT * FROM {' . $this
          ->index_tablename() . '} ORDER BY ' . $this->batched_execution_state->sandbox['weight_field_alias'] . ' ASC', 0, $this
          ->get_option('segment_size'));
        $this->view->result = array();
        foreach ($result as $item_hashed) {
          $item = new stdClass();

          // We had to shorten some of the column names in the index, restore
          // those now.
          foreach ($item_hashed as $hash => $value) {
            if (isset($this->batched_execution_state->sandbox['field_aliases'][$hash])) {
              $item->{$this->batched_execution_state->sandbox['field_aliases'][$hash]} = $value;
            }
            else {
              $item->{$hash} = $value;
            }
          }

          // Push the restored $item in the views result array.
          $this->view->result[] = $item;
        }
        $this->view
          ->_post_execute();
        break;
    }
  }
}