diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ReferrerFilterBetweenDates.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ReferrerFilterBetweenDates.php new file mode 100644 index 000000000..c58aad3bb --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ReferrerFilterBetweenDates.php @@ -0,0 +1,123 @@ +join('acp.userHistories', self::A) + ->andWhere( + "OVERLAPSI({$history}.startDate, {$history}.endDate),(:{$start}, :{$end}) = TRUE" + ) + ->andWhere( + "{$history}.user IN (:{$users})", + ) + ->setParameter($users, $data['accepted_referrers']) + ->setParameter($start, $this->rollingDateConverter->convert($data['start_date'])) + ->setParameter($end, $this->rollingDateConverter->convert($data['end_date'])); + } + + public function applyOn(): string + { + return Declarations::ACP_TYPE; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder + ->add('accepted_referrers', PickUserDynamicType::class, [ + 'multiple' => true, + ]) + ->add('start_date', PickRollingDateType::class, [ + 'label' => 'export.filter.course.by_referrer_between_dates.start date', + 'required' => true, + ]) + ->add('end_date', PickRollingDateType::class, [ + 'label' => 'export.filter.course.by_referrer_between_dates.end date', + 'required' => true, + ]); + } + + public function getFormDefaultData(): array + { + return [ + 'start_date' => new RollingDate(RollingDate::T_YEAR_CURRENT_START), + 'end_date' => new RollingDate(RollingDate::T_TODAY), + 'accepted_referrers' => [], + ]; + } + + public function describeAction($data, $format = 'string'): array + { + $users = []; + + foreach ($data['accepted_referrers'] as $r) { + $users[] = $this->userRender->renderString($r, []); + } + + return [ + 'exports.filter.course.by_referrer_between_dates.description', [ + 'agents' => implode(', ', $users), + 'start_date' => $this->rollingDateConverter->convert($data['start_date']), + 'end_date' => $this->rollingDateConverter->convert($data['end_date']), + ], ]; + } + + public function getTitle(): string + { + return 'export.filter.course.by_referrer_between_dates.title'; + } +} diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ReferrerFilterBetweenDatesTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ReferrerFilterBetweenDatesTest.php new file mode 100644 index 000000000..9b0eb4d72 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ReferrerFilterBetweenDatesTest.php @@ -0,0 +1,89 @@ +rollingDateConverter = self::$container->get(RollingDateConverterInterface::class); + $this->userRender = self::$container->get(UserRender::class); + } + + public function getFilter() + { + return new ReferrerFilterBetweenDates($this->rollingDateConverter, $this->userRender); + } + + public function getFormData() + { + self:self::bootKernel(); + $em = self::$container->get(EntityManagerInterface::class); + + $users = $em->createQueryBuilder() + ->from(User::class, 'u') + ->select('u') + ->getQuery() + ->setMaxResults(1) + ->getResult(); + + return [ + [ + 'accepted_referrers' => $users[0], + 'start_date' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), + 'end_date' => new RollingDate(RollingDate::T_TODAY), + ], + ]; + } + + public function getQueryBuilders() + { + self::bootKernel(); + + $em = self::$container->get(EntityManagerInterface::class); + + yield $em->createQueryBuilder() + ->from(AccompanyingPeriod::class, 'acp') + ->select('acp.id'); + + $qb = $em->createQueryBuilder(); + $qb + ->from(AccompanyingPeriod\AccompanyingPeriodWork::class, 'acpw') + ->join('acpw.accompanyingPeriod', 'acp') + ->join('acp.participations', 'acppart') + ->join('acppart.person', 'person') + ; + + $qb->select('COUNT(DISTINCT acpw.id) as export_result'); + + yield $qb; + } +} diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ReferrerFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ReferrerFilterTest.php index a56741bd3..52173fe8c 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ReferrerFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/AccompanyingCourseFilters/ReferrerFilterTest.php @@ -31,7 +31,7 @@ final class ReferrerFilterTest extends AbstractFilterTest { self::bootKernel(); - $this->filter = self::$container->get('chill.person.export.filter_referrer'); + $this->filter = self::$container->get(ReferrerFilter::class); } public function getFilter() diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml index 38b5d5041..d488df8d6 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml @@ -96,11 +96,14 @@ services: tags: - { name: chill.export_filter, alias: accompanyingcourse_activeonedaybetweendates_filter } - chill.person.export.filter_referrer: - class: Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\ReferrerFilter + Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\ReferrerFilter: tags: - { name: chill.export_filter, alias: accompanyingcourse_referrer_filter } + Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\ReferrerFilterBetweenDates: + tags: + - { name: chill.export_filter, alias: accompanyingcourse_referrer_filter_between_dates } + chill.person.export.filter_openbetweendates: class: Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters\OpenBetweenDatesFilter tags: diff --git a/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml b/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml index af85b2217..f94f9d578 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml +++ b/src/Bundle/ChillPersonBundle/translations/messages+intl-icu.fr.yaml @@ -145,6 +145,12 @@ exports: describe: >- Uniquement les parcours qui ne sont pas localisés à une adresse de référence, à la date du {date_calc, date, medium} + Les agents traitants au { agent_at, date, medium }, seulement {agents} + + by_referrer_between_dates: + description: >- + Filtré par référent du parcours, entre deux dates: depuis le {start_date, date, medium}, jusqu'au {end_date, date, medium}, seulement {agents} + 'total persons matching the search pattern': >- { total, plural, =0 {Aucun usager ne correspond aux termes de recherche} diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index ec6036950..e4995d207 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -1191,6 +1191,10 @@ export: "Filtered by user main scope: only %scope%": "Filtré par service du référent: uniquement %scope%" by_referrer: Computation date for referrer: Date à laquelle le référent était actif + by_referrer_between_dates: + title: Filtrer les parcours par référent (entre deux dates) + start date: Le référent était actif après le + end date: Le référent était actif avant le having_temporarily: label: Qualité de la localisation Having a temporarily location: Ayant une localisation temporaire