You are here

public function ViewsBulkOperationsActionProcessor::getPageList in Views Bulk Operations (VBO) 4.0.x

Same name and namespace in other branches
  1. 8.3 src/Service/ViewsBulkOperationsActionProcessor.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionProcessor::getPageList()
  2. 8.2 src/Service/ViewsBulkOperationsActionProcessor.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsActionProcessor::getPageList()

Get full list of items from a specific view page.

Parameters

int $page: Results page number.

Return value

array Array of result data arrays.

Overrides ViewsBulkOperationsActionProcessorInterface::getPageList

1 call to ViewsBulkOperationsActionProcessor::getPageList()
ViewsBulkOperationsActionProcessor::executeProcessing in src/Service/ViewsBulkOperationsActionProcessor.php
Helper function for processing results from view data.

File

src/Service/ViewsBulkOperationsActionProcessor.php, line 201

Class

ViewsBulkOperationsActionProcessor
Defines VBO action processor.

Namespace

Drupal\views_bulk_operations\Service

Code

public function getPageList($page) {
  $list = [];
  $this->viewDataService
    ->init($this->view, $this->view
    ->getDisplay(), $this->bulkFormData['relationship_id']);

  // Set exposed filters and pager parameters.
  if (!empty($this->bulkFormData['clear_on_exposed']) && !empty($this->bulkFormData['exposed_input'])) {
    $this->view
      ->setExposedInput($this->bulkFormData['exposed_input']);
  }
  else {
    $this->view
      ->setExposedInput([
      '_views_bulk_operations_override' => TRUE,
    ]);
  }

  // In some cases we may encounter nondeterministic behaviour in
  // db queries with sorts allowing different order of results.
  // To fix this we're removing all sorts and setting one sorting
  // rule by the view base id field.
  $sorts = $this->view
    ->getHandlers('sort');
  foreach ($sorts as $id => $sort) {
    $this->view
      ->setHandler($this->bulkFormData['display_id'], 'sort', $id, NULL);
  }
  $base_field = $this->view->storage
    ->get('base_field');
  $this->view
    ->setHandler($this->bulkFormData['display_id'], 'sort', $base_field, [
    'id' => $base_field,
    'table' => $this->view->storage
      ->get('base_table'),
    'field' => $base_field,
    'order' => 'ASC',
    'relationship' => 'none',
    'group_type' => 'group',
    'exposed' => 'FALSE',
    'plugin_id' => 'standard',
  ]);
  $this->view
    ->setItemsPerPage($this->bulkFormData['batch_size']);
  $this->view
    ->setCurrentPage($page);
  $this->view
    ->build();
  $offset = $this->bulkFormData['batch_size'] * $page;

  // If the view doesn't start from the first result,
  // move the offset.
  if ($pager_offset = $this->view->pager
    ->getOffset()) {
    $offset += $pager_offset;
  }
  $this->view->query
    ->setLimit($this->bulkFormData['batch_size']);
  $this->view->query
    ->setOffset($offset);
  $this->moduleHandler
    ->invokeAll('views_pre_execute', [
    $this->view,
  ]);
  $this->view->query
    ->execute($this->view);
  $base_field = $this->view->storage
    ->get('base_field');
  foreach ($this->view->result as $row) {
    $entity = $this->viewDataService
      ->getEntity($row);
    $exclude = FALSE;
    if ($this->excludeMode) {

      // Filter out excluded results basing on base field ID and language.
      foreach ($this->bulkFormData['exclude_list'] as $key => $item) {
        if ($row->{$base_field} === $item[0] && $entity
          ->language()
          ->getId() === $item[1]) {
          $exclude = TRUE;
          break;
        }
      }
    }
    if (!$exclude) {
      $list[] = [
        $row->{$base_field},
        $entity
          ->language()
          ->getId(),
        $entity
          ->getEntityTypeId(),
        $entity
          ->id(),
      ];
    }
  }
  return $list;
}