rename method newsWithDateFilter => currentNews

This commit is contained in:
Julien Fastré 2023-11-29 15:59:55 +01:00
parent 6787612071
commit 6da297d1d2
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
2 changed files with 10 additions and 7 deletions

View File

@ -34,9 +34,9 @@ class NewsItemApiController
*/
public function listCurrentNewsItems(): JsonResponse
{
$total = $this->newsItemRepository->countWithDateFilter();
$total = $this->newsItemRepository->countCurrentNews();
$paginator = $this->paginatorFactory->create($total);
$newsItems = $this->newsItemRepository->findWithDateFilter(
$newsItems = $this->newsItemRepository->findCurrentNews(
$paginator->getItemsPerPage(),
$paginator->getCurrentPage()->getFirstItemNumber()
);

View File

@ -80,9 +80,12 @@ class NewsItemRepository implements ObjectRepository
return $qb->getQuery()->getResult();
}
public function findWithDateFilter($limit = null, $offset = null)
/**
* @return list<NewsItem>
*/
public function findCurrentNews(int $limit = null, int $offset = null): array
{
$qb = $this->buildQueryWithDateFilter();
$qb = $this->buildQueryCurrentNews();
if ($limit) {
$qb->setMaxResults($limit);
@ -107,15 +110,15 @@ class NewsItemRepository implements ObjectRepository
->getSingleScalarResult();
}
public function countWithDateFilter()
public function countCurrentNews()
{
return $this->buildQueryWithDateFilter()
return $this->buildQueryCurrentNews()
->select('COUNT(n)')
->getQuery()
->getSingleScalarResult();
}
public function buildQueryWithDateFilter(): QueryBuilder
private function buildQueryCurrentNews(): QueryBuilder
{
$now = $this->clock->now();