public function testCreate() { $filterParams = ['$page' => 2, '$limit' => 5]; $numberOfItems = mt_rand(100, 1000); $this->testedObject->prepareFilterParams($filterParams); $result = $this->testedObject->create($numberOfItems); $this->assertInstanceOf(PaginatorInfo::class, $result); $this->assertSame($numberOfItems, $result->getNumberOfItems()); }
public function indexAction() { try { $filterParams = $this->paginatorInfoFactory->prepareFilterParams($this->params()->fromQuery()); $this->queryFilter->setQueryParameters($filterParams); /** @var PaginatorAdapter $paginator */ $paginator = $this->service->getFilteredResults($this->queryFilter); $paginatorInfo = $this->paginatorInfoFactory->create($paginator->count()); $paginatorInfo->preparePagesToShow(); return ['books' => $paginator->getIterator(), 'paginator' => $paginatorInfo, 'route' => 'library/books/*', 'query' => $filterParams]; } catch (QueryFilterException $e) { $this->flashMessenger()->addErrorMessage($e->getMessage()); } catch (PaginationException $e) { $this->flashMessenger()->addErrorMessage($e->getMessage()); } return array('books' => array()); }
public function indexAction() { try { $this->queryFilter->setQueryParameters($this->paginatorInfoFactory->prepareFilterParams($this->params()->fromQuery())); /** @var PaginatorAdapter $paginator */ $paginator = $this->service->getFilteredResults($this->queryFilter, $hydrationMode = Query::HYDRATE_ARRAY); $paginatorInfo = $this->paginatorInfoFactory->create($paginator->count()); $data = array('data' => $paginator->getIterator()); if ($paginatorInfo->shouldDisplay()) { $data['pagination'] = $paginatorInfo->toArray(); } return new JsonModel($data); } catch (QueryFilterException $e) { throw new Exception\BadRequestException($e->getMessage(), Response::STATUS_CODE_400, $e); } catch (PaginationException $e) { throw new Exception\BadRequestException($e->getMessage(), Response::STATUS_CODE_400, $e); } catch (\PDOException $e) { throw new Exception\PDOServiceUnavailableException(); } }