diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php b/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php index 8988f4278..a9f794888 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountAccompanyingCourse.php @@ -101,7 +101,7 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface ->andWhere('acp.step != :count_acp_step') ->leftJoin('acp.participations', 'acppart') ->leftJoin('acppart.person', 'person') - ->andWhere('acppart.startDate != acppart.endDate') + ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') ->andWhere( $qb->expr()->exists( 'SELECT 1 FROM ' . PersonCenterHistory::class . ' acl_count_person_history WHERE acl_count_person_history.person = person diff --git a/src/Bundle/ChillPersonBundle/Export/Export/StatAccompanyingCourseDuration.php b/src/Bundle/ChillPersonBundle/Export/Export/StatAccompanyingCourseDuration.php index a0e68beea..c124f0227 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/StatAccompanyingCourseDuration.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/StatAccompanyingCourseDuration.php @@ -16,7 +16,6 @@ use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\GroupedExportInterface; use Chill\MainBundle\Form\Type\ChillDateType; use Chill\PersonBundle\Entity\AccompanyingPeriod; -use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; use Chill\PersonBundle\Entity\Person\PersonCenterHistory; use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; @@ -53,7 +52,7 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn public function getDescription(): string { - return 'Create an average of accompanying courses duration according to various filters'; + return 'Create an average of accompanying courses duration of each person participation to accompanying course, according to filters on persons, accompanying course'; } public function getGroup(): string @@ -63,21 +62,37 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn public function getLabels($key, array $values, $data) { - if ('export_result' !== $key) { - throw new LogicException("the key {$key} is not used by this export"); - } + return static function ($value) use ($key) { + if ('_header' === $value) { + switch ($key) { + case 'avg_export_result': + return 'export.export.acp_stats.avg_duration'; - $labels = array_combine($values, $values); - $labels['_header'] = $this->getTitle(); + case 'count_acppart_export_result': + return 'export.export.acp_stats.count_participations'; - return static function ($value) use ($labels) { - return $labels[$value]; + case 'count_acp_export_result': + return 'export.export.acp_stats.count_acps'; + + case 'count_pers_export_result': + return 'export.export.acp_stats.count_persons'; + + default: + throw new LogicException('key not supported: ' . $key); + } + } + + if (null === $value) { + return ''; + } + + return $value; }; } public function getQueryKeys($data): array { - return ['export_result']; + return ['avg_export_result', 'count_acp_export_result', 'count_acppart_export_result', 'count_pers_export_result']; } public function getResult($query, $data) @@ -87,7 +102,7 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn public function getTitle(): string { - return 'Accompanying courses duration'; + return 'Accompanying courses participation duration and number of participations'; } public function getType(): string @@ -104,22 +119,28 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn $qb = $this->repository->createQueryBuilder('acp'); $qb + ->select('AVG( + LEAST(acppart.endDate, COALESCE(acp.closingDate, :force_closingDate)) + - GREATEST(acppart.startDate, COALESCE(acp.openingDate, :force_closingDate)) + ) AS avg_export_result') + ->addSelect('COUNT(DISTINCT acppart.id) AS count_acppart_export_result') + ->addSelect('COUNT(DISTINCT person.id) AS count_pers_export_result') + ->addSelect('COUNT(DISTINCT acp.id) AS count_acp_export_result') + ->setParameter('force_closingDate', $data['closingdate']) + ->leftJoin('acp.participations', 'acppart') + ->leftJoin('acppart.person', 'person') + ->andWhere('acp.step != :count_acp_step') + ->andWhere('acppart.startDate != acppart.endDate OR acppart.endDate IS NULL') ->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) + 'SELECT 1 FROM ' . PersonCenterHistory::class . ' acl_count_person_history WHERE acl_count_person_history.person = person + AND acl_count_person_history.center IN (:authorized_centers) ' ) ) + ->setParameter('count_acp_step', AccompanyingPeriod::STEP_DRAFT) ->setParameter('authorized_centers', $centers); - $qb - ->select('AVG( - COALESCE(acp.closingDate, :force_closingDate) - acp.openingDate - ) AS export_result') - ->setParameter('force_closingDate', $data['closingdate']); - return $qb; } @@ -132,6 +153,7 @@ class StatAccompanyingCourseDuration implements ExportInterface, GroupedExportIn { return [ Declarations::ACP_TYPE, + Declarations::PERSON_TYPE, ]; } } diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index bdedea895..022ac5654 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -359,8 +359,8 @@ Count people participating in an accompanying course by various parameters.: Com Exports of accompanying courses: Exports des parcours d'accompagnement Count accompanying courses: Nombre de parcours Count accompanying courses by various parameters: Compte le nombre de parcours en fonction de différents filtres. -Accompanying courses duration: Durée moyenne des parcours -Create an average of accompanying courses duration according to various filters: Moyenne de la durée des parcours en jours, selon différents filtres. +Accompanying courses participation duration and number of participations: Durée moyenne et nombre des participation des usagers aux parcours +Create an average of accompanying courses duration of each person participation to accompanying course, according to filters on persons, accompanying course: Crée un rapport qui comptabilise la moyenne de la durée de participation de chaque usager concerné aux parcours, avec différents filtres, notamment sur les usagers concernés. Closingdate to apply: Date de fin à prendre en compte lorsque le parcours n'est pas clotûré Exports of social work actions: Exports des actions d'accompagnement @@ -989,6 +989,12 @@ notification: Notify any: Notifier d'autres utilisateurs export: + export: + acp_stats: + avg_duration: Moyenne de la durée de participation de chaque usager concerné + count_participations: Nombre de participations distinctes + count_persons: Nombre d'usagers concernés distincts + count_acps: Nombre de parcours distincts aggregator: course: by_referrer: