You are here

protected function Adaptive::buildAdaptivePageList in Pagerer 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/pagerer/Adaptive.php \Drupal\pagerer\Plugin\pagerer\Adaptive::buildAdaptivePageList()

Returns an array of pages using an adaptive logic.

Parameters

array $pages: Array of pages already enlisted, to prevent override.

int $l: Adaptive lock to left page.

int $r: Adaptive lock to right page.

int $x: Adaptive center lock for neighborhood.

Return value

array Render array of pages items, with a 'outer_page' key set to TRUE.

1 call to Adaptive::buildAdaptivePageList()
Adaptive::buildPageList in src/Plugin/pagerer/Adaptive.php
Return an array of pages.

File

src/Plugin/pagerer/Adaptive.php, line 200

Class

Adaptive
Pager style with links to pages following an adaptive logic.

Namespace

Drupal\pagerer\Plugin\pagerer

Code

protected function buildAdaptivePageList(array &$pages, $l, $r, $x) {
  $current = $this->pager
    ->getCurrentPage();
  $x = is_null($x) ? $current : $x;

  // Space on the left of the holding marker.
  $sl = $x - $l;

  // Space on the right of the holding marker.
  $sr = $r - $x;

  // Half of the maximum space either side to calculate from.
  $m = max($sl, $sr) / 2;
  for ($i = 0; $i < 2; $i++) {
    $off = intval($m * pow(0.5, $i));

    // Pages on the left.
    $p = $x - $off;
    if ($p > $l and $p < $current and !isset($pages[$p]) and !(isset($pages[$p - 1]) or isset($pages[$p + 1]))) {
      $pages[$p] = $this
        ->getPageItem($p - $current, $this
        ->getOption('progr_links'), TRUE);
      $pages[$p]['outer_page'] = TRUE;
    }

    // Pages on the right.
    $p = $x + $off;
    if ($p < $r and $p > $current and !isset($pages[$p]) and !(isset($pages[$p - 1]) or isset($pages[$p + 1]))) {
      $pages[$p] = $this
        ->getPageItem($p - $current, $this
        ->getOption('progr_links'), TRUE);
      $pages[$p]['outer_page'] = TRUE;
    }
  }
  return $pages;
}