You are here

protected function InfiniteScroll::getNumberItemsLeft in Views Infinite Scroll 8

Returns the number of items in the next page.

Return value

int The number of items in the next page.

1 call to InfiniteScroll::getNumberItemsLeft()
InfiniteScroll::render in src/Plugin/views/pager/InfiniteScroll.php
Return the renderable array of the pager.

File

src/Plugin/views/pager/InfiniteScroll.php, line 152

Class

InfiniteScroll
Views pager plugin to handle infinite scrolling.

Namespace

Drupal\views_infinite_scroll\Plugin\views\pager

Code

protected function getNumberItemsLeft() {
  $items_per_page = (int) $this->view
    ->getItemsPerPage();
  $total = (int) $this
    ->getTotalItems();
  $current_page = (int) $this
    ->getCurrentPage() + 1;

  // Default to the pager amount.
  $next_page_count = $items_per_page;

  // Calculate the remaining items if we are at the 2nd to last page.
  if ($current_page >= ceil($total / $items_per_page) - 1) {
    $next_page_count = $total - $current_page * $items_per_page;
    return $next_page_count;
  }
  return $next_page_count;
}