From 2767075be76deb929395bba4575b3a50245bed00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 2 Nov 2022 12:55:10 +0100 Subject: [PATCH] Feature: [export] Finalize HasTemporaryLocation filter on accompanying course --- .../HasTemporaryLocationFilter.php | 64 +++++++++++++++++-- .../translations/messages.fr.yml | 4 ++ 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasTemporaryLocationFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasTemporaryLocationFilter.php index b674f1881..2ae1ad2a0 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasTemporaryLocationFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasTemporaryLocationFilter.php @@ -12,8 +12,12 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Export\FilterInterface; +use Chill\MainBundle\Form\Type\ChillDateType; use Chill\PersonBundle\Export\Declarations; +use DateTimeImmutable; use Doctrine\ORM\QueryBuilder; +use LogicException; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; class HasTemporaryLocationFilter implements FilterInterface @@ -26,10 +30,25 @@ class HasTemporaryLocationFilter implements FilterInterface public function alterQuery(QueryBuilder $qb, $data) { $qb - ->andWhere( - $qb->expr()->in('', ':') - ) - ->setParameter('', $data[]); + ->join('acp.locationHistories', 'acp_having_temporarily_location') + ->andWhere('acp_having_temporarily_location.startDate <= :acp_having_temporarily_location_date + AND (acp_having_temporarily_location.endDate IS NULL OR acp_having_temporarily_location.endDate > :acp_having_temporarily_location_date)') + ->setParameter('acp_having_temporarily_location_date', $data['calc_date']); + + switch ($data['having_temporarily']) { + case true: + $qb->andWhere('acp_having_temporarily_location.addressLocation IS NOT NULL'); + + break; + + case false: + $qb->andWhere('acp_having_temporarily_location.personLocation IS NOT NULL'); + + break; + + default: + throw new LogicException('value not supported'); + } } public function applyOn(): string @@ -39,13 +58,44 @@ class HasTemporaryLocationFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { - //$builder->add(); + $builder + ->add('having_temporarily', ChoiceType::class, [ + 'choices' => [ + 'export.filter.course.having_temporarily.Having a temporarily location' => true, + 'export.filter.course.having_temporarily.Having a person\'s location' => false, + ], + 'choice_label' => static function ($choice) { + switch ($choice) { + case true: + return 'export.filter.course.having_temporarily.Having a temporarily location'; + + case false: + return 'export.filter.course.having_temporarily.Having a person\'s location'; + + default: + throw new LogicException('this choice is not supported'); + } + }, + ]) + ->add('calc_date', ChillDateType::class, [ + 'label' => 'export.filter.course.having_temporarily.Calculation date', + 'input' => 'datetime_immutable', + 'data' => new DateTimeImmutable(), + ]); } public function describeAction($data, $format = 'string'): array { - return ['', [ - ]]; + switch ($data['having_temporarily']) { + case true: + return ['export.filter.course.having_temporarily.Having a temporarily location', []]; + + case false: + return ['export.filter.course.having_temporarily.Having a person\'s location', []]; + + default: + throw new LogicException('value not supported'); + } } public function getTitle(): string diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 134a97414..406cf7828 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -1021,6 +1021,10 @@ export: Computation date for referrer: Date à laquelle le référent était actif by_referrer: Computation date for referrer: Date à laquelle le référent était actif + having_temporarily: + Having a temporarily location: Ayant une localisation temporaire + Having a person's location: Ayant une localisation auprès d'un usager + Calculation date: Date de la localisation list: person_with_acp: List peoples having an accompanying period: Liste des personnes ayant un parcours d'accompagnement