From 4c91bf5084c0a7d40972934f03f3e6023e3cff71 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Tue, 16 Aug 2022 15:07:03 +0200 Subject: [PATCH] household position aggregator for person --- .../HouseholdPositionAggregator.php | 125 ++++++++++++++++++ .../config/services/exports_person.yaml | 7 + .../translations/messages.fr.yml | 5 +- 3 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/HouseholdPositionAggregator.php diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/HouseholdPositionAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/HouseholdPositionAggregator.php new file mode 100644 index 000000000..ec4a270ac --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/HouseholdPositionAggregator.php @@ -0,0 +1,125 @@ +translator = $translator; + $this->positionRepository = $positionRepository; + $this->translatableStringHelper = $translatableStringHelper; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->resetDQLPart('from'); + $qb->from('ChillPersonBundle:Household\HouseholdMember', 'hm'); + + $qb->join('hm.person', 'person'); + $qb->join('person.center', 'center'); + + $qb->andWhere($qb->expr()->andX( + $qb->expr()->lte('hm.startDate', ':date'), + $qb->expr()->orX( + $qb->expr()->isNull('hm.endDate'), + $qb->expr()->gte('hm.endDate', ':date') + ) + )); + + $qb->setParameter('date', $data['date_position']); + + $qb->addSelect('IDENTITY(hm.position) AS household_position_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('household_position_aggregator'); + } else { + $qb->groupBy('household_position_aggregator'); + } + + } + + public function applyOn() + { + return 'person'; + } + + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('date_position', ChillDateType::class, [ + 'label' => 'Household position in relation to this date', + 'data' => new DateTime(), + ]); + } + + public function getLabels($key, array $values, $data) + { + return function ($value) { + if ('_header' === $value) { + return 'Household position'; + } + + if (null === $value) { + return $this->translator->trans('without data'); + } + + $p = $this->positionRepository->find($value); + + return $this->translatableStringHelper->localize($p->getLabel()); + }; + } + + public function getQueryKeys($data) + { + return [ + 'household_position_aggregator', + ]; + } + + public function getTitle() + { + return 'Aggregate by household position'; + } + + public function validateForm($data, ExecutionContextInterface $context) + { + if (null === $data['date_position']) { + $context->buildViolation('The date should not be empty') + ->addViolation(); + } + } +} diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml index 288cd1f15..c17dcaaf1 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_person.yaml @@ -111,3 +111,10 @@ services: autoconfigure: true tags: - { name: chill.export_aggregator, alias: person_marital_status_aggregator } + + chill.person.export.aggregator_household_position: + class: Chill\PersonBundle\Export\Aggregator\PersonAggregators\HouseholdPositionAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: person_household_position_aggregator } diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 34921ec4b..df43b5922 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -388,7 +388,7 @@ 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 +"Filtered by person's age: between %min_age% and %max_age%": "Filtré par âge de la personne entre %min_age% et %max_age%" 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. @@ -570,6 +570,9 @@ Group by country: Grouper par pays Group people by gender: Grouper les personnes par genre Group people by their professional situation: Grouper les personnes par situation professionelle Group people by marital status: Grouper les personnes par état matrimonial +Aggregate by household position: Grouper par position dans le ménage +Household position in relation to this date: Position dans le ménage par rapport à cette date +Household position: Position dans le ménage Aggregate by age: Grouper par âge Calculate age in relation to this date: Calculer l'âge par rapport à cette date