You are here

protected function Xml::doExecute in Views XML Backend 8

Performs the actual view execution.

Parameters

ViewExecutable $view: The view to execute.

See also

Xml::execute()

1 call to Xml::doExecute()
Xml::execute in src/Plugin/views/query/Xml.php
Executes the query and fills the associated view object with according values.

File

src/Plugin/views/query/Xml.php, line 421
Contains \Drupal\views_xml_backend\Plugin\views\query\Xml.

Class

Xml
Views query plugin for an XML query.

Namespace

Drupal\views_xml_backend\Plugin\views\query

Code

protected function doExecute(ViewExecutable $view) {
  $xpath = $this
    ->getXpath($this
    ->fetchFileContents($this
    ->getXmlDocumentPath($view)));
  if ($view->pager
    ->useCountQuery() || !empty($view->get_total_rows)) {

    // Normall we would call $view->pager->executeCountQuery($count_query);
    // but we can't in this case, so do the calculation ourselves.
    $view->pager->total_items = $xpath
      ->query($view->build_info['query'])->length;
    $view->pager->total_items -= $view->pager
      ->getOffset();
  }
  foreach ($xpath
    ->query($view->build_info['query']) as $row) {
    $result_row = new ResultRow();
    $view->result[] = $result_row;
    foreach ($view->field as $field_name => $field) {
      if (!isset($field->options['xpath_selector']) || $field->options['xpath_selector'] === '') {
        continue;
      }
      $result_row->{$field_name} = $this
        ->executeRowQuery($xpath, $field->options['xpath_selector'], $row);
    }
    foreach ($this->extraFields as $field_name => $selector) {
      $result_row->{$field_name} = $this
        ->executeRowQuery($xpath, $selector, $row);
    }
  }
  $this
    ->executeSorts($view);
  if (!empty($this->limit) || !empty($this->offset)) {

    // @todo Re-implement the performance optimization. For the case with no
    // sorts, we can avoid parsing the whole file.
    $view->result = array_slice($view->result, (int) $this->offset, (int) $this->limit);
  }

  // Set the index values after all manipulation is done.
  $this
    ->reIndexResults($view);
  $view->pager
    ->postExecute($view->result);
  $view->pager
    ->updatePageInfo();
  $view->total_rows = $view->pager
    ->getTotalItems();
}