diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php new file mode 100644 index 000000000..5718f990d --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php @@ -0,0 +1,104 @@ +typeRepository = $typeRepository; + $this->translatableStringHelper = $translatableStringHelper; + } + + /** + * @inheritDoc + */ + public function getLabels($key, array $values, $data) + { + return function ($value): string { + if ($value === '_header') { + return 'Composition'; + } + + $c = $this->typeRepository->find($value); + + return $this->translatableStringHelper->localize( + $c->getLabel() + ); + }; + } + + /** + * @inheritDoc + */ + public function getQueryKeys($data): array + { + return ['composition_aggregator']; + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + // TODO: Implement buildForm() method. + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Group by composition'; + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + $qb + ->join('household.compositions', 'composition') + //->join('composition.householdCompositionType', 'type') + ; + + $qb->addSelect('IDENTITY(composition.householdCompositionType) AS composition_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('composition_aggregator'); + } else { + $qb->groupBy('composition_aggregator'); + } + } + + /** + * @inheritDoc + */ + public function applyOn(): string + { + return Declarations::HOUSEHOLD_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php b/src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php index 0fa708bf0..5bc333e2a 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php @@ -106,6 +106,7 @@ class CountHousehold implements ExportInterface, GroupedExportInterface ->join('acp.participations', 'acppart') ->join('acppart.person', 'person') ->join('person.householdParticipations', 'householdmember') + ->join('householdmember.household', 'household') ; $qb->select('COUNT(DISTINCT householdmember.household) AS export_result'); diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/HouseholdFilters/CompositionFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/HouseholdFilters/CompositionFilter.php new file mode 100644 index 000000000..132b878fd --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Filter/HouseholdFilters/CompositionFilter.php @@ -0,0 +1,106 @@ +translatableStringHelper = $translatableStringHelper; + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + $builder->add('accepted_composition', EntityType::class, [ + 'class' => HouseholdCompositionType::class, + 'choice_label' => function (HouseholdCompositionType $type) { + return $this->translatableStringHelper->localize( + $type->getLabel() + ); + }, + 'multiple' => true, + 'expanded' => true, + ]); + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Filter by composition'; + } + + /** + * @inheritDoc + */ + public function describeAction($data, $format = 'string'): array + { + $compositions = []; + + foreach ($data['accepted_composition'] as $c) { + $compositions[] = $this->translatableStringHelper->localize( + $c->getLabel() + ); + } + + return ['Filtered by composition: only %compositions%', [ + '%compositions%' => implode(", ou ", $compositions) + ]]; + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + $qb + ->join('household.compositions', 'composition') + //->join('composition.householdCompositionType', 'type') + ; + + $where = $qb->getDQLPart('where'); + + $clause = $qb->expr()->in('composition.householdCompositionType', ':compositions'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->add('where', $where); + $qb->setParameter('compositions', $data['accepted_composition']); + } + + /** + * @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 45d70f6e4..b59537717 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_household.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_household.yaml @@ -9,5 +9,17 @@ services: - { name: chill.export, alias: count_household } ## Filters + chill.person.export.filter_household_composition: + class: Chill\PersonBundle\Export\Filter\HouseholdFilters\CompositionFilter + autowire: true + autoconfigure: true + tags: + - { name: chill.export_filter, alias: household_composition_filter } ## Aggregators + chill.person.export.aggregator_household_composition: + class: Chill\PersonBundle\Export\Aggregator\HouseholdAggregators\CompositionAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: household_composition_aggregator } diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 2f783c1e7..a19150477 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -508,7 +508,6 @@ On date: Actifs à cette date Filtered by active at least one day between dates: Filtrer les parcours actifs au moins un jour dans la période "Filtered by actives courses: at least one day between %datefrom% and %dateto%": "Filtrer les parcours actifs: au moins un jour entre le %datefrom% et le %dateto%" - Filtered by referrers: Filtrer par référent Accepted referrers: Référents "Filtered by referrer: only %referrers%": "Filtré par référent: uniquement %referrers%" @@ -531,6 +530,11 @@ is specified: La date d'échéance est spécifiée is not specified: La date d'échéance n'est pas spécifiée "Filtered by maxdate: only %choice%": "Filtré par date d'échéance: uniquement si %choice%" +Filter by composition: Filtrer par composition familiale +Accepted composition: Composition familiale +"Filtered by composition: only %compositions%": "Filtré par composition familiale: uniquement %compositions%" +Group by composition: Grouper par composition familiale + ## aggregators Group people by nationality: Grouper les personnes par nationalités Group by level: Grouper par niveau