From fc7d2fcca3e1d9983f8b536b68d92dbc5b591068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 6 Jun 2022 17:50:21 +0200 Subject: [PATCH] fix cs --- .../Controller/CalendarController.php | 57 +++++++-------- .../ChillCalendarBundle/Form/CalendarType.php | 5 +- .../Repository/CalendarACLAwareRepository.php | 73 ++++++++++--------- .../CalendarACLAwareRepositoryInterface.php | 17 ++++- .../Templating/Listing/FilterOrderHelper.php | 10 +-- .../Listing/FilterOrderHelperBuilder.php | 2 +- 6 files changed, 87 insertions(+), 77 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index 78f134935..1a680e990 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -19,16 +19,15 @@ use Chill\CalendarBundle\Repository\CalendarRepository; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Repository\UserRepository; -use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\MainBundle\Templating\Listing\FilterOrderHelper; use Chill\MainBundle\Templating\Listing\FilterOrderHelperFactoryInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Person; use Chill\ThirdPartyBundle\Entity\ThirdParty; +use DateTimeImmutable; use Exception; use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Form; use Symfony\Component\Form\FormInterface; @@ -40,10 +39,10 @@ use Symfony\Component\Serializer\SerializerInterface; class CalendarController extends AbstractController { - private CalendarRepository $calendarRepository; - private CalendarACLAwareRepositoryInterface $calendarACLAwareRepository; + private CalendarRepository $calendarRepository; + private FilterOrderHelperFactoryInterface $filterOrderHelperFactory; private LoggerInterface $logger; @@ -203,32 +202,24 @@ class CalendarController extends AbstractController $filterOrder = $this->buildListFilterOrder(); ['from' => $from, 'to' => $to] = $filterOrder->getDateRangeData('startDate'); - $total = $this->calendarACLAwareRepository - ->countByAccompanyingPeriod($accompanyingPeriod, $from, $to); - $paginator = $this->paginator->create($total); - $calendarItems = $this->calendarACLAwareRepository->findByAccompanyingPeriod( - $accompanyingPeriod, - $from, - $to, - ['startDate' => 'DESC'], - $paginator->getCurrentPageFirstItemNumber(), - $paginator->getItemsPerPage() - ); + $total = $this->calendarACLAwareRepository + ->countByAccompanyingPeriod($accompanyingPeriod, $from, $to); + $paginator = $this->paginator->create($total); + $calendarItems = $this->calendarACLAwareRepository->findByAccompanyingPeriod( + $accompanyingPeriod, + $from, + $to, + ['startDate' => 'DESC'], + $paginator->getCurrentPageFirstItemNumber(), + $paginator->getItemsPerPage() + ); - return $this->render('@ChillCalendar/Calendar/listByAccompanyingCourse.html.twig', [ - 'calendarItems' => $calendarItems, - 'accompanyingCourse' => $accompanyingPeriod, - 'paginator' => $paginator, - 'filterOrder' => $filterOrder, - ]); - } - - private function buildListFilterOrder(): FilterOrderHelper - { - $filterOrder = $this->filterOrderHelperFactory->create(self::class); - $filterOrder->addDateRange('startDate', 'chill_calendar.start date filter', new \DateTimeImmutable('3 days ago'), null); - - return $filterOrder->build(); + return $this->render('@ChillCalendar/Calendar/listByAccompanyingCourse.html.twig', [ + 'calendarItems' => $calendarItems, + 'accompanyingCourse' => $accompanyingPeriod, + 'paginator' => $paginator, + 'filterOrder' => $filterOrder, + ]); } /** @@ -394,6 +385,14 @@ class CalendarController extends AbstractController ]); } + private function buildListFilterOrder(): FilterOrderHelper + { + $filterOrder = $this->filterOrderHelperFactory->create(self::class); + $filterOrder->addDateRange('startDate', 'chill_calendar.start date filter', new DateTimeImmutable('3 days ago'), null); + + return $filterOrder->build(); + } + private function buildParamsToUrl(?User $user, ?AccompanyingPeriod $accompanyingPeriod): array { $params = []; diff --git a/src/Bundle/ChillCalendarBundle/Form/CalendarType.php b/src/Bundle/ChillCalendarBundle/Form/CalendarType.php index fc3db2d43..05fa11524 100644 --- a/src/Bundle/ChillCalendarBundle/Form/CalendarType.php +++ b/src/Bundle/ChillCalendarBundle/Form/CalendarType.php @@ -18,12 +18,9 @@ use Chill\MainBundle\Form\DataTransformer\IdToLocationDataTransformer; use Chill\MainBundle\Form\DataTransformer\IdToUserDataTransformer; use Chill\MainBundle\Form\DataTransformer\IdToUsersDataTransformer; use Chill\MainBundle\Form\Type\CommentType; +use Chill\MainBundle\Form\Type\PrivateCommentType; use Chill\PersonBundle\Form\DataTransformer\PersonsToIdDataTransformer; use Chill\ThirdPartyBundle\Form\DataTransformer\ThirdPartiesToIdDataTransformer; -use Chill\MainBundle\Form\Type\PrivateCommentType; -use Chill\MainBundle\Templating\TranslatableStringHelper; -use Chill\PersonBundle\Entity\Person; -use Chill\ThirdPartyBundle\Entity\ThirdParty; use DateTimeImmutable; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\AbstractType; diff --git a/src/Bundle/ChillCalendarBundle/Repository/CalendarACLAwareRepository.php b/src/Bundle/ChillCalendarBundle/Repository/CalendarACLAwareRepository.php index e0a4ec0b0..4832d2735 100644 --- a/src/Bundle/ChillCalendarBundle/Repository/CalendarACLAwareRepository.php +++ b/src/Bundle/ChillCalendarBundle/Repository/CalendarACLAwareRepository.php @@ -1,9 +1,19 @@ em = $em; } - - /** - * @return array|Calendar[] - */ - public function findByAccompanyingPeriod(AccompanyingPeriod $period, ?\DateTimeImmutable $startDate, ?\DateTimeImmutable $endDate, ?array $orderBy = [], ?int $offset = null, ?int $limit = null): array - { - $qb = $this->buildQueryByAccompanyingPeriod($period, $startDate, $endDate)->select('c'); - - foreach ($orderBy as $sort => $order) { - $qb->addOrderBy('c.'.$sort, $order); - } - - if (null !== $offset) { - $qb->setFirstResult($offset); - } - - if (null !== $limit) { - $qb->setMaxResults($limit); - } - - return $qb->getQuery()->getResult(); - } - - public function countByAccompanyingPeriod(AccompanyingPeriod $period, ?\DateTimeImmutable $startDate, ?\DateTimeImmutable $endDate): int - { - $qb = $this->buildQueryByAccompanyingPeriod($period, $startDate, $endDate)->select('count(c)'); - - return $qb->getQuery()->getSingleScalarResult(); - } - - public function buildQueryByAccompanyingPeriod(AccompanyingPeriod $period, ?\DateTimeImmutable $startDate, ?\DateTimeImmutable $endDate): QueryBuilder + public function buildQueryByAccompanyingPeriod(AccompanyingPeriod $period, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): QueryBuilder { $qb = $this->em->createQueryBuilder(); $qb->from(Calendar::class, 'c'); @@ -72,4 +49,32 @@ class CalendarACLAwareRepository implements CalendarACLAwareRepositoryInterface return $qb; } + public function countByAccompanyingPeriod(AccompanyingPeriod $period, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): int + { + $qb = $this->buildQueryByAccompanyingPeriod($period, $startDate, $endDate)->select('count(c)'); + + return $qb->getQuery()->getSingleScalarResult(); + } + + /** + * @return array|Calendar[] + */ + public function findByAccompanyingPeriod(AccompanyingPeriod $period, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate, ?array $orderBy = [], ?int $offset = null, ?int $limit = null): array + { + $qb = $this->buildQueryByAccompanyingPeriod($period, $startDate, $endDate)->select('c'); + + foreach ($orderBy as $sort => $order) { + $qb->addOrderBy('c.' . $sort, $order); + } + + if (null !== $offset) { + $qb->setFirstResult($offset); + } + + if (null !== $limit) { + $qb->setMaxResults($limit); + } + + return $qb->getQuery()->getResult(); + } } diff --git a/src/Bundle/ChillCalendarBundle/Repository/CalendarACLAwareRepositoryInterface.php b/src/Bundle/ChillCalendarBundle/Repository/CalendarACLAwareRepositoryInterface.php index c31a39e33..bc62a6a65 100644 --- a/src/Bundle/ChillCalendarBundle/Repository/CalendarACLAwareRepositoryInterface.php +++ b/src/Bundle/ChillCalendarBundle/Repository/CalendarACLAwareRepositoryInterface.php @@ -1,17 +1,26 @@ getFormData()['checkboxes'][$name]; } - public function getDateRanges(): array + public function getCheckboxes(): array { - return $this->dateRanges; + return $this->checkboxes; } /** @@ -99,9 +99,9 @@ class FilterOrderHelper return $this->getFormData()['dateRanges'][$name]; } - public function getCheckboxes(): array + public function getDateRanges(): array { - return $this->checkboxes; + return $this->dateRanges; } public function getQueryString(): ?string diff --git a/src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelperBuilder.php b/src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelperBuilder.php index 37903af60..66daf1b3e 100644 --- a/src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelperBuilder.php +++ b/src/Bundle/ChillMainBundle/Templating/Listing/FilterOrderHelperBuilder.php @@ -11,7 +11,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Templating\Listing; -use \DateTimeImmutable; +use DateTimeImmutable; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\HttpFoundation\RequestStack;