2013-06-07 11:44:37 +02:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | GPLv2+ */
|
2013-06-07 11:44:37 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Zend_Paginator_ScrollingStyle_Interface
|
|
|
|
*/
|
|
|
|
class Icinga_Web_Paginator_ScrollingStyle_SlidingWithBorder implements Zend_Paginator_ScrollingStyle_Interface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Returns an array of "local" pages given a page number and range.
|
2013-06-11 10:27:44 +02:00
|
|
|
*
|
2013-06-07 11:44:37 +02:00
|
|
|
* @param Zend_Paginator $paginator
|
|
|
|
* @param integer $pageRange (Optional) Page range
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getPages(Zend_Paginator $paginator, $pageRange = null)
|
|
|
|
{
|
2014-06-20 17:31:32 +02:00
|
|
|
// This is unused
|
2013-06-07 11:44:37 +02:00
|
|
|
if ($pageRange === null) {
|
|
|
|
$pageRange = $paginator->getPageRange();
|
|
|
|
}
|
|
|
|
|
|
|
|
$pageNumber = $paginator->getCurrentPageNumber();
|
2013-06-11 10:27:44 +02:00
|
|
|
$pageCount = count($paginator);
|
2013-06-07 11:44:37 +02:00
|
|
|
$range = array();
|
|
|
|
|
2014-06-20 17:31:32 +02:00
|
|
|
if ($pageCount < 10) {
|
|
|
|
// Show all pages if we have less than 10.
|
|
|
|
|
|
|
|
for ($i = 1; $i < 10; $i++) {
|
2013-06-11 10:27:44 +02:00
|
|
|
if ($i > $pageCount) {
|
|
|
|
break;
|
|
|
|
}
|
2013-06-07 11:44:37 +02:00
|
|
|
$range[$i] = $i;
|
|
|
|
}
|
|
|
|
} else {
|
2014-06-20 17:31:32 +02:00
|
|
|
// More than 10 pages:
|
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
foreach (array(1, 2) as $i) {
|
|
|
|
$range[$i] = $i;
|
|
|
|
}
|
2014-06-20 17:31:32 +02:00
|
|
|
if ($pageNumber < 6 ) {
|
2015-02-03 16:27:59 +01:00
|
|
|
// We are on page 1-5 from
|
2014-06-20 17:31:32 +02:00
|
|
|
for ($i = 1; $i <= 7; $i++) {
|
|
|
|
$range[$i] = $i;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Current page > 5
|
2013-06-07 11:44:37 +02:00
|
|
|
$range[] = '...';
|
2014-06-20 17:31:32 +02:00
|
|
|
|
|
|
|
// Less than 5 pages left
|
|
|
|
if (($pageCount - $pageNumber) < 5) {
|
|
|
|
$start = 5 - ($pageCount - $pageNumber);
|
|
|
|
} else {
|
|
|
|
$start = 1;
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
2014-06-20 17:31:32 +02:00
|
|
|
|
|
|
|
for ($i = $pageNumber - $start; $i < ($pageNumber + (4 - $start)); $i++) {
|
2013-06-11 10:27:44 +02:00
|
|
|
if ($i > $pageCount) {
|
|
|
|
break;
|
|
|
|
}
|
2013-06-07 11:44:37 +02:00
|
|
|
$range[$i] = $i;
|
|
|
|
}
|
|
|
|
}
|
2014-06-20 17:31:32 +02:00
|
|
|
if ($pageNumber < ($pageCount - 2)) {
|
2013-06-07 11:44:37 +02:00
|
|
|
$range[] = '...';
|
|
|
|
}
|
2014-06-20 17:31:32 +02:00
|
|
|
|
|
|
|
foreach (array($pageCount - 1, $pageCount) as $i) {
|
|
|
|
$range[$i] = $i;
|
|
|
|
}
|
|
|
|
|
2013-06-07 11:44:37 +02:00
|
|
|
}
|
2013-06-11 10:27:44 +02:00
|
|
|
if (empty($range)) {
|
|
|
|
$range[] = 1;
|
|
|
|
}
|
2013-06-07 11:44:37 +02:00
|
|
|
return $range;
|
|
|
|
}
|
|
|
|
}
|