You are here

public function ViewsBulkOperationsViewData::getTotalResults in Views Bulk Operations (VBO) 8

Same name and namespace in other branches
  1. 8.3 src/Service/ViewsBulkOperationsViewData.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsViewData::getTotalResults()
  2. 8.2 src/Service/ViewsBulkOperationsViewData.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsViewData::getTotalResults()
  3. 4.0.x src/Service/ViewsBulkOperationsViewData.php \Drupal\views_bulk_operations\Service\ViewsBulkOperationsViewData::getTotalResults()

Get the total count of results on all pages.

TODO: Find a way to get total number of results with mini pager.

Return value

int The total number of results this view displays.

Overrides ViewsBulkOperationsViewDataInterface::getTotalResults

File

src/Service/ViewsBulkOperationsViewData.php, line 173

Class

ViewsBulkOperationsViewData
Gets Views data needed by VBO.

Namespace

Drupal\views_bulk_operations\Service

Code

public function getTotalResults() {

  // This number is not correct in $this->view->total_rows for
  // standard entity views and different pagers, so we have to build
  // a custom count query in such a case.
  if (isset($this->view->query)) {
    $query = $this->view->query
      ->query();
  }
  if (!empty($query)) {
    $total_results = $query
      ->countQuery()
      ->execute()
      ->fetchField();
  }
  else {
    if (isset($this->view->query) && empty($this->view->result)) {

      // Let modules modify the view just prior to executing it.
      $this->moduleHandler
        ->invokeAll('views_pre_execute', [
        $this->view,
      ]);
      $this->view->query
        ->execute($this->view);
    }
    $total_results = $this->view->total_rows;
  }

  // Include pager offset.
  if ($total_results && ($offset = $this->view->pager
    ->getOffset())) {
    $total_results -= $offset;
  }
  return $total_results;
}