/** * Apply the given page limit and number on the given query and setup a paginator for it * * The $itemsPerPage and $pageNumber parameters are only applied if not available in the current request. * The paginator is set on the `paginator' view property only if the current view has not been requested as compact. * * @param QueryInterface $query The query to create a paginator for * @param int $itemsPerPage Default number of items per page * @param int $pageNumber Default page number * * @return $this */ protected function setupPaginationControl(QueryInterface $query, $itemsPerPage = 25, $pageNumber = 0) { $request = $this->getRequest(); $limit = $request->getParam('limit', $itemsPerPage); $page = $request->getParam('page', $pageNumber); $query->limit($limit, $page > 0 ? ($page - 1) * $limit : 0); if (!$this->view->compact) { $paginator = new Paginator(); $paginator->setQuery($query); $this->view->paginator = $paginator; } return $this; }
/** * Fetch and return the rows in the given range of the query result * * @param int $offset Page offset * @param int $itemCountPerPage Number of items per page * * @return array */ public function getItems($offset, $itemCountPerPage) { return $this->query->limit($itemCountPerPage, $offset)->fetchAll(); }
/** * Limit this query's results * * @param int $count When to stop returning results * @param int $offset When to start returning results * * @return $this */ public function limit($count = null, $offset = null) { $this->query->limit($count, $offset); return $this; }