From 5940e2c0b74b66cb4d0458a86a62e5afeb5ab2b0 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 8 Aug 2022 17:39:53 +0200 Subject: [PATCH] exports: add new Confidential and Emergency Aggregators --- .../ConfidentialAggregator.php | 100 ++++++++++++++++++ .../EmergencyAggregator.php | 100 ++++++++++++++++++ .../services/exports_accompanying_course.yaml | 14 +++ .../translations/messages.fr.yml | 4 + 4 files changed, 218 insertions(+) create mode 100644 src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ConfidentialAggregator.php create mode 100644 src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/EmergencyAggregator.php diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ConfidentialAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ConfidentialAggregator.php new file mode 100644 index 000000000..d2bec5c32 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ConfidentialAggregator.php @@ -0,0 +1,100 @@ +translator = $translator; + } + + /** + * @inheritDoc + */ + public function getLabels($key, array $values, $data) + { + return function ($value): string { + if ($value === '_header') { + return 'Confidentiality'; + } + switch ($value) { + + case true: + return $this->translator->trans('is confidential'); + + case false: + return $this->translator->trans('is not confidential'); + + default: + throw new LogicException(sprintf('The value %s is not valid', $value)); + } + return $value; + }; + } + + /** + * @inheritDoc + */ + public function getQueryKeys($data): array + { + return ['confidential_aggregator']; + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Group by confidential'; + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->addSelect('acp.confidential AS confidential_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('confidential_aggregator'); + } else { + $qb->groupBy('confidential_aggregator'); + } + } + + /** + * @inheritDoc + */ + public function applyOn(): string + { + return Declarations::ACP_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/EmergencyAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/EmergencyAggregator.php new file mode 100644 index 000000000..c5991e7f0 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/EmergencyAggregator.php @@ -0,0 +1,100 @@ +translator = $translator; + } + + /** + * @inheritDoc + */ + public function getLabels($key, array $values, $data) + { + return function ($value): string { + if ($value === '_header') { + return 'Emergency'; + } + switch ($value) { + + case true: + return $this->translator->trans('is emergency'); + + case false: + return $this->translator->trans('is not emergency'); + + default: + throw new LogicException(sprintf('The value %s is not valid', $value)); + } + return $value; + }; + } + + /** + * @inheritDoc + */ + public function getQueryKeys($data): array + { + return ['emergency_aggregator']; + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Group by emergency'; + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->addSelect('acp.emergency AS emergency_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('emergency_aggregator'); + } else { + $qb->groupBy('emergency_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 45c818ffb..5a97f1b85 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml @@ -212,3 +212,17 @@ services: autoconfigure: true tags: - { name: chill.export_aggregator, alias: accompanyingcourse_administrative_location_aggregator } + + chill.person.export.aggregator_confidential: + class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\ConfidentialAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: accompanyingcourse_confidential_aggregator } + + chill.person.export.aggregator_emergency: + class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\EmergencyAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: accompanyingcourse_emergency_aggregator } diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 14505de45..1bfd1f5c3 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -474,12 +474,16 @@ Accepted confidentials: '' is confidential: le parcours est confidentiel is not confidential: le parcours n'est pas confidentiel "Filtered by confidential: only %confidential%": "Filtré par confidentialité: uniquement si %confidential%" +Confidentiality: Confidentialité +Group by confidential: Grouper par confidentialité Filter by emergency: Filtrer par urgence Accepted emergencies: '' is emergency: le parcours est urgent is not emergency: le parcours n'est pas urgent "Filtered by emergency: only %emergency%": "Filtré par urgence: uniquement si %emergency%" +Emergency: Urgence +Group by emergency: Grouper par urgence Filter by intensity: Filtrer par intensité Accepted intensities: ''