Beispiel #1
0
 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());
 }
Beispiel #2
0
 public function testSetQueryParametersWithAllPossibleOptions()
 {
     $data = ['$fields' => 'id,author,title', '$sort' => '-year,price', '$limit' => '5', '$page' => '1', 'year' => '$between(2014,2005)', 'price' => ['$min(20)', '$max(50)'], 'name' => ['$startswith("a")', '$endswith("z")'], 'status' => 'packaging,shipping', 'author' => '"Robert C. Marting"'];
     $this->testedObject->setQueryParameters($data);
     $resultCriteria = $this->testedObject->getCriteria();
     $this->assertCount(12, $resultCriteria);
     $this->assertNotNull($this->testedObject->getCriteria(Criteria::TYPE_SPECIAL_LIMIT));
     $this->assertNotNull($this->testedObject->getCriteria(Criteria::TYPE_SPECIAL_OFFSET));
 }
Beispiel #3
0
 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();
     }
 }