From ace2cb6151fc1360bffcbdb5e5d02c73ab1406a0 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 8 Aug 2022 16:59:03 +0200 Subject: [PATCH] exports: add new AdministrativeLocation aggregator --- .../AdministrativeLocationAggregator.php | 100 ++++++++++++++++++ .../services/exports_accompanying_course.yaml | 7 ++ .../translations/messages.fr.yml | 2 + 3 files changed, 109 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/AdministrativeLocationAggregator.php diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/AdministrativeLocationAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/AdministrativeLocationAggregator.php new file mode 100644 index 000000000..8d421f369 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/AdministrativeLocationAggregator.php @@ -0,0 +1,100 @@ +locationRepository = $locationRepository; + $this->translatableStringHelper = $translatableStringHelper; + } + + /** + * @inheritDoc + */ + public function getLabels($key, array $values, $data) + { + return function ($value): string { + if ('_header' === $value) { + return 'Administrative location'; + } + + $l = $this->locationRepository->find($value); + + return $l->getName() .' ('. $this->translatableStringHelper->localize($l->getLocationType()->getTitle()) . ')'; + }; + } + + /** + * @inheritDoc + */ + public function getQueryKeys($data): array + { + return ['location_aggregator']; + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + /** + * @inheritDoc + */ + public function getTitle() + { + return 'Group by administrative location'; + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->join('acp.administrativeLocation', 'al'); + + $qb->addSelect('IDENTITY(acp.administrativeLocation) AS location_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('location_aggregator'); + } else { + $qb->groupBy('location_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 1aae1d1fa..45c818ffb 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml @@ -205,3 +205,10 @@ services: autoconfigure: true tags: - { name: chill.export_aggregator, alias: accompanyingcourse_closingmotive_aggregator } + + chill.person.export.aggregator_administrative_location: + class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\AdministrativeLocationAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: accompanyingcourse_administrative_location_aggregator } diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 767061f55..14505de45 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -457,7 +457,9 @@ Group by closing motive: Grouper par motif de fermeture Filter by administrative location: Filtrer par localisation administrative Accepted locations: Localisations administratives +Administrative location: Localisation administrative "Filtered by administratives locations: only %locations%": "Filtré par localisation administrative: uniquement %locations%" +Group by administrative location: Grouper par localisation administrative Filter by requestor: Filtrer les parcours selon la présence du demandeur au sein des usagers concernés Accepted choices: ''