diff --git a/library/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorder.php b/library/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorder.php index 23b0b7639..94a4fe4f6 100644 --- a/library/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorder.php +++ b/library/Icinga/Web/Paginator/ScrollingStyle/SlidingWithBorder.php @@ -43,6 +43,7 @@ class Icinga_Web_Paginator_ScrollingStyle_SlidingWithBorder implements Zend_Pagi */ public function getPages(Zend_Paginator $paginator, $pageRange = null) { + // This is unused if ($pageRange === null) { $pageRange = $paginator->getPageRange(); } @@ -51,40 +52,52 @@ class Icinga_Web_Paginator_ScrollingStyle_SlidingWithBorder implements Zend_Pagi $pageCount = count($paginator); $range = array(); - if ($pageCount < 15) { - for ($i = 1; $i < 15; $i++) { + if ($pageCount < 10) { + // Show all pages if we have less than 10. + + for ($i = 1; $i < 10; $i++) { if ($i > $pageCount) { break; } $range[$i] = $i; } } else { + // More than 10 pages: + foreach (array(1, 2) as $i) { $range[$i] = $i; } - if ($pageNumber > 8) { - $range[] = '...'; - $start = 5; - if ($pageCount - $pageNumber < 8) { - $start = 9 - ($pageCount - $pageNumber); + if ($pageNumber < 6 ) { + // We are on page 1-5 from + for ($i = 1; $i <= 7; $i++) { + $range[$i] = $i; } - for ($i = $pageNumber - $start; $i < $pageNumber + (10 - $start); $i++) { + } else { + // Current page > 5 + $range[] = '...'; + + // Less than 5 pages left + if (($pageCount - $pageNumber) < 5) { + $start = 5 - ($pageCount - $pageNumber); + } else { + $start = 1; + } + + for ($i = $pageNumber - $start; $i < ($pageNumber + (4 - $start)); $i++) { if ($i > $pageCount) { break; } $range[$i] = $i; } - } else { - for ($i = 3; $i <= 10; $i++) { - $range[$i] = $i; - } } - if ($pageNumber < ($pageCount - 7)) { + if ($pageNumber < ($pageCount - 2)) { $range[] = '...'; - foreach (array($pageCount - 1, $pageCount) as $i) { - $range[$i] = $i; - } } + + foreach (array($pageCount - 1, $pageCount) as $i) { + $range[$i] = $i; + } + } if (empty($range)) { $range[] = 1;