From 5880858191336a0c30e16b3ed743db3e61e59c87 Mon Sep 17 00:00:00 2001 From: LenaertsJ Date: Fri, 8 Mar 2024 10:37:43 +0000 Subject: [PATCH] =?UTF-8?q?Resolve=20"Nouveau=20filtre:=20Filtrer=20les=20?= =?UTF-8?q?actions=20ayant=20re=C3=A7u=20une=20nouvelle=20=C3=A9valuation?= =?UTF-8?q?=20cr=C3=A9=C3=A9e=20entre=20deux=20dates"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unreleased/Feature-20240227-133135.yaml | 6 ++ ...odWorkWithEvaluationBetweenDatesFilter.php | 85 +++++++++++++++++++ .../WithEvaluationBetweenDatesFilterTest.php | 63 ++++++++++++++ .../services/exports_social_actions.yaml | 4 + .../translations/messages.fr.yml | 5 ++ 5 files changed, 163 insertions(+) create mode 100644 .changes/unreleased/Feature-20240227-133135.yaml create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/AccompanyingPeriodWorkWithEvaluationBetweenDatesFilter.php create mode 100644 src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/WithEvaluationBetweenDatesFilterTest.php diff --git a/.changes/unreleased/Feature-20240227-133135.yaml b/.changes/unreleased/Feature-20240227-133135.yaml new file mode 100644 index 000000000..9935f9916 --- /dev/null +++ b/.changes/unreleased/Feature-20240227-133135.yaml @@ -0,0 +1,6 @@ +kind: Feature +body: New export filter for social actions with an evaluation created between two + dates +time: 2024-02-27T13:31:35.828320711+01:00 +custom: + Issue: "237" diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/AccompanyingPeriodWorkWithEvaluationBetweenDatesFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/AccompanyingPeriodWorkWithEvaluationBetweenDatesFilter.php new file mode 100644 index 000000000..439cb47ca --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/AccompanyingPeriodWorkWithEvaluationBetweenDatesFilter.php @@ -0,0 +1,85 @@ +add('start_date', PickRollingDateType::class, [ + 'label' => 'export.filter.work.evaluation_between_dates.start_date', + ]) + ->add('end_date', PickRollingDateType::class, [ + 'label' => 'export.filter.work.evaluation_between_dates.end_date', + ]); + } + + public function getFormDefaultData(): array + { + return ['start_date' => new RollingDate(RollingDate::T_YEAR_CURRENT_START), 'end_date' => new RollingDate(RollingDate::T_TODAY)]; + } + + public function getTitle(): string + { + return 'export.filter.work.evaluation_between_dates.title'; + } + + public function describeAction($data, $format = 'string'): array + { + return [ + 'export.filter.work.evaluation_between_dates.description', + [ + '%startDate%' => null !== $data['start_date'] ? $this->rollingDateConverter->convert($data['start_date'])->format('d-m-Y') : '', + '%endDate%' => null !== $data['end_date'] ? $this->rollingDateConverter->convert($data['end_date'])->format('d-m-Y') : '', + ], + ]; + } + + public function addRole(): ?string + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data): void + { + $s = 'workeval_between_filter_start'; + $e = 'workeval_between_filter_end'; + + $qb->andWhere( + $qb->expr()->exists( + 'SELECT 1 FROM '.AccompanyingPeriodWorkEvaluation::class." workeval_between_filter_workeval WHERE workeval_between_filter_workeval.createdAt BETWEEN :{$s} AND :{$e} AND IDENTITY(workeval_between_filter_workeval.accompanyingPeriodWork) = acpw.id" + ) + ) + ->setParameter($s, $this->rollingDateConverter->convert($data['start_date'])) + ->setParameter($e, $this->rollingDateConverter->convert($data['end_date'])); + } + + public function applyOn(): string + { + return Declarations::SOCIAL_WORK_ACTION_TYPE; + } +} diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/WithEvaluationBetweenDatesFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/WithEvaluationBetweenDatesFilterTest.php new file mode 100644 index 000000000..680eb4cc9 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/SocialWorkFilters/WithEvaluationBetweenDatesFilterTest.php @@ -0,0 +1,63 @@ +filter = self::$container->get(AccompanyingPeriodWorkWithEvaluationBetweenDatesFilter::class); + } + + public function getFilter() + { + return $this->filter; + } + + public function getFormData() + { + return [ + [ + 'start_date' => new RollingDate(RollingDate::T_MONTH_CURRENT_START), + 'end_date' => new RollingDate(RollingDate::T_TODAY), + ], + ]; + } + + public function getQueryBuilders() + { + self::bootKernel(); + + $em = self::$container->get(EntityManagerInterface::class); + + return [ + $em->createQueryBuilder() + ->select('acpw.id') + ->from(AccompanyingPeriodWork::class, 'acpw'), + ]; + } +} diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml index 1987568e3..9e199679f 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml @@ -79,6 +79,10 @@ services: tags: - { name: chill.export_filter, alias: social_work_actions_creator_scope_filter } + Chill\PersonBundle\Export\Filter\SocialWorkFilters\AccompanyingPeriodWorkWithEvaluationBetweenDatesFilter: + tags: + - { name: chill.export_filter, alias: social_work_actions_evaluation_btw_dates_filter } + ## AGGREGATORS chill.person.export.aggregator_action_type: diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 50c6a87d5..dc1d89b55 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -1291,6 +1291,11 @@ export: by_creator_scope: title: Filtrer les actions par service du créateur "Filtered by creator scope: only %scopes%": "Filtré par service du créateur: uniquement %scopes%" + evaluation_between_dates: + title: Filtrer les actions associées à une évaluation créée entre deux dates + description: Uniquement les actions associées à une évaluation créée entre le %startDate% et le %endDate% + start_date: Date de début + end_date: Date de fin list: person_with_acp: