Skip to content

Commit

Permalink
fix creating page range
Browse files Browse the repository at this point in the history
  • Loading branch information
serieznyi authored and Maxim Mironyuk committed Nov 22, 2017
1 parent d2bef45 commit e261db6
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions Filter/ViewData/PagerAwareViewData.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,36 +173,37 @@ public function isLastPage()
*/
public function getPages()
{
if ($this->numPages <= 1) {
return [];
}

if ($this->numPages <= $this->maxPages) {
return range(1, $this->numPages);
}

// Determine the sliding range, centered around the current page.
$numAdjacents = (int) floor(($this->maxPages - 3) / 2);

if ($this->currentPage + $numAdjacents > $this->numPages) {
$begin = $this->numPages - $this->maxPages + 2;
$slidingStart = $this->numPages - $this->maxPages + 2;
} else {
$begin = $this->currentPage - $numAdjacents;
$slidingStart = $this->currentPage - $numAdjacents;
}
if ($begin < 2) {
$begin = 2;

if ($slidingStart < 2) {
$slidingStart = 2;
}

$end = $begin + $this->maxPages - 2;
// if ($end >= $this->numPages) $end = $this->numPages - 1;
$slidingEnd = $slidingStart + $this->maxPages - 3;

// $tmpBegin = $this->maxPages - floor($this->maxPages / 2);
// $tmpEnd = $tmpBegin + $this->maxPages - 1;
//
// if ($tmpBegin < 1) {
// $tmpEnd += 1 - $tmpBegin;
// $tmpBegin = 1;
// }
//
// if ($tmpEnd > $this->getLastPage()) {
// $tmpBegin -= $tmpEnd - $this->getLastPage();
// $tmpEnd = $this->getLastPage();
// }
//
// $begin = min($tmpBegin, 2);
// $end = $tmpEnd;
if ($slidingEnd >= $this->numPages) {
$slidingEnd = $this->numPages - 1;
}

return range($begin, $end, 1);
return array_merge(
[1],
range($slidingStart, $slidingEnd),
[$this->numPages]
);
}
}

0 comments on commit e261db6

Please sign in to comment.