File indexing completed on 2024-05-26 06:03:15

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Paginator
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  * @version    $Id$
0020  */
0021 
0022 /**
0023  * @see Zend_Paginator_ScrollingStyle_Interface
0024  */
0025 // require_once 'Zend/Paginator/ScrollingStyle/Interface.php';
0026 
0027 /**
0028  * A Yahoo! Search-like scrolling style.  The cursor will advance to
0029  * the middle of the range, then remain there until the user reaches
0030  * the end of the page set, at which point it will continue on to
0031  * the end of the range and the last page in the set.
0032  *
0033  * @link       http://search.yahoo.com/search?p=Zend+Framework
0034  * @category   Zend
0035  * @package    Zend_Paginator
0036  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0037  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0038  */
0039 class Zend_Paginator_ScrollingStyle_Sliding implements Zend_Paginator_ScrollingStyle_Interface
0040 {
0041     /**
0042      * Returns an array of "local" pages given a page number and range.
0043      *
0044      * @param  Zend_Paginator $paginator
0045      * @param  integer $pageRange (Optional) Page range
0046      * @return array
0047      */
0048     public function getPages(Zend_Paginator $paginator, $pageRange = null)
0049     {
0050         if ($pageRange === null) {
0051             $pageRange = $paginator->getPageRange();
0052         }
0053 
0054         $pageNumber = $paginator->getCurrentPageNumber();
0055         $pageCount  = count($paginator);
0056 
0057         if ($pageRange > $pageCount) {
0058             $pageRange = $pageCount;
0059         }
0060 
0061         $delta = ceil($pageRange / 2);
0062 
0063         if ($pageNumber - $delta > $pageCount - $pageRange) {
0064             $lowerBound = $pageCount - $pageRange + 1;
0065             $upperBound = $pageCount;
0066         } else {
0067             if ($pageNumber - $delta < 0) {
0068                 $delta = $pageNumber;
0069             }
0070 
0071             $offset     = $pageNumber - $delta;
0072             $lowerBound = $offset + 1;
0073             $upperBound = $offset + $pageRange;
0074         }
0075 
0076         return $paginator->getPagesInRange($lowerBound, $upperBound);
0077     }
0078 }