public function getCacheKey() : array { $key = parent::getCacheKey(); $key[] = $this->paginator->getBase(); $key[] = $this->paginator->getPage(); $key[] = $this->paginator->getItemsPerPage(); return $key; }
public function actionDefault($page = 1) { if ($page < 1) { $this->redirect('this', ['page' => 1]); } $this->paginator = new Paginator(); $this->paginator->setItemsPerPage(self::ORDERS_PER_PAGE); $this->paginator->setPage($page); $orders = $this->orderService->getAll($this->paginator->getItemsPerPage(), $this->paginator->getOffset()); $this->paginator->setItemCount(count($orders)); $orders = iterator_to_array($orders); if (count($orders) === 0 && $page > 1) { $this->redirect('this', ['page' => 1]); } $this->orders = $orders; }
public function renderDetail($id, $page = 1) { $allProducts = $this->productService->getProductsInCategory(self::BASE_LANG, $id); $paginator = new Paginator(); $paginator->setItemsPerPage(self::ITEMS_PER_PAGE); $paginator->setItemCount(count($allProducts)); $paginator->setPage((int) $page); $products = array_slice($allProducts, self::ITEMS_PER_PAGE * $paginator->getPage() - 1, $paginator->getItemsPerPage()); if (!$products && 0 === count($allProducts)) { throw new BadRequestException(); } $this->template->paginator = $paginator; $this->template->products = $products; }
public function renderDefault($page = 1, $filter = '%') { $paginator = new Nette\Utils\Paginator(); $paginator->setItemsPerPage(3); // the number of records on page $paginator->setPage($page); //current page, default 1 $users = $this->database->table('users')->where('login LIKE ? OR email LIKE ?', $filter, $filter)->limit($paginator->getLength(), $paginator->getOffset()); $this->template->users = $users; $this->template->filter = $filter; $this->template->totalPosts = $this->database->table('users')->count(); $paginator->setItemCount($this->template->totalPosts); $this->template->totalPages = $paginator->getPageCount(); $this->template->page = $paginator->page; $this->template->pageCount = $paginator->getItemsPerPage(); }
/** * Get last page URL * @param Paginator $paginator * @return Link */ private function getLastPageUrl(Paginator $paginator) { $url = clone $this->request->getUrl(); parse_str($url->getQuery(), $query); $query['offset'] = $paginator->getLastPage() * $paginator->getItemsPerPage() - $paginator->getItemsPerPage(); $query['limit'] = $paginator->getItemsPerPage(); $url->appendQuery($query); return new Link($url, Link::LAST); }
public function getIterator() : IteratorAggregate { return $this->collection->limitBy($this->paginator->getItemsPerPage(), $this->paginator->getOffset()) ?: parent::getIterator(); }