diff --git a/.changes/unreleased/Feature-20231218-153151.yaml b/.changes/unreleased/Feature-20231218-153151.yaml new file mode 100644 index 000000000..8a842bfa2 --- /dev/null +++ b/.changes/unreleased/Feature-20231218-153151.yaml @@ -0,0 +1,6 @@ +kind: Feature +body: Create new filter for persons having a participation in an accompanying period + during a certain time span +time: 2023-12-18T15:31:51.489901829+01:00 +custom: + Issue: "231" diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php new file mode 100644 index 000000000..289af5f07 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php @@ -0,0 +1,88 @@ +andWhere( + $qb->expr()->exists( + 'SELECT 1 FROM '.AccompanyingPeriodParticipation::class." {$p}_acp JOIN {$p}_acp.accompanyingPeriod {$p}_acpp ". + "WHERE {$p}_acp.person = person ". + "AND OVERLAPSI({$p}_acp.startDate, {$p}_acp.endDate), (:{$p}_date_after, :{$p}_date_before) = TRUE ". + "AND OVERLAPSI({$p}_acpp.openingDate, {$p}_acpp.closingDate), (:{$p}_date_after, :{$p}_date_before) = TRUE" + ) + ) + ->setParameter("{$p}_date_after", $this->rollingDateConverter->convert($data['date_after']), Types::DATE_IMMUTABLE) + ->setParameter("{$p}_date_before", $this->rollingDateConverter->convert($data['date_before']), Types::DATE_IMMUTABLE); + } + + public function applyOn(): string + { + return Declarations::PERSON_TYPE; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('date_after', PickRollingDateType::class, [ + 'label' => 'export.filter.person.with_participation_between_dates.date_after', + ]); + + $builder->add('date_before', PickRollingDateType::class, [ + 'label' => 'export.filter.person.with_participation_between_dates.date_before', + ]); + } + + public function getFormDefaultData(): array + { + return [ + 'date_after' => new RollingDate(RollingDate::T_YEAR_CURRENT_START), + 'date_before' => new RollingDate(RollingDate::T_TODAY), + ]; + } + + public function describeAction($data, $format = 'string') + { + return ['export.filter.person.with_participation_between_dates.Filtered by participations during period: between %dateafter% and %datebefore%', [ + '%dateafter%' => $this->rollingDateConverter->convert($data['date_after'])->format('d-m-Y'), + '%datebefore%' => $this->rollingDateConverter->convert($data['date_before'])->format('d-m-Y'), + ]]; + } + + public function getTitle() + { + return 'export.filter.person.with_participation_between_dates.title'; + } +} diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilterTest.php new file mode 100644 index 000000000..d9c58e743 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilterTest.php @@ -0,0 +1,63 @@ +filter = self::$container->get(WithParticipationBetweenDatesFilter::class); + } + + public function getFilter() + { + return $this->filter; + } + + public function getFormData() + { + return [ + [ + 'date_after' => new RollingDate(RollingDate::T_YEAR_CURRENT_START), + 'date_before' => new RollingDate(RollingDate::T_TODAY), + ], + ]; + } + + public function getQueryBuilders() + { + self::bootKernel(); + + $em = self::$container->get(EntityManagerInterface::class); + + return [ + $em->createQueryBuilder() + ->select('person.id') + ->from(Person::class, 'person'), + ]; + } +} diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml index d25a3b9e6..c0ed03115 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml @@ -116,6 +116,10 @@ services: tags: - { name: chill.export_filter, alias: person_without_household_composition_filter } + Chill\PersonBundle\Export\Filter\PersonFilters\WithParticipationBetweenDatesFilter: + tags: + - { name: chill.export_filter, alias: person_with_participation_between_dates_filter } + ## Aggregators chill.person.export.aggregator_nationality: class: Chill\PersonBundle\Export\Aggregator\PersonAggregators\NationalityAggregator diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 82c538c69..783bc6be0 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -1142,6 +1142,11 @@ export: Filtered by person\'s address status computed at %datecalc%, only %statuses%: Filtré par comparaison à l'adresse de référence, calculé à %datecalc%, seulement %statuses% Status: Statut Address at date: Adresse à la date + with_participation_between_dates: + date_after: Concerné par un parcours après le + date_before: Concerné par un parcours avant le + title: Filtrer les usagers ayant été associés à un parcours ouverts un jour dans la période de temps indiquée + 'Filtered by participations during period: between %dateafter% and %datebefore%': 'Filtré par personne concerné par un parcours dans la periode entre: %dateafter% et %datebefore%' course: having_info_within_interval: