From cae9dddac4355c3dd4091636df29e8f3ca04b723 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Wed, 31 Aug 2022 17:57:49 +0200 Subject: [PATCH] exports: fix acp requestor aggregator --- .../DurationAggregator.php | 18 +++--- .../RequestorAggregator.php | 60 +++++++++---------- .../translations/messages.fr.yml | 6 +- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/DurationAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/DurationAggregator.php index 2a0215e82..ec9d1c1c6 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/DurationAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/DurationAggregator.php @@ -35,10 +35,10 @@ class DurationAggregator implements AggregatorInterface */ public function getLabels($key, array $values, $data) { - return function ($value) use ($data): string { + return function ($value) use ($data): ?string { if ($value === '_header') { - return $this->translator->trans('Rounded month duration'); + return 'Rounded month duration'; } if ($value === null) { @@ -105,12 +105,14 @@ class DurationAggregator implements AggregatorInterface // https://packagist.org/packages/doctrineum/date-interval#3.1.0 // (composer fait un conflit de dépendance) - //->addSelect(" - // EXTRACT( - // month FROM - // DATE_INTERVAL(acp.closingDate, acp.openingDate) - // ) - // AS duration_aggregator") + /* + ->addSelect(" + EXTRACT( + month FROM + DATE_INTERVAL(acp.closingDate, acp.openingDate) + ) + AS duration_aggregator") + */ // NON //->addSelect("BETWEEN acp.openingDate AND acp.closingDate AS duration_aggregator") diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/RequestorAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/RequestorAggregator.php index 8d8b7029c..06d09f776 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/RequestorAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/RequestorAggregator.php @@ -30,27 +30,11 @@ class RequestorAggregator implements AggregatorInterface */ public function getLabels($key, array $values, $data) { - return function ($value): string { - switch ($value) { - - case '_header': - return 'Requestor'; - - case 'participation': - return $this->translator->trans('is person concerned'); - - case 'other_person': - return $this->translator->trans('is other person'); - - case 'thirdparty': - return $this->translator->trans('is thirdparty'); - - case 'no_requestor': - return $this->translator->trans('no requestor'); - - default: - throw new \LogicException(sprintf('The value %s is not valid', $value)); + return function ($value) use ($data): string { + if ($value === '_header') { + return 'Requestor'; } + return $this->translator->trans($value); }; } @@ -59,7 +43,9 @@ class RequestorAggregator implements AggregatorInterface */ public function getQueryKeys($data): array { - return ['requestor_aggregator']; + return [ + 'requestor_aggregator' + ]; } /** @@ -91,17 +77,27 @@ class RequestorAggregator implements AggregatorInterface */ public function alterQuery(QueryBuilder $qb, $data) { - /* - La requête va être différente par chaque regroupement. comment faire ? + if (!in_array('part', $qb->getAllAliases())) { + $qb->join('acp.participations', 'part'); + } - $qb - ->join('acp.requestorPerson','rp') - ->join('acp.requestorThirdParty','rt') - ->join('acp.participations', 'part') - ; - - $qb->addSelect('rp.id AS requestor_aggregator'); - */ + $qb->addSelect(" + ( CASE + WHEN acp.requestorPerson IS NOT NULL + THEN + ( CASE + WHEN acp.requestorPerson = part.person + THEN 'is person concerned' + ELSE 'is other person' + END ) + ELSE + ( CASE + WHEN acp.requestorThirdParty IS NOT NULL + THEN 'is thirdparty' + ELSE 'no requestor' + END ) + END ) AS requestor_aggregator + "); $groupBy = $qb->getDQLPart('groupBy'); @@ -110,6 +106,8 @@ class RequestorAggregator implements AggregatorInterface } else { $qb->groupBy('requestor_aggregator'); } + + // TODO 'order by' ne fonctionne pas, l'ordre n'est pas terrible } /** diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index e71db1a31..511bb791f 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -481,11 +481,11 @@ Group by administrative location: Grouper les parcours par localisation administ Filter by requestor: Filtrer les parcours selon la présence du demandeur au sein des usagers concernés Accepted choices: '' is person concerned: Le demandeur est un usager concerné -is other person: Le demandeur est un autre usager +is other person: Le demandeur est un usager, mais n'est pas concerné is thirdparty: Le demandeur est un tiers -no requestor: Il n'y a pas de demandeur +no requestor: Le parcours ne comporte pas de demandeur "Filtered by requestor: only %choice%": "Filtré par présence du demandeur au sein des usagers concernés: uniquement si %choice%" -Group by requestor: Grouper selon la nature du demandeur +Group by requestor: Grouper les parcours selon la nature du demandeur Filter by confidential: Filtrer les parcours par confidentialité Accepted confidentials: ''