Esempio n. 1
0
 /**
  * {@inheritDoc}
  */
 public function getCount(AdapterInterface $adapter, $page, $perPage)
 {
     $itemCount = $adapter->getItemCount();
     $pageCount = (int) ceil($itemCount / $perPage);
     if ($this->shouldMerge($itemCount, $perPage)) {
         return $pageCount - 1;
     }
     return $pageCount;
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  */
 public function getItems($offset, $limit)
 {
     $items = $this->adapter->getItems($offset, $limit);
     $oldCount = count($items);
     foreach ($this->callbacks as $callback) {
         $items = call_user_func($callback, $items);
     }
     $newCount = count($items);
     if ($oldCount !== $newCount) {
         throw new \LogicException(sprintf('Callbacks may not change the number of items (old count: %d, new count: %d).', $oldCount, $newCount));
     }
     return $items;
 }
Esempio n. 3
0
 /**
  * Gets items of this page as well as the 1-st item from the next page.
  * Doing it this way keeps us from having to run the expensive total item
  * count query in some scenarios.
  *
  * @return array
  */
 private function getItemsWithOneExtra()
 {
     if (null === $this->itemsWithOneExtra) {
         $this->itemsWithOneExtra = $this->adapter->getItems($this->getOffset(), $this->getLength() + 1);
     }
     return $this->itemsWithOneExtra;
 }
Esempio n. 4
0
 /**
  * Fetches the given range of items from the adapter and stores them in
  * the cache array.
  *
  * @param integer $offset
  * @param integer $limit
  */
 private function cache($offset, $limit)
 {
     $items = $this->adapter->getItems($offset, $limit);
     $i = $offset;
     foreach ($items as $item) {
         $this->cached[$i++] = $item;
     }
     if (count($items) < $limit) {
         $this->lastItemPos = $i - 1;
     }
 }
Esempio n. 5
0
 /**
  * {@inheritDoc}
  */
 public function getCount(AdapterInterface $adapter, $page, $perPage)
 {
     return (int) ceil($adapter->getItemCount() / $perPage);
 }