diff --git a/src/Bundle/ChillMainBundle/Controller/NewsItemApiController.php b/src/Bundle/ChillMainBundle/Controller/NewsItemApiController.php index 25fe7620f..5224228a8 100644 --- a/src/Bundle/ChillMainBundle/Controller/NewsItemApiController.php +++ b/src/Bundle/ChillMainBundle/Controller/NewsItemApiController.php @@ -36,7 +36,10 @@ class NewsItemApiController { $total = $this->newsItemRepository->countWithDateFilter(); $paginator = $this->paginatorFactory->create($total); - $newsItems = $this->newsItemRepository->findWithDateFilter(); + $newsItems = $this->newsItemRepository->findWithDateFilter( + $limit = $paginator->getItemsPerPage(), + $offset = $paginator->getCurrentPage()->getFirstItemNumber() + ); return new JsonResponse($this->serializer->serialize( new Collection(array_values($newsItems), $paginator), diff --git a/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php b/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php index b9b0f8727..88b597647 100644 --- a/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php @@ -80,9 +80,19 @@ class NewsItemRepository implements ObjectRepository return $qb->getQuery()->getResult(); } - public function findWithDateFilter() + public function findWithDateFilter($limit = null, $offset = null) { - return $this->buildQueryWithDateFilter() + $qb = $this->buildQueryWithDateFilter(); + + if ($limit) { + $qb->setMaxResults($limit); + } + + if ($offset) { + $qb->setFirstResult($offset); + } + + return $qb ->getQuery() ->getResult(); }