mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-05 07:19:49 +00:00
add limit and offset for apicontroller
This commit is contained in:
parent
c185c35c44
commit
502894ecea
@ -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),
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user