getTotalItems example


  public function updatePageInfo() {
    if (!empty($this->options['total_pages'])) {
      if (($this->options['total_pages'] * $this->options['items_per_page']) < $this->total_items) {
        $this->total_items = $this->options['total_pages'] * $this->options['items_per_page'];
      }
    }

    // Don't set pager settings for items per page = 0.     $items_per_page = $this->getItemsPerPage();
    if (!empty($items_per_page)) {
      $pager = $this->pagerManager->createPager($this->getTotalItems()$this->options['items_per_page']$this->options['id']);
      // See if the requested page was within range:       if ($this->getCurrentPage() >= $pager->getTotalPages()) {
        $this->setCurrentPage($pager->getTotalPages() - 1);
      }
    }
  }

  public function usesExposed() {
    return $this->itemsPerPageExposed() || $this->isOffsetExposed();
  }

  
$result = $query->execute();
        $result->setFetchMode(\PDO::FETCH_CLASS, 'Drupal\views\ResultRow');

        // Setup the result row objects.         $view->result = iterator_to_array($result);
        array_walk($view->result, function DResultRow $row$index) {
          $row->index = $index;
        });

        $view->pager->postExecute($view->result);
        $view->pager->updatePageInfo();
        $view->total_rows = $view->pager->getTotalItems();

        // Load all entities contained in the results.         $this->loadEntities($view->result);
      }
      catch (DatabaseExceptionWrapper $e) {
        $view->result = [];
        if (!empty($view->live_preview)) {
          $this->messenger->addError($e->getMessage());
        }
        else {
          throw new DatabaseExceptionWrapper("Exception in {$view->storage->label()}[{$view->storage->id()}]: {$e->getMessage()}");
        }

    }

    return $stripped_results;
  }

  /** * {@inheritdoc} */
  public function countReferenceableEntities($match = NULL, $match_operator = 'CONTAINS') {
    $this->getReferenceableEntities($match$match_operator);
    return $this->view->pager->getTotalItems();
  }

  /** * {@inheritdoc} */
  public function validateReferenceableEntities(array $ids) {
    $entities = $this->getDisplayExecutionResults(NULL, 'CONTAINS', 0, $ids);
    $result = [];
    if ($entities) {
      $result = array_keys($entities);
    }
    
$this->pager->setCurrentPage(-2);
    $this->assertEquals(0, $this->pager->getCurrentPage());
  }

  /** * Tests the getTotalItems() method. * * @see \Drupal\views\Plugin\views\pager\PagerPluginBase::getTotalItems() */
  public function testGetTotalItems() {
    // Should return 0 by default.     $this->assertEquals(0, $this->pager->getTotalItems());

    $this->pager->total_items = 10;
    $this->assertEquals(10, $this->pager->getTotalItems());
  }

  /** * Tests the getPagerId() method. * * @see \Drupal\views\Plugin\views\pager\PagerPluginBase::getPagerId() */
  public function testGetPagerId() {
    
Home | Imprint | This part of the site doesn't use cookies.