web/lib/Zend/Paginator/Adapter/Array.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: Array.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    20  */
       
    21 
       
    22 /**
       
    23  * @see Zend_Paginator_Adapter_Interface
       
    24  */
       
    25 require_once 'Zend/Paginator/Adapter/Interface.php';
       
    26 
       
    27 /**
       
    28  * @category   Zend
       
    29  * @package    Zend_Paginator
       
    30  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    31  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    32  */
       
    33 class Zend_Paginator_Adapter_Array implements Zend_Paginator_Adapter_Interface
       
    34 {
       
    35     /**
       
    36      * Array
       
    37      *
       
    38      * @var array
       
    39      */
       
    40     protected $_array = null;
       
    41 
       
    42     /**
       
    43      * Item count
       
    44      *
       
    45      * @var integer
       
    46      */
       
    47     protected $_count = null;
       
    48 
       
    49     /**
       
    50      * Constructor.
       
    51      *
       
    52      * @param array $array Array to paginate
       
    53      */
       
    54     public function __construct(array $array)
       
    55     {
       
    56         $this->_array = $array;
       
    57         $this->_count = count($array);
       
    58     }
       
    59 
       
    60     /**
       
    61      * Returns an array of items for a page.
       
    62      *
       
    63      * @param  integer $offset Page offset
       
    64      * @param  integer $itemCountPerPage Number of items per page
       
    65      * @return array
       
    66      */
       
    67     public function getItems($offset, $itemCountPerPage)
       
    68     {
       
    69         return array_slice($this->_array, $offset, $itemCountPerPage);
       
    70     }
       
    71 
       
    72     /**
       
    73      * Returns the total number of rows in the array.
       
    74      *
       
    75      * @return integer
       
    76      */
       
    77     public function count()
       
    78     {
       
    79         return $this->_count;
       
    80     }
       
    81 }