From cf7cf664a9a7f8347235e4261b67f5b1c6288a0a Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 3 Aug 2022 14:35:55 +0200 Subject: [PATCH] person filters added --- .../Export/Filter/AgeFilter.php | 12 +- .../Export/Filter/BirthdateFilter.php | 17 +-- .../Export/Filter/DeadOrAliveFilter.php | 113 ++++++++++++++++++ .../Export/Filter/DeathdateFilter.php | 109 +++++++++++++++++ .../Export/Filter/EntrustedChildFilter.php | 65 ++++++++++ .../Export/Filter/FamilySituationFilter.php | 55 +++++++++ .../Export/Filter/NomadicFilter.php | 64 ++++++++++ .../Filter/ResidentialAddressAtUserFilter.php | 67 +++++++++++ .../config/services/exports_person.yaml | 31 +++++ .../translations/messages.fr.yml | 35 +++++- 10 files changed, 548 insertions(+), 20 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/DeadOrAliveFilter.php create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/DeathdateFilter.php create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/EntrustedChildFilter.php create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/FamilySituationFilter.php create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/NomadicFilter.php create mode 100644 src/Bundle/ChillPersonBundle/Export/Filter/ResidentialAddressAtUserFilter.php diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AgeFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AgeFilter.php index ef2bc2fa0..3a6e6861a 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AgeFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AgeFilter.php @@ -13,11 +13,14 @@ namespace Chill\PersonBundle\Export\Filter; use Chill\MainBundle\Export\ExportElementValidatedInterface; use Chill\MainBundle\Export\FilterInterface; +use Chill\MainBundle\Form\Type\ChillDateType; use Chill\PersonBundle\Export\Declarations; use DateTime; use Doctrine\ORM\Query\Expr; +use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\Extension\Core\Type\DateType; use Symfony\Component\Form\Extension\Core\Type\IntegerType; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Validator\Context\ExecutionContextInterface; class AgeFilter implements ExportElementValidatedInterface, FilterInterface @@ -27,7 +30,7 @@ class AgeFilter implements ExportElementValidatedInterface, FilterInterface return null; } - public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data) + public function alterQuery(QueryBuilder $qb, $data) { $where = $qb->getDQLPart('where'); @@ -61,7 +64,7 @@ class AgeFilter implements ExportElementValidatedInterface, FilterInterface return Declarations::PERSON_TYPE; } - public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) + public function buildForm(FormBuilderInterface $builder) { $builder->add('min_age', IntegerType::class, [ 'label' => 'Minimum age', @@ -71,12 +74,9 @@ class AgeFilter implements ExportElementValidatedInterface, FilterInterface 'label' => 'Maximum age', ]); - $builder->add('date_calc', DateType::class, [ + $builder->add('date_calc', ChillDateType::class, [ 'label' => 'Calculate age in relation to this date', 'data' => new DateTime('now'), - 'attr' => ['class' => 'datepicker'], - 'widget' => 'single_text', - 'format' => 'dd-MM-yyyy', ]); } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/BirthdateFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/BirthdateFilter.php index 36457e0f8..d7235a5c2 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/BirthdateFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/BirthdateFilter.php @@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Export\Filter; use Chill\MainBundle\Export\ExportElementValidatedInterface; use Chill\MainBundle\Export\FilterInterface; +use Chill\MainBundle\Form\Type\ChillDateType; use DateTime; use Doctrine\ORM\Query\Expr; use Symfony\Component\Form\Extension\Core\Type\DateType; @@ -52,26 +53,20 @@ class BirthdateFilter implements ExportElementValidatedInterface, FilterInterfac public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) { - $builder->add('date_from', DateType::class, [ + $builder->add('date_from', ChillDateType::class, [ 'label' => 'Born after this date', - 'data' => new DateTime(), - 'attr' => ['class' => 'datepicker'], - 'widget' => 'single_text', - 'format' => 'dd-MM-yyyy', + 'data' => new DateTime() ]); - $builder->add('date_to', DateType::class, [ + $builder->add('date_to', ChillDateType::class, [ 'label' => 'Born before this date', - 'data' => new DateTime(), - 'attr' => ['class' => 'datepicker'], - 'widget' => 'single_text', - 'format' => 'dd-MM-yyyy', + 'data' => new DateTime() ]); } public function describeAction($data, $format = 'string') { - return ['Filtered by person\'s birtdate: ' + return ['Filtered by person\'s birthdate: ' . 'between %date_from% and %date_to%', [ '%date_from%' => $data['date_from']->format('d-m-Y'), '%date_to%' => $data['date_to']->format('d-m-Y'), diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/DeadOrAliveFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/DeadOrAliveFilter.php new file mode 100644 index 000000000..6f65038bd --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/DeadOrAliveFilter.php @@ -0,0 +1,113 @@ +getDQLPart('where'); + + $personState = $data['person_state']; + $calc = $data['date_calc']; + + if ($personState == 'alive') { + $clause = $qb->expr()->orX( + $qb->expr()->andX( + $qb->expr()->isNull('person.deathdate'), + $qb->expr()->lte( + 'person.birthdate', + ':date_calc' + ) + ), + $qb->expr()->andX( + $qb->expr()->isNotNull('person.deathdate'), + $qb->expr()->gt( + 'person.deathdate', + ':date_calc' + ), + $qb->expr()->lte( + 'person.birthdate', + ':date_calc' + ) + ) + ); + } else { + $clause = $qb->expr()->andX( + $qb->expr()->isNotNull('person.deathdate'), + $qb->expr()->lte( + 'person.deathdate', + ':date_calc' + ) + ); + } + + if ($where instanceof Expr\Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('date_calc', $calc); + } + + public function applyOn() + { + return Declarations::PERSON_TYPE; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('person_state', ChoiceType::class, [ + 'choices' => [ + 'Alive' => 'alive', + 'Deceased' => 'deceased', + ], + 'multiple' => false, + 'expanded' => true, + ]); + + $builder->add('date_calc', ChillDateType::class, [ + 'label' => 'Filter in relation to this date', + 'data' => new DateTime('now'), + ]); + } + + public function describeAction($data, $format = 'string') + { + return ['Filtered by a state of %deadOrAlive%: ' + . 'at this date %date_calc%', [ + '%date_calc%' => $data['date_calc']->format('d-m-Y'), + '%deadOrAlive%' => $data['person_state'], + ], ]; + } + + public function getTitle() + { + return 'Filtered by person\'s that are alive or have deceased at a certain date'; + } +} diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/DeathdateFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/DeathdateFilter.php new file mode 100644 index 000000000..2197a93c6 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/DeathdateFilter.php @@ -0,0 +1,109 @@ +getDQLPart('where'); + $clause = $qb->expr()->between( + 'person.deathdate', + ':date_from', + ':date_to' + ); + + if ($where instanceof Expr\Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('date_from', $data['date_from']); + $qb->setParameter('date_to', $data['date_to']); + } + + public function applyOn() + { + return Declarations::PERSON_TYPE; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('date_from', ChillDateType::class, [ + 'label' => 'Death after this date', + 'data' => new DateTime(), + ]); + + $builder->add('date_to', ChillDateType::class, [ + 'label' => 'Deathdate before', + 'data' => new DateTime(), + ]); + } + + public function describeAction($data, $format = 'string') + { + return ['Filtered by person\'s deathdate: ' + . 'between %date_from% and %date_to%', [ + '%date_from%' => $data['date_from']->format('d-m-Y'), + '%date_to%' => $data['date_to']->format('d-m-Y'), + ], ]; + } + + public function getTitle() + { + return 'Filter by person\'s deathdate'; + } + + public function validateForm($data, ExecutionContextInterface $context) + { + $date_from = $data['date_from']; + $date_to = $data['date_to']; + + if (null === $date_from) { + $context->buildViolation('The "date from" should not be empty') + //->atPath('date_from') + ->addViolation(); + } + + if (null === $date_to) { + $context->buildViolation('The "date to" should not be empty') + //->atPath('date_to') + ->addViolation(); + } + + if ( + (null !== $date_from && null !== $date_to) + && $date_from >= $date_to + ) { + $context->buildViolation('The date "date to" should be after the ' + . 'date given in "date from" field') + ->addViolation(); + } + } +} diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/EntrustedChildFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/EntrustedChildFilter.php new file mode 100644 index 000000000..9d2c81b3c --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/EntrustedChildFilter.php @@ -0,0 +1,65 @@ +resetDQLPart('from'); + $qb->from('App:VendeePersonMineur', 'vpm'); + + $qb->join('vpm.person', 'person'); + $qb->join('person.center', 'center'); + + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->eq('vpm.enfantConfie', 'true'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + } + + public function applyOn() + { + return Declarations::PERSON_TYPE; + } + + public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) + { + // No form needed + } + + public function describeAction($data, $format = 'string') + { + return ['Filtered by entrusted child status']; + } + + public function getTitle() + { + return 'Filter by entrusted child status'; + } +} diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/FamilySituationFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/FamilySituationFilter.php new file mode 100644 index 000000000..30d67aff5 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/FamilySituationFilter.php @@ -0,0 +1,55 @@ +add('date_calc', DateType::class, [ + 'label' => 'Family composition(s) at this time', + 'data' => new DateTime(), + ]); + } + + public function describeAction($data, $format = 'string') + { + return ['Filtered by person\'s family situation']; + } + + public function getTitle() + { + return 'Filter by person\'s family situation'; + } +} diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/NomadicFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/NomadicFilter.php new file mode 100644 index 000000000..b4ef13c36 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/NomadicFilter.php @@ -0,0 +1,64 @@ +resetDQLPart('from'); + $qb->from('App:VendeePerson', 'vp'); + + $qb->join('vp.person', 'person'); + $qb->join('person.center', 'center'); + + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->eq('vp.gensDuVoyage', 'true'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + } + + public function applyOn() + { + return Declarations::PERSON_TYPE; + } + + public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) + { + // No form needed + } + + public function describeAction($data, $format = 'string') + { + return ['Filtered by nomadic status']; + } + + public function getTitle() + { + return 'Filter by nomadic status'; + } +} diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/ResidentialAddressAtUserFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/ResidentialAddressAtUserFilter.php new file mode 100644 index 000000000..14369c7f0 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/ResidentialAddressAtUserFilter.php @@ -0,0 +1,67 @@ +resetDQLPart('from'); + $qb->from('ChillPersonBundle:Person:ResidentialAddress', 'ra'); + + $qb->join('ra.person', 'person'); + $qb->join('person.center', 'center'); + + $where = $qb->getDQLPart('where'); + $clause = $qb->expr()->isNotNull('ra.hostPerson'); + + if ($where instanceof Expr\Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + + dump($qb->getQuery()); + } + + public function applyOn() + { + return Declarations::PERSON_TYPE; + } + + public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) + { + // No form needed unless validity date should be added ( not specified in doc as a parameter ). + } + + public function describeAction($data, $format = 'string') + { + return ['Filtered by person\'s who have a residential address located at another user']; + } + + public function getTitle() + { + return 'Filtered by person\'s who have a residential address located at another user'; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml index e45930ddb..47fb89770 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml @@ -43,6 +43,16 @@ services: class: Chill\PersonBundle\Export\Filter\BirthdateFilter tags: - { name: chill.export_filter, alias: person_birthdate_filter } + + chill.person.export.filter_deathdate: + class: Chill\PersonBundle\Export\Filter\DeathdateFilter + tags: + - { name: chill.export_filter, alias: person_deathdate_filter } + + chill.person.export.filter_dead_or_alive: + class: Chill\PersonBundle\Export\Filter\DeadOrAliveFilter + tags: + - { name: chill.export_filter, alias: person_dead_or_alive_filter } chill.person.export.filter_nationality: class: Chill\PersonBundle\Export\Filter\NationalityFilter @@ -50,6 +60,27 @@ services: autoconfigure: true tags: - { name: chill.export_filter, alias: person_nationality_filter } + + chill.person.export.filter_residential_address_at_user: + class: Chill\PersonBundle\Export\Filter\ResidentialAddressAtUserFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: person_residential_address_at_user_filter } + + chill.person.export.filter_entrusted_child: + class: Chill\PersonBundle\Export\Filter\EntrustedChildFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: person_entrusted_child_filter } + + chill.person.export.filter_nomadic: + class: Chill\PersonBundle\Export\Filter\NomadicFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: person_nomadic_filter } # AGGREGATORS chill.person.export.aggregator_nationality: diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index f613b09da..6e8044d74 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -329,8 +329,8 @@ Accompanyied people: Personnes accompagnées ## exports Exports of persons: Exports des personnes -Count peoples by various parameters.: Compte le nombre de personnes en fonction de différents filtres. -Count peoples: Nombre de personnes +Count people by various parameters.: Compte le nombre de personnes en fonction de différents filtres. +Count people: Nombre de personnes List peoples: Liste des personnes Create a list of people according to various filters.: Crée une liste des personnes selon différents filtres. Fields to include in export: Champs à inclure dans l'export @@ -364,7 +364,36 @@ Born after this date: Nés après cette date Born before this date: Nés avant cette date This field should not be empty: Ce champ ne peut pas être vide This date should be after the date given in "born after" field: Cette date doit être après la date donnée du le champ "nés après le" -"Filtered by person's birtdate: between %date_from% and %date_to%": "Filtré par date de naissance de la personne: uniquement nés entre le %date_from% et %date_to%" +"Filtered by person's birthdate: between %date_from% and %date_to%": "Filtré par date de naissance de la personne: uniquement nés entre le %date_from% et %date_to%" + +Filter by person's deathdate: Filtrer par date de décès de la personne +"Filtered by person's deathdate: between %date_from% and %date_to%": "Filtré par date de naissance de la personne: uniquement nés entre le %date_from% et %date_to%" +Death after this date: Décédé après cette date +Deathdate before: Décédé avant cette date + +Alive: Vivant +Deceased: Décédé +Filter in relation to this date: Filtrer par rapport à cette date +"Filtered by a state of %deadOrAlive% at this date %date_calc%": Filtré par personnes qui sont %deadOrAlive% à cette date %date_calc% + +Filter by person's age: Filtrer par âge de la personne +Filtered by person's age: Filtré par âge de la personne +Minimum age: Âge minimum +Maximum age: Âge maximum +The minimum age should be less than the maximum age.: L'âge minimum doit être plus bas que l'âge maximum. + +Family composition: Composition familiale +Family composition at this time: Composition familiale à cette date. + +Filtered by entrusted child status: Uniquement les personnes qui sont "enfant confié" +Filter by entrusted child status: Uniquement les personnes qui sont "enfant confié" + +Filtered by nomadic status: Uniquement les personnes qui sont "gens de voyage" +Filter by nomadic status: Uniquement les personnes qui sont "gens de voyage" + +Filtered by person's who have a residential address located at another user: Uniquement les usagers qui ont une addresse de résidence chez un autre usager + +Filtered by person's that are alive or have deceased at a certain date: Filtrer par usagers qui sont décédé ou vivant à une certaine date "Filter by accompanying period: active period": "Filtrer par période d'accompagnement: en file active" Having an accompanying period opened after this date: Ayant une période d'accompagnement ouverte après cette date