From cbc83c0e63eed828d5baed885b3000474f0cb468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 10 Nov 2023 14:41:58 +0100 Subject: [PATCH] Export: add grouping "group activity by person" (activites saved in person context) --- .../unreleased/Feature-20231110-144056.yaml | 6 ++ .../PersonAggregators/PersonAggregator.php | 65 +++++++++++++++++++ .../PersonAggregatorTest.php | 57 ++++++++++++++++ .../config/services/export.yaml | 4 ++ .../translations/messages.fr.yml | 4 ++ 5 files changed, 136 insertions(+) create mode 100644 .changes/unreleased/Feature-20231110-144056.yaml create mode 100644 src/Bundle/ChillActivityBundle/Export/Aggregator/PersonAggregators/PersonAggregator.php create mode 100644 src/Bundle/ChillActivityBundle/Tests/Export/Aggregator/PersonAggregators/PersonAggregatorTest.php diff --git a/.changes/unreleased/Feature-20231110-144056.yaml b/.changes/unreleased/Feature-20231110-144056.yaml new file mode 100644 index 000000000..f263d14c6 --- /dev/null +++ b/.changes/unreleased/Feature-20231110-144056.yaml @@ -0,0 +1,6 @@ +kind: Feature +body: 'Export: add an aggregator "group activities by person" (only for the activities + saved in a person context)' +time: 2023-11-10T14:40:56.93459414+01:00 +custom: + Issue: "199" diff --git a/src/Bundle/ChillActivityBundle/Export/Aggregator/PersonAggregators/PersonAggregator.php b/src/Bundle/ChillActivityBundle/Export/Aggregator/PersonAggregators/PersonAggregator.php new file mode 100644 index 000000000..c7a3bd6b5 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Export/Aggregator/PersonAggregators/PersonAggregator.php @@ -0,0 +1,65 @@ +labelPersonHelper->getLabel($key, $values, 'export.aggregator.person.by_person.person'); + } + + public function getQueryKeys($data) + { + return ['activity_by_person_agg']; + } + + public function getTitle() + { + return 'export.aggregator.person.by_person.title'; + } + + public function addRole(): ?string + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb + ->addSelect('IDENTITY(activity.person) AS activity_by_person_agg') + ->addGroupBy('activity_by_person_agg'); + } + + public function applyOn() + { + return Declarations::ACTIVITY_PERSON; + } +} diff --git a/src/Bundle/ChillActivityBundle/Tests/Export/Aggregator/PersonAggregators/PersonAggregatorTest.php b/src/Bundle/ChillActivityBundle/Tests/Export/Aggregator/PersonAggregators/PersonAggregatorTest.php new file mode 100644 index 000000000..388f13793 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/Tests/Export/Aggregator/PersonAggregators/PersonAggregatorTest.php @@ -0,0 +1,57 @@ +labelPersonHelper = self::$container->get(LabelPersonHelper::class); + } + + public function getAggregator() + { + return new PersonAggregator($this->labelPersonHelper); + } + + public function getFormData() + { + return [[]]; + } + + public function getQueryBuilders() + { + self::bootKernel(); + + $em = self::$container->get(EntityManagerInterface::class); + + return [ + $em->createQueryBuilder() + ->select('count(activity.id)') + ->from(Activity::class, 'activity'), + ]; + } +} diff --git a/src/Bundle/ChillActivityBundle/config/services/export.yaml b/src/Bundle/ChillActivityBundle/config/services/export.yaml index ce219b82d..dcc6bec17 100644 --- a/src/Bundle/ChillActivityBundle/config/services/export.yaml +++ b/src/Bundle/ChillActivityBundle/config/services/export.yaml @@ -227,3 +227,7 @@ services: Chill\ActivityBundle\Export\Aggregator\ActivityPresenceAggregator: tags: - { name: chill.export_aggregator, alias: activity_presence_agg } + + Chill\ActivityBundle\Export\Aggregator\PersonAggregators\PersonAggregator: + tags: + - { name: chill.export_aggregator, alias: activity_person_agg } diff --git a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml index ed4c1a5f4..52c5366a7 100644 --- a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml @@ -395,6 +395,10 @@ export: 'Filtered by activity presence: only %presences%': 'Filtré par présence de l''usager: seulement %presences%' aggregator: + person: + by_person: + title: Grouper les échanges par usager (dossier d'usager dans lequel l'échange est enregistré) + person: Usager acp: by_activity_type: title: Grouper les parcours par type d'échange