From 5b2a2a1bc5699f04530eb843918c56331c004e73 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 13 Dec 2023 17:45:08 +0100 Subject: [PATCH 1/8] Add WithParticipationBetweenDatesFilter to ChillPersonBundle This update adds a new filter, WithParticipationBetweenDatesFilter, to the ChillPersonBundle. This filter helps to find persons who participated in any parcours between specified date ranges. Additionally, relevant French translations have been updated and the filter has been registered in the services configuration file. --- .../WithParticipationBetweenDatesFilter.php | 96 +++++++++++++++++++ .../config/services/exports_person.yaml | 4 + .../translations/messages.fr.yml | 4 + 3 files changed, 104 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php 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..52d788894 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php @@ -0,0 +1,96 @@ +andWhere( + $qb->expr()->exists( + 'SELECT 1 FROM '.AccompanyingPeriodParticipation::class." {$p}_acpp ". + "WHERE {$p}_acpp.person = person ". + "AND OVERLAPSI (acpp.startDate, acpp.endDate), (:{$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_PREVIOUS_START), + 'date_before' => new RollingDate(RollingDate::T_TODAY), + ]; + } + + public function describeAction($data, $format = 'string') + { + return ['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/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..578bdb8d0 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -1142,6 +1142,10 @@ 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 course: having_info_within_interval: From b9890d13026b0fc3a99455630d31303e5e32858c Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 18 Dec 2023 10:33:30 +0100 Subject: [PATCH 2/8] Minor fixes --- .../WithParticipationBetweenDatesFilter.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php index 52d788894..121abb8d0 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php @@ -46,14 +46,19 @@ final readonly class WithParticipationBetweenDatesFilter implements FilterInterf $qb ->andWhere( - $qb->expr()->exists( - 'SELECT 1 FROM '.AccompanyingPeriodParticipation::class." {$p}_acpp ". - "WHERE {$p}_acpp.person = person ". - "AND OVERLAPSI (acpp.startDate, acpp.endDate), (:{$p}_date_after), :{$p}_date_before)) = 'TRUE' ") + $qb->expr()->andX( + $qb->expr()->exists( + "SELECT 1 FROM ".AccompanyingPeriodParticipation::class." {$p}_acp ". + "WHERE {$p}_acp.person = person ". + "AND OVERLAPSI ({$p}_acp.openingDate, {$p}_acp.closingDate), (:{$p}_date_after), :{$p}_date_before)) = TRUE"), + $qb->expr()->exists( + 'SELECT 1 FROM '.AccompanyingPeriodParticipation::class." {$p}_acpp ". + "WHERE {$p}_acpp.person = person ". + "AND OVERLAPSI ({$p}_acpp.startDate, {$p}_acpp.endDate), (:{$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 @@ -75,7 +80,7 @@ final readonly class WithParticipationBetweenDatesFilter implements FilterInterf public function getFormDefaultData(): array { return [ - 'date_after' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), + 'date_after' => new RollingDate(RollingDate::T_YEAR_CURRENT_START), 'date_before' => new RollingDate(RollingDate::T_TODAY), ]; } From 044bab45ad3f8443679fc4ff29a61dccfb177f80 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 18 Dec 2023 15:29:59 +0100 Subject: [PATCH 3/8] Fix query : was missing parenthesis. --- .../WithParticipationBetweenDatesFilter.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php index 121abb8d0..ab921c895 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php @@ -20,6 +20,7 @@ use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Templating\TranslatableStringHelper; +use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; use Chill\PersonBundle\Export\Declarations; use Doctrine\DBAL\Types\Types; @@ -46,16 +47,14 @@ final readonly class WithParticipationBetweenDatesFilter implements FilterInterf $qb ->andWhere( - $qb->expr()->andX( + $qb->expr()->exists( - "SELECT 1 FROM ".AccompanyingPeriodParticipation::class." {$p}_acp ". + "SELECT 1 FROM ".AccompanyingPeriodParticipation::class." {$p}_acp JOIN {$p}_acp.accompanyingPeriod {$p}_acpp ". "WHERE {$p}_acp.person = person ". - "AND OVERLAPSI ({$p}_acp.openingDate, {$p}_acp.closingDate), (:{$p}_date_after), :{$p}_date_before)) = TRUE"), - $qb->expr()->exists( - 'SELECT 1 FROM '.AccompanyingPeriodParticipation::class." {$p}_acpp ". - "WHERE {$p}_acpp.person = person ". - "AND OVERLAPSI ({$p}_acpp.startDate, {$p}_acpp.endDate), (:{$p}_date_after), :{$p}_date_before)) = TRUE") - ) + "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); From 34cbd2605c0e8da0ab8bc887b0bc4d772c21f8c2 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 18 Dec 2023 15:32:04 +0100 Subject: [PATCH 4/8] Add a changie --- .changes/unreleased/Feature-20231218-153151.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changes/unreleased/Feature-20231218-153151.yaml 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" From c06c861e175819c0ad294f97ffb117856e888462 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 18 Dec 2023 15:38:20 +0100 Subject: [PATCH 5/8] Php cs fixes --- .../WithParticipationBetweenDatesFilter.php | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php index 121abb8d0..48c44463a 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php @@ -11,27 +11,19 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\PersonFilters; -use Chill\ActivityBundle\Entity\Activity; -use Chill\ActivityBundle\Entity\ActivityReason; -use Chill\ActivityBundle\Repository\ActivityReasonRepository; -use Chill\MainBundle\Export\ExportElementValidatedInterface; use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; -use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Entity\AccompanyingPeriodParticipation; use Chill\PersonBundle\Export\Declarations; use Doctrine\DBAL\Types\Types; use Doctrine\ORM\QueryBuilder; -use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\FormBuilderInterface; -use Symfony\Component\Validator\Context\ExecutionContextInterface; final readonly class WithParticipationBetweenDatesFilter implements FilterInterface { public function __construct( - private TranslatableStringHelper $translatableStringHelper, private RollingDateConverterInterface $rollingDateConverter, ) {} @@ -48,13 +40,15 @@ final readonly class WithParticipationBetweenDatesFilter implements FilterInterf ->andWhere( $qb->expr()->andX( $qb->expr()->exists( - "SELECT 1 FROM ".AccompanyingPeriodParticipation::class." {$p}_acp ". + 'SELECT 1 FROM '.AccompanyingPeriodParticipation::class." {$p}_acp ". "WHERE {$p}_acp.person = person ". - "AND OVERLAPSI ({$p}_acp.openingDate, {$p}_acp.closingDate), (:{$p}_date_after), :{$p}_date_before)) = TRUE"), + "AND OVERLAPSI ({$p}_acp.openingDate, {$p}_acp.closingDate), (:{$p}_date_after), :{$p}_date_before)) = TRUE" + ), $qb->expr()->exists( 'SELECT 1 FROM '.AccompanyingPeriodParticipation::class." {$p}_acpp ". "WHERE {$p}_acpp.person = person ". - "AND OVERLAPSI ({$p}_acpp.startDate, {$p}_acpp.endDate), (:{$p}_date_after), :{$p}_date_before)) = TRUE") + "AND OVERLAPSI ({$p}_acpp.startDate, {$p}_acpp.endDate), (:{$p}_date_after), :{$p}_date_before)) = TRUE" + ) ) ) ->setParameter("{$p}_date_after", $this->rollingDateConverter->convert($data['date_after']), Types::DATE_IMMUTABLE) @@ -97,5 +91,4 @@ final readonly class WithParticipationBetweenDatesFilter implements FilterInterf { return 'export.filter.person.with_participation_between_dates.title'; } - } From d2a31de1be42d1385b338c5b4ddf37699d404ccf Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 18 Dec 2023 17:04:16 +0100 Subject: [PATCH 6/8] Add a missing translation for the filter description --- .../PersonFilters/WithParticipationBetweenDatesFilter.php | 2 +- src/Bundle/ChillPersonBundle/translations/messages.fr.yml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php index 71b79ba54..289af5f07 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilter.php @@ -75,7 +75,7 @@ final readonly class WithParticipationBetweenDatesFilter implements FilterInterf public function describeAction($data, $format = 'string') { - return ['Filtered by participations during period: between %dateafter% and %datebefore%', [ + 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'), ]]; diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 578bdb8d0..783bc6be0 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -1146,6 +1146,7 @@ export: 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: From f103b228e42889c1dcda0c406287c65d16f4bac3 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 18 Dec 2023 17:04:42 +0100 Subject: [PATCH 7/8] Create test for the participationBetweenDatesFilter --- ...ithParticipationBetweenDatesFilterTest.php | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilterTest.php 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..bbca0e8bb --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilterTest.php @@ -0,0 +1,58 @@ +filter = self::$container->get(WithParticipationBetweenDatesFilter::class); + } + + /** + * @inheritDoc + */ + public function getFilter() + { + return $this->filter; + } + + /** + * @inheritDoc + */ + public function getFormData() + { + return [ + [ + 'date_after' => new RollingDate(RollingDate::T_YEAR_CURRENT_START), + 'date_before' => new RollingDate(RollingDate::T_TODAY), + ], + ]; + } + + /** + * @inheritDoc + */ + public function getQueryBuilders() + { + self::bootKernel(); + + $em = self::$container->get(EntityManagerInterface::class); + + return [ + $em->createQueryBuilder() + ->select('person.id') + ->from(Person::class, 'person'), + ]; + } +} From 469e379166f587be917dcb66bb95c9e2e2f832b7 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Mon, 18 Dec 2023 17:05:18 +0100 Subject: [PATCH 8/8] php cs fixes --- ...ithParticipationBetweenDatesFilterTest.php | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilterTest.php index bbca0e8bb..d9c58e743 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/PersonFilters/WithParticipationBetweenDatesFilterTest.php @@ -1,5 +1,14 @@ filter = self::$container->get(WithParticipationBetweenDatesFilter::class); } - /** - * @inheritDoc - */ public function getFilter() { return $this->filter; } - /** - * @inheritDoc - */ public function getFormData() { return [ @@ -40,9 +48,6 @@ final class WithParticipationBetweenDatesFilterTest extends AbstractFilterTest ]; } - /** - * @inheritDoc - */ public function getQueryBuilders() { self::bootKernel();