You are here

function views_data_export_plugin_display_export::query in Views data export 6.3

Same name and namespace in other branches
  1. 6 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_display_export::query()
  2. 6.2 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_display_export::query()
  3. 7.4 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.

File

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

Class

views_data_export_plugin_display_export
The plugin that batches its rendering.

Code

function query($group_by = FALSE) {
  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, 100);
        $this->view->result = array();
        while ($item_arr = db_fetch_array($result)) {
          $item = new stdClass();

          // We had to shorten some of the column names in the index, restore
          // those now.
          foreach ($item_arr 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;
        }
        break;
    }
  }
}