diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php new file mode 100644 index 000000000..c629fe0bf --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php @@ -0,0 +1,108 @@ +translator = $translator; + } + + /** + * @inheritDoc + */ + public function getLabels($key, array $values, $data) + { + return function ($value): string { + + if ($value === '_header') { + return 'Number of children'; + } + + return $this->translator->trans( + 'household_composition.numberOfChildren children in household', [ + 'numberOfChildren' => $value + ]); + }; + } + + /** + * @inheritDoc + */ + public function getQueryKeys($data): array + { + return ['childrennumber_aggregator']; + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('on_date', ChillDateType::class, [ + 'data' => new \DateTime('now'), + ]); + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Group by number of children'; + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->addSelect('composition.numberOfChildren AS childrennumber_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('childrennumber_aggregator'); + } else { + $qb->groupBy('childrennumber_aggregator'); + } + + // add date in where clause + $where = $qb->getDQLPart('where'); + + $clause = $qb->expr()->andX( + $qb->expr()->lte('composition.startDate', ':ondate'), + $qb->expr()->orX( + $qb->expr()->gt('composition.endDate', ':ondate'), + $qb->expr()->isNull('composition.endDate') + ) + ); + } + + /** + * @inheritDoc + */ + public function applyOn(): string + { + return Declarations::HOUSEHOLD_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_household.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_household.yaml index b59537717..0b8c5f1ce 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_household.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_household.yaml @@ -23,3 +23,10 @@ services: autoconfigure: true tags: - { name: chill.export_aggregator, alias: household_composition_aggregator } + + chill.person.export.aggregator_household_childrennumber: + class: Chill\PersonBundle\Export\Aggregator\HouseholdAggregators\ChildrenNumberAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: household_childrennumber_aggregator } diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index f46bb1750..3f895e0c4 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -535,6 +535,8 @@ Accepted composition: Composition familiale "Filtered by composition: only %compositions% on %ondate%": "Filtré par composition familiale: uniquement %compositions%, en date du %ondate%" Group by composition: Grouper par composition familiale +Group by number of children: Grouper par nombre d'enfants + ## aggregators Group people by nationality: Grouper les personnes par nationalités Group by level: Grouper par niveau