/** * Creates the page collection. * * @param string $scrollingStyle Scrolling style * @return stdClass */ protected function _createPages($scrollingStyle = null) { $pageCount = $this->count(); $currentPageNumber = $this->getCurrentPageNumber(); $pages = new stdClass(); $pages->pageCount = $pageCount; $pages->itemCountPerPage = $this->getItemCountPerPage(); $pages->first = 1; $pages->current = $currentPageNumber; $pages->last = $pageCount; // Previous and next if ($currentPageNumber - 1 > 0) { $pages->previous = $currentPageNumber - 1; } if ($currentPageNumber + 1 <= $pageCount) { $pages->next = $currentPageNumber + 1; } // Pages in range $scrollingStyle = $this->_loadScrollingStyle($scrollingStyle); $pages->pagesInRange = $scrollingStyle->getPages($this); $pages->firstPageInRange = min($pages->pagesInRange); $pages->lastPageInRange = max($pages->pagesInRange); // Item numbers if ($this->getCurrentItems() !== null) { $pages->currentItemCount = $this->getCurrentItemCount(); $pages->totalItemCount = $this->_adapter->count(); $pages->firstItemNumber = ($currentPageNumber - 1) * $this->_itemCountPerPage + 1; $pages->lastItemNumber = $pages->firstItemNumber + $pages->currentItemCount - 1; } return $pages; }
/** * Returns the items for a given page. * * @return Traversable */ public function getItemsByPage($pageNumber) { $pageNumber = $this->normalizePageNumber($pageNumber); if ($this->_cacheEnabled()) { $data = self::$_cache->load($this->_getCacheId($pageNumber)); if ($data !== false) { return $data; } } $offset = ($pageNumber - 1) * $this->getItemCountPerPage(); $items = $this->_adapter->getItems($offset, $this->getItemCountPerPage()); $filter = $this->getFilter(); if ($filter !== null) { $items = $filter->filter($items); } if (!$items instanceof Traversable) { $items = new ArrayIterator($items); } if ($this->_cacheEnabled()) { self::$_cache->save($items, $this->_getCacheId($pageNumber), array($this->_getCacheInternalId())); } return $items; }
/** * Constructor. * * @param Zend_Paginator_Adapter_Interface|\Zend\Paginator\AdapterAggregate $adapter */ public function __construct($adapter) { if ($adapter instanceof Adapter) { $this->_adapter = $adapter; } else { if ($adapter instanceof AdapterAggregate) { $this->_adapter = $adapter->getPaginatorAdapter(); } else { throw new Exception\InvalidArgumentException('Zend_Paginator only accepts instances of the type ' . 'Zend_Paginator_Adapter_Interface or Zend_Paginator_AdapterAggregate.'); } } $config = self::$_config; if ($config != null) { $setupMethods = array('ItemCountPerPage', 'PageRange'); foreach ($setupMethods as $setupMethod) { $value = $config->get(strtolower($setupMethod)); if ($value != null) { $setupMethod = 'set' . $setupMethod; $this->{$setupMethod}($value); } } } }
/** * Calculates the page count. * * @return integer */ protected function _calculatePageCount() { return (int) ceil($this->_adapter->count() / $this->_itemCountPerPage); }