You are here

function views_data_export_plugin_display_export::execute_normal 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::execute_normal()
  2. 6 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_display_export::execute_normal()
  3. 6.2 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_display_export::execute_normal()
  4. 7 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_display_export::execute_normal()
  5. 7.3 plugins/views_data_export_plugin_display_export.inc \views_data_export_plugin_display_export::execute_normal()

Compiles the next chunk of the output file.

This will only be executed in batched mode.

1 call to views_data_export_plugin_display_export::execute_normal()
views_data_export_plugin_display_export::execute in plugins/views_data_export_plugin_display_export.inc
Execute this display handler.

File

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

Class

views_data_export_plugin_display_export
The plugin that batches its rendering.

Code

function execute_normal() {

  // Pass through to our render method,
  $output = $this->view
    ->render();

  // Append what was rendered to the output file.
  $this
    ->outputfile_write($output);

  // Store for convenience.
  $state =& $this->batched_execution_state;
  $sandbox =& $state->sandbox;

  // Update progress measurements & move our state forward
  switch ($state->batch_state) {
    case VIEWS_DATA_EXPORT_BODY:

      // Remove rendered results from our index
      if (count($this->view->result) && $sandbox['weight_field_alias']) {
        $last = end($this->view->result);
        db_delete($this
          ->index_tablename())
          ->condition($sandbox['weight_field_alias'], $last->{$sandbox['weight_field_alias']}, '<=')
          ->execute();

        // Update progress.
        $progress = db_query('SELECT COUNT(*) FROM {' . $this
          ->index_tablename() . '}')
          ->fetchField();

        // TODO: These next few lines are messy, clean them up.
        $progress = 0.99 - $progress / $sandbox['max'] * 0.99;
        $progress = (int) floor($progress * 100000);
        $progress = $progress / 100000;
        $sandbox['finished'] = $progress;
      }
      else {

        // No more results.
        $progress = 0.99;
        $state->batch_state = VIEWS_DATA_EXPORT_FOOTER;
      }
      break;
    case VIEWS_DATA_EXPORT_HEADER:
      $sandbox['finished'] = 0;
      $state->batch_state = VIEWS_DATA_EXPORT_BODY;
      break;
    case VIEWS_DATA_EXPORT_FOOTER:
      $sandbox['finished'] = 1;
      $state->batch_state = VIEWS_DATA_EXPORT_FINISHED;
      break;
  }

  // Create a more helpful exporting message.
  $sandbox['message'] = $this
    ->compute_time_remaining($sandbox['started'], $sandbox['finished']);
}