From f78c1c0512699b8339e26a1354cc918e8d468f84 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 15 Nov 2023 15:58:41 +0100 Subject: [PATCH] adjust logic for calendar exports linked to person --- .../Export/LinkedToPerson/CountCalendars.php | 21 ++++++++++--------- .../StatCalendarAvgDuration.php | 18 ++++++++++++++-- .../StatCalendarSumDuration.php | 18 ++++++++++++++-- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Export/Export/LinkedToPerson/CountCalendars.php b/src/Bundle/ChillCalendarBundle/Export/Export/LinkedToPerson/CountCalendars.php index 8cad77f50..3e8ade4c7 100644 --- a/src/Bundle/ChillCalendarBundle/Export/Export/LinkedToPerson/CountCalendars.php +++ b/src/Bundle/ChillCalendarBundle/Export/Export/LinkedToPerson/CountCalendars.php @@ -104,23 +104,24 @@ class CountCalendars implements ExportInterface, GroupedExportInterface $qb = $this->calendarRepository->createQueryBuilder('cal'); $qb->select('COUNT(cal.id) AS export_result'); - $qb->leftJoin('cal.accompanyingPeriod', 'acp'); + $qb->leftJoin('cal.person', 'person'); if ($this->filterStatsByCenters) { $qb - ->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.AccompanyingPeriodParticipation::class.' acl_count_part - JOIN '.PersonCenterHistory::class.' acl_count_person_history WITH IDENTITY(acl_count_person_history.person) = IDENTITY(acl_count_part.person) - WHERE acl_count_part.accompanyingPeriod = acp.id AND acl_count_person_history.center IN (:authorized_centers) - ' + ->join('person.centerHistory', 'centerHistory') + ->where( + $qb->expr()->andX( + $qb->expr()->lte('centerHistory.startDate', 'cal.startDate'), + $qb->expr()->orX( + $qb->expr()->isNull('centerHistory.endDate'), + $qb->expr()->gt('centerHistory.endDate', 'cal.endDate') + ) ) ) - ->setParameter('authorized_centers', $centers); + ->andWhere($qb->expr()->in('centerHistory.center', ':centers')) + ->setParameter('centers', $centers); } - AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); - return $qb; } diff --git a/src/Bundle/ChillCalendarBundle/Export/Export/LinkedToPerson/StatCalendarAvgDuration.php b/src/Bundle/ChillCalendarBundle/Export/Export/LinkedToPerson/StatCalendarAvgDuration.php index 14aa59539..47bccb5d4 100644 --- a/src/Bundle/ChillCalendarBundle/Export/Export/LinkedToPerson/StatCalendarAvgDuration.php +++ b/src/Bundle/ChillCalendarBundle/Export/Export/LinkedToPerson/StatCalendarAvgDuration.php @@ -88,9 +88,23 @@ class StatCalendarAvgDuration implements ExportInterface, GroupedExportInterface $qb = $this->calendarRepository->createQueryBuilder('cal'); $qb->select('AVG(cal.endDate - cal.startDate) AS export_result'); - $qb->join('cal.accompanyingPeriod', 'acp'); + $qb->join('cal.person', 'person'); - AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + if ($this->filterStatsByCenters) { + $qb + ->join('person.centerHistory', 'centerHistory') + ->where( + $qb->expr()->andX( + $qb->expr()->lte('centerHistory.startDate', 'cal.startDate'), + $qb->expr()->orX( + $qb->expr()->isNull('centerHistory.endDate'), + $qb->expr()->gt('centerHistory.endDate', 'cal.endDate') + ) + ) + ) + ->andWhere($qb->expr()->in('centerHistory.center', ':centers')) + ->setParameter('centers', $centers); + } return $qb; } diff --git a/src/Bundle/ChillCalendarBundle/Export/Export/LinkedToPerson/StatCalendarSumDuration.php b/src/Bundle/ChillCalendarBundle/Export/Export/LinkedToPerson/StatCalendarSumDuration.php index 092286581..578988e7c 100644 --- a/src/Bundle/ChillCalendarBundle/Export/Export/LinkedToPerson/StatCalendarSumDuration.php +++ b/src/Bundle/ChillCalendarBundle/Export/Export/LinkedToPerson/StatCalendarSumDuration.php @@ -88,9 +88,23 @@ class StatCalendarSumDuration implements ExportInterface, GroupedExportInterface $qb = $this->calendarRepository->createQueryBuilder('cal'); $qb->select('SUM(cal.endDate - cal.startDate) AS export_result'); - $qb->join('cal.accompanyingPeriod', 'acp'); + $qb->join('cal.person', 'person'); - AccompanyingCourseExportHelper::addClosingMotiveExclusionClause($qb); + if ($this->filterStatsByCenters) { + $qb + ->join('person.centerHistory', 'centerHistory') + ->where( + $qb->expr()->andX( + $qb->expr()->lte('centerHistory.startDate', 'cal.startDate'), + $qb->expr()->orX( + $qb->expr()->isNull('centerHistory.endDate'), + $qb->expr()->gt('centerHistory.endDate', 'cal.endDate') + ) + ) + ) + ->andWhere($qb->expr()->in('centerHistory.center', ':centers')) + ->setParameter('centers', $centers); + } return $qb; }