web/lib/Zend/Paginator/ScrollingStyle/Sliding.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_Paginator
       
    17  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    19  * @version    $Id: Sliding.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    20  */
       
    21 
       
    22 /**
       
    23  * @see Zend_Paginator_ScrollingStyle_Interface
       
    24  */
       
    25 require_once 'Zend/Paginator/ScrollingStyle/Interface.php';
       
    26 
       
    27 /**
       
    28  * A Yahoo! Search-like scrolling style.  The cursor will advance to
       
    29  * the middle of the range, then remain there until the user reaches
       
    30  * the end of the page set, at which point it will continue on to
       
    31  * the end of the range and the last page in the set.
       
    32  *
       
    33  * @link       http://search.yahoo.com/search?p=Zend+Framework
       
    34  * @category   Zend
       
    35  * @package    Zend_Paginator
       
    36  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    37  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    38  */
       
    39 class Zend_Paginator_ScrollingStyle_Sliding implements Zend_Paginator_ScrollingStyle_Interface
       
    40 {
       
    41     /**
       
    42      * Returns an array of "local" pages given a page number and range.
       
    43      *
       
    44      * @param  Zend_Paginator $paginator
       
    45      * @param  integer $pageRange (Optional) Page range
       
    46      * @return array
       
    47      */
       
    48     public function getPages(Zend_Paginator $paginator, $pageRange = null)
       
    49     {
       
    50         if ($pageRange === null) {
       
    51             $pageRange = $paginator->getPageRange();
       
    52         }
       
    53 
       
    54         $pageNumber = $paginator->getCurrentPageNumber();
       
    55         $pageCount  = count($paginator);
       
    56 
       
    57         if ($pageRange > $pageCount) {
       
    58             $pageRange = $pageCount;
       
    59         }
       
    60 
       
    61         $delta = ceil($pageRange / 2);
       
    62 
       
    63         if ($pageNumber - $delta > $pageCount - $pageRange) {
       
    64             $lowerBound = $pageCount - $pageRange + 1;
       
    65             $upperBound = $pageCount;
       
    66         } else {
       
    67             if ($pageNumber - $delta < 0) {
       
    68                 $delta = $pageNumber;
       
    69             }
       
    70 
       
    71             $offset     = $pageNumber - $delta;
       
    72             $lowerBound = $offset + 1;
       
    73             $upperBound = $offset + $pageRange;
       
    74         }
       
    75 
       
    76         return $paginator->getPagesInRange($lowerBound, $upperBound);
       
    77     }
       
    78 }