From 6da297d1d273d9b566de552ab316a884d4938be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 29 Nov 2023 15:59:55 +0100 Subject: [PATCH] rename method newsWithDateFilter => currentNews --- .../Controller/NewsItemApiController.php | 4 ++-- .../Repository/NewsItemRepository.php | 13 ++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Controller/NewsItemApiController.php b/src/Bundle/ChillMainBundle/Controller/NewsItemApiController.php index 6df54c779..a44bcf989 100644 --- a/src/Bundle/ChillMainBundle/Controller/NewsItemApiController.php +++ b/src/Bundle/ChillMainBundle/Controller/NewsItemApiController.php @@ -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() ); diff --git a/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php b/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php index 44e1f2d39..3e918dfd1 100644 --- a/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php @@ -80,9 +80,12 @@ class NewsItemRepository implements ObjectRepository return $qb->getQuery()->getResult(); } - public function findWithDateFilter($limit = null, $offset = null) + /** + * @return list + */ + 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();