You are here

public static function ControllerBase::getPage in MongoDB 8.2

Return a reliable page number based on available data.

Parameters

int $count: The number of events templates in the collection.

int $requestedPage: The page number requested by the user, starting at 0.

int $height: The pager height.

Return value

int The actual index of the page to display.

2 calls to ControllerBase::getPage()
ControllerBase::setupPager in modules/mongodb_watchdog/src/Controller/ControllerBase.php
Set up the pager.
ControllerBaseTest::testPageGeneration in modules/mongodb_watchdog/tests/src/Unit/ControllerBaseTest.php
Test page generation for various data set shapes.

File

modules/mongodb_watchdog/src/Controller/ControllerBase.php, line 160

Class

ControllerBase
Base controller class for paged reports.

Namespace

Drupal\mongodb_watchdog\Controller

Code

public static function getPage(int $count, int $requestedPage, int $height) : int {
  if ($requestedPage <= 0) {
    return 0;
  }

  // There is always at least one page, even with $count === 0.
  $pageCount = max(1, intval(ceil($count / $height)));
  if ($requestedPage < $pageCount) {
    return $requestedPage;
  }
  $page = $pageCount - 1;
  return $page;
}