From 561639ab96af0d635c8f2a78ed5a68c6319053fc Mon Sep 17 00:00:00 2001 From: 4Giedrius <4giedrius@gmail.com> Date: Mon, 24 Nov 2014 13:28:21 +0200 Subject: [PATCH] Paginator should not go below zero when there are only few pages --- src/bb-library/Box/Paginator.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/bb-library/Box/Paginator.php b/src/bb-library/Box/Paginator.php index 03ec6e373..b8ebd13bb 100644 --- a/src/bb-library/Box/Paginator.php +++ b/src/bb-library/Box/Paginator.php @@ -82,19 +82,17 @@ class Box_Paginator { private function calculateRange() { - $startRange = $this->currentPage - floor($this->midRange/2); - $endRange = $this->currentPage + floor($this->midRange/2); + $startRange = $this->currentPage - floor($this->midRange / 2); + $endRange = $this->currentPage + floor($this->midRange / 2); - if($startRange <= 0) - { - $endRange += abs($startRange)+1; + if ($startRange <= 0) { + $endRange += abs($startRange) + 1; $startRange = 1; } - if($endRange > $this->numPages) - { - $startRange -= $endRange-$this->numPages; - $endRange = $this->numPages; + if ($endRange > $this->numPages) { + $endRange = $this->numPages; + $startRange = $endRange - $this->numPages + 1; } $this->range = range($startRange, $endRange);