You are here

public function views_xml_backend_plugin_query_xml::execute in Views XML Backend 7

Same name and namespace in other branches
  1. 6 views_xml_backend_plugin_query_xml.inc \views_xml_backend_plugin_query_xml::execute()

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. The array must use a numeric index starting at 0.

Parameters

view $view: The view which is executed.

Overrides views_plugin_query::execute

File

./views_xml_backend_plugin_query_xml.inc, line 136
Contains views_xml_backend_plugin_query_xml.

Class

views_xml_backend_plugin_query_xml
@file Contains views_xml_backend_plugin_query_xml.

Code

public function execute(&$view) {
  $start = microtime(TRUE);

  // Avoid notices about $view->execute_time being undefined if the query
  // doesn't finish.
  $view->execute_time = NULL;

  // Make sure that an xml file exists. This could happen if you come from the
  // add wizard to the actual views edit page.
  if (empty($this->options['xml_file'])) {
    return FALSE;
  }
  $data = new stdClass();
  try {

    // Do token replacement. At this point, only argument values are
    // available.
    $path = $this
      ->replace_arguments($view, $this->options['xml_file']);
    $data->contents = $this
      ->fetch_file($path);
  } catch (Exception $e) {
    $cache = $view->display_handler
      ->get_plugin('cache')
      ->cache_flush();
    drupal_set_message(t('Views XML Backend: ' . $e
      ->getMessage()), 'error');
    return;
  }

  // Allow other modules to alter the data. Could be used for adding Tidy
  // support.
  // @todo Document this.
  drupal_alter('views_xml_backend_data', $data, $view->name);

  // When content is empty, parsing it is pointless.
  if (!$data->contents) {
    if ($this->options['show_errors']) {
      drupal_set_message(t('Views XML Backend: File is empty.'), 'warning');
    }
    return;
  }
  $use = $this
    ->errorStart();

  // Go!
  $this
    ->parse($view, $data);
  $view->execute_time = microtime(TRUE) - $start;
  $this
    ->errorStop($use, $this->options['show_errors']);
}