*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / Paginator / Adapter / Iterator.php
blob4d19b55be8439ca8ba0f81548013d72c47b6518d
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
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.
15 * @category Zend
16 * @package Zend_Paginator
17 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
18 * @license http://framework.zend.com/license/new-bsd New BSD License
19 * @version $Id: Iterator.php 16215 2009-06-21 19:36:07Z thomas $
22 /**
23 * @see Zend_Paginator_Adapter_Interface
25 require_once 'Zend/Paginator/Adapter/Interface.php';
27 /**
28 * @category Zend
29 * @package Zend_Paginator
30 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
31 * @license http://framework.zend.com/license/new-bsd New BSD License
33 class Zend_Paginator_Adapter_Iterator implements Zend_Paginator_Adapter_Interface
35 /**
36 * Iterator which implements Countable
38 * @var Iterator
40 protected $_iterator = null;
42 /**
43 * Item count
45 * @var integer
47 protected $_count = null;
49 /**
50 * Constructor.
52 * @param Iterator $iterator Iterator to paginate
53 * @throws Zend_Paginator_Exception
55 public function __construct(Iterator $iterator)
57 if (!$iterator instanceof Countable) {
58 /**
59 * @see Zend_Paginator_Exception
61 require_once 'Zend/Paginator/Exception.php';
63 throw new Zend_Paginator_Exception('Iterator must implement Countable');
66 $this->_iterator = $iterator;
67 $this->_count = count($iterator);
70 /**
71 * Returns an iterator of items for a page, or an empty array.
73 * @param integer $offset Page offset
74 * @param integer $itemCountPerPage Number of items per page
75 * @return LimitIterator|array
77 public function getItems($offset, $itemCountPerPage)
79 if ($this->_count == 0) {
80 return array();
83 return new LimitIterator($this->_iterator, $offset, $itemCountPerPage);
86 /**
87 * Returns the total number of rows in the collection.
89 * @return integer
91 public function count()
93 return $this->_count;