diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ClosingMotiveAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ClosingMotiveAggregator.php new file mode 100644 index 000000000..198cacea7 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ClosingMotiveAggregator.php @@ -0,0 +1,103 @@ +motiveRepository = $em->getRepository(ClosingMotive::class); + $this->translatableStringHelper = $translatableStringHelper; + } + + /** + * @inheritDoc + */ + public function getLabels($key, array $values, $data) + { + return function ($value): string { + if ('_header' === $value) { + return 'Closing motive'; + } + + $cm = $this->motiveRepository->find($value); + + return $this->translatableStringHelper->localize( + $cm->getName() + ); + }; + } + + /** + * @inheritDoc + */ + public function getQueryKeys($data) + { + return ['closingmotive_aggregator']; + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Group by closing motive'; + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->join('acp.closingMotive', 'cm'); + + $qb->addSelect('IDENTITY(acp.closingMotive) AS closingmotive_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('closingmotive_aggregator'); + } else { + $qb->groupBy('closingmotive_aggregator'); + } + } + + /** + * @inheritDoc + */ + public function applyOn(): string + { + return Declarations::ACP_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml index 726c84599..1aae1d1fa 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml @@ -197,4 +197,11 @@ services: autowire: true autoconfigure: true tags: - - { name: chill.export_aggregator, alias: accompanyingcourse_origin_aggregator } \ No newline at end of file + - { name: chill.export_aggregator, alias: accompanyingcourse_origin_aggregator } + + chill.person.export.aggregator_closingmotive: + class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\ClosingMotiveAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: accompanyingcourse_closingmotive_aggregator } diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index be32253e0..767061f55 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -453,6 +453,7 @@ Group by origin: Grouper par origine du parcours Filter by closing motive: Filtrer par motif de fermeture Accepted closingmotives: Motifs de clôture "Filtered by closingmotive: only %closingmotives%": "Filtré par motif de clôture: uniquement %closingmotives%" +Group by closing motive: Grouper par motif de fermeture Filter by administrative location: Filtrer par localisation administrative Accepted locations: Localisations administratives