diff --git a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php index dea2099e1..e35a9619b 100644 --- a/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php +++ b/src/Bundle/ChillCalendarBundle/Controller/CalendarController.php @@ -227,6 +227,7 @@ class CalendarController extends AbstractController 'accompanyingCourse' => $accompanyingPeriod, 'paginator' => $paginator, 'filterOrder' => $filterOrder, + 'nbIgnored' => $this->calendarACLAwareRepository->countIgnoredByAccompanyingPeriod($accompanyingPeriod, $from, $to), 'hasDocs' => 0 < $this->docGeneratorTemplateRepository->countByEntity(Calendar::class), ]); } @@ -258,6 +259,7 @@ class CalendarController extends AbstractController 'person' => $person, 'paginator' => $paginator, 'filterOrder' => $filterOrder, + 'nbIgnored' => $this->calendarACLAwareRepository->countIgnoredByPerson($person, $from, $to), 'hasDocs' => 0 < $this->docGeneratorTemplateRepository->countByEntity(Calendar::class), ]); } diff --git a/src/Bundle/ChillCalendarBundle/Repository/CalendarACLAwareRepository.php b/src/Bundle/ChillCalendarBundle/Repository/CalendarACLAwareRepository.php index 15d0d83c0..6861df341 100644 --- a/src/Bundle/ChillCalendarBundle/Repository/CalendarACLAwareRepository.php +++ b/src/Bundle/ChillCalendarBundle/Repository/CalendarACLAwareRepository.php @@ -64,31 +64,38 @@ class CalendarACLAwareRepository implements CalendarACLAwareRepositoryInterface return $qb; } + public function buildQueryByAccompanyingPeriodIgnoredByDates(AccompanyingPeriod $period, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): QueryBuilder + { + $qb = $this->em->createQueryBuilder(); + $qb->from(Calendar::class, 'c'); + + $andX = $qb->expr()->andX($qb->expr()->eq('c.accompanyingPeriod', ':period')); + $qb->setParameter('period', $period); + + if (null !== $startDate) { + $andX->add($qb->expr()->lt('c.startDate', ':startDate')); + $qb->setParameter('startDate', $startDate); + } + + if (null !== $endDate) { + $andX->add($qb->expr()->gt('c.endDate', ':endDate')); + $qb->setParameter('endDate', $endDate); + } + + $qb->where($andX); + + return $qb; + } + /** * Base implementation. The list of allowed accompanying period is retrieved "manually" from @see{AccompanyingPeriodACLAwareRepository}. */ public function buildQueryByPerson(Person $person, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): QueryBuilder { - // find the reachable accompanying periods for person - $periods = $this->accompanyingPeriodACLAwareRepository->findByPerson($person, AccompanyingPeriodVoter::SEE); - $qb = $this->em->createQueryBuilder() ->from(Calendar::class, 'c'); - $qb - ->where( - $qb->expr()->orX( - // the calendar where the person is the main person: - $qb->expr()->eq('c.person', ':person'), - // when the calendar is in a reachable period, and contains person - $qb->expr()->andX( - $qb->expr()->in('c.accompanyingPeriod', ':periods'), - $qb->expr()->isMemberOf(':person', 'c.persons') - ) - ) - ) - ->setParameter('person', $person) - ->setParameter('periods', $periods); + $this->addQueryByPersonWithoutDate($qb, $person); // filter by date if (null !== $startDate) { @@ -104,6 +111,30 @@ class CalendarACLAwareRepository implements CalendarACLAwareRepositoryInterface return $qb; } + /** + * Base implementation. The list of allowed accompanying period is retrieved "manually" from @see{AccompanyingPeriodACLAwareRepository}. + */ + public function buildQueryByPersonIgnoredByDates(Person $person, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): QueryBuilder + { + $qb = $this->em->createQueryBuilder() + ->from(Calendar::class, 'c'); + + $this->addQueryByPersonWithoutDate($qb, $person); + + // filter by date + if (null !== $startDate) { + $qb->andWhere($qb->expr()->lt('c.startDate', ':startDate')) + ->setParameter('startDate', $startDate); + } + + if (null !== $endDate) { + $qb->andWhere($qb->expr()->gt('c.endDate', ':endDate')) + ->setParameter('endDate', $endDate); + } + + return $qb; + } + public function countByAccompanyingPeriod(AccompanyingPeriod $period, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): int { $qb = $this->buildQueryByAccompanyingPeriod($period, $startDate, $endDate)->select('count(c)'); @@ -119,6 +150,21 @@ class CalendarACLAwareRepository implements CalendarACLAwareRepositoryInterface ->getSingleScalarResult(); } + public function countIgnoredByAccompanyingPeriod(AccompanyingPeriod $period, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): int + { + $qb = $this->buildQueryByAccompanyingPeriodIgnoredByDates($period, $startDate, $endDate)->select('count(c)'); + + return $qb->getQuery()->getSingleScalarResult(); + } + + public function countIgnoredByPerson(Person $person, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): int + { + return $this->buildQueryByPersonIgnoredByDates($person, $startDate, $endDate) + ->select('COUNT(c)') + ->getQuery() + ->getSingleScalarResult(); + } + /** * @return array|Calendar[] */ @@ -160,4 +206,25 @@ class CalendarACLAwareRepository implements CalendarACLAwareRepositoryInterface return $qb->getQuery()->getResult(); } + + private function addQueryByPersonWithoutDate(QueryBuilder $qb, Person $person): void + { + // find the reachable accompanying periods for person + $periods = $this->accompanyingPeriodACLAwareRepository->findByPerson($person, AccompanyingPeriodVoter::SEE); + + $qb + ->where( + $qb->expr()->orX( + // the calendar where the person is the main person: + $qb->expr()->eq('c.person', ':person'), + // when the calendar is in a reachable period, and contains person + $qb->expr()->andX( + $qb->expr()->in('c.accompanyingPeriod', ':periods'), + $qb->expr()->isMemberOf(':person', 'c.persons') + ) + ) + ) + ->setParameter('person', $person) + ->setParameter('periods', $periods); + } } diff --git a/src/Bundle/ChillCalendarBundle/Repository/CalendarACLAwareRepositoryInterface.php b/src/Bundle/ChillCalendarBundle/Repository/CalendarACLAwareRepositoryInterface.php index d860c3470..70fb02590 100644 --- a/src/Bundle/ChillCalendarBundle/Repository/CalendarACLAwareRepositoryInterface.php +++ b/src/Bundle/ChillCalendarBundle/Repository/CalendarACLAwareRepositoryInterface.php @@ -32,6 +32,18 @@ interface CalendarACLAwareRepositoryInterface */ public function countByPerson(Person $person, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): int; + /** + * Return the number or calendars associated with an accompanyign period which **does not** match the date conditions. + */ + public function countIgnoredByAccompanyingPeriod(AccompanyingPeriod $period, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): int; + + /** + * Return the number or calendars associated with a person which **does not** match the date conditions. + * + * See condition on @see{self::findByPerson}. + */ + public function countIgnoredByPerson(Person $person, ?DateTimeImmutable $startDate, ?DateTimeImmutable $endDate): int; + /** * @return array|Calendar[] */ diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig index 56c1ba880..d85c5237e 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByAccompanyingCourse.html.twig @@ -27,9 +27,11 @@ {% if calendarItems|length == 0 %}
- {{ "There is no calendar items."|trans }} - + {% if nbIgnored == 0 %} + {{ "There is no calendar items."|trans }} + {% else %} + {{ 'chill_calendar.There are count ignored calendars by date filter'|trans({'nbIgnored': nbIgnored}) }} + {% endif %}
{% else %} {{ include('@ChillCalendar/Calendar/_list.html.twig', {context: 'accompanying_course'}) }} diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByPerson.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByPerson.html.twig index dc849202e..7c5fdc639 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByPerson.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/listByPerson.html.twig @@ -26,11 +26,11 @@ {% if calendarItems|length == 0 %}- {{ "There is no calendar items."|trans }} - - {{ 'Create'|trans }} - + {% if nbIgnored == 0 %} + {{ "There is no calendar items."|trans }} + {% else %} + {{ 'chill_calendar.There are count ignored calendars by date filter'|trans({'nbIgnored': nbIgnored}) }} + {% endif %}
{% else %} {{ include ('@ChillCalendar/Calendar/_list.html.twig', {context: 'person'}) }} diff --git a/src/Bundle/ChillCalendarBundle/translations/messages+intl-icu.fr.yml b/src/Bundle/ChillCalendarBundle/translations/messages+intl-icu.fr.yml new file mode 100644 index 000000000..4bbc105b9 --- /dev/null +++ b/src/Bundle/ChillCalendarBundle/translations/messages+intl-icu.fr.yml @@ -0,0 +1,8 @@ +chill_calendar: + There are count ignored calendars by date filter: >- + {nbIgnored, plural, + =0 {Il n'y a aucun rendez-vous ignoré par le filtre de date.} + one {Il y a un rendez-vous ignoré par le filtre de date. Modifiez le filtre de date pour le voir apparaitre.} + few {# rendez-vous sont ignorés par le filtre de date. Modifiez le filtre de date pour les voir apparaitre.} + other {# rendez-vous sont ignorés par le filtre de date. Modifiez le filtre de date pour les voir apparaitre.} + }