adjust logic for calendar exports linked to person

This commit is contained in:
Julie Lenaerts 2023-11-15 15:58:41 +01:00
parent c3ced7fb6e
commit f78c1c0512
3 changed files with 43 additions and 14 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}