From 374ad43df6c378b8eca7b1e615b816fe3f9de5f9 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 1 Sep 2022 10:11:53 +0200 Subject: [PATCH] exports: cleaning code --- .../ACPAggregators/DateAggregator.php | 2 +- .../DurationAggregator.php | 58 ++++--------------- .../RequestorAggregator.php | 15 +---- .../RequestorFilter.php | 2 +- 4 files changed, 15 insertions(+), 62 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/DateAggregator.php b/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/DateAggregator.php index 1c2f02d3b..ace5557d4 100644 --- a/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/DateAggregator.php +++ b/src/Bundle/ChillActivityBundle/Export/Aggregator/ACPAggregators/DateAggregator.php @@ -96,7 +96,7 @@ class DateAggregator implements AggregatorInterface $fmt = 'IW'; break; case 'year': - $fmt = 'YYYY'; $order = 'DESC'; break; + $fmt = 'YYYY'; $order = 'DESC'; break; // order DESC does not works ! default: throw new RuntimeException(sprintf("The frequency data '%s' is invalid.", $data['frequency'])); diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/DurationAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/DurationAggregator.php index ec9d1c1c6..a738283ec 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/DurationAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/DurationAggregator.php @@ -12,16 +12,7 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Contracts\Translation\TranslatorInterface; -/** - * Les regroupements seront un nombre de mois, arrondi à l'unité la plus proche (donc - * - au dela de 15 jours => 1 mois, - * - jusqu'à 45 jours => 1 mois, - * 15 | 45 | 75 - * --+----o----+----o----+---- - * | 30 | 60 | - * etc.) - */ -class DurationAggregator implements AggregatorInterface +final class DurationAggregator implements AggregatorInterface { private TranslatorInterface $translator; @@ -49,7 +40,7 @@ class DurationAggregator implements AggregatorInterface return $this->translator->trans("duration 0 month"); } - return ''. $value . $this->translator->trans(' months'); + return $value . $this->translator->trans(' months'); }; } @@ -90,44 +81,15 @@ class DurationAggregator implements AggregatorInterface */ public function alterQuery(QueryBuilder $qb, $data) { - $qb - // OUI - ->addSelect(' - (acp.closingDate - acp.openingDate +15) *12/365 - AS duration_aggregator' - ) - //->addSelect('DATE_DIFF(acp.closingDate, acp.openingDate) AS duration_aggregator') - //->addSelect('EXTRACT(month FROM acp.openingDate) AS duration_aggregator') - //->addSelect("DATE_SUB(acp.openingDate, 6, 'day') AS duration_aggregator") + $qb->addSelect(' + (acp.closingDate - acp.openingDate +15) *12/365 + AS duration_aggregator' + ); - // TODO adapter la fonction extract pour l'utiliser avec des intervals: extract(month from interval) - // et ajouter une fonction custom qui calcule les intervals, comme doctrineum/date-interval - // 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") - */ - - // NON - //->addSelect("BETWEEN acp.openingDate AND acp.closingDate AS duration_aggregator") - //->addSelect("EXTRACT(month FROM DATE_SUB(acp.openingDate, 6, 'day')) AS duration_aggregator") - //->addSelect('EXTRACT(month FROM DATE_DIFF(acp.closingDate, acp.openingDate)) AS duration_aggregator') - /* - ->addSelect(' - ( CASE - WHEN EXTRACT(day FROM DATE_DIFF(acp.closingDate, acp.openingDate)) > 15 - THEN EXTRACT(month FROM DATE_DIFF(acp.closingDate, acp.openingDate)) +1 - ELSE EXTRACT(month FROM DATE_DIFF(acp.closingDate, acp.openingDate)) - END ) AS duration_aggregator - ') - */ - ; + // TODO Pour avoir un interval plus précis (nécessaire ?): + // adapter la fonction extract pour pouvoir l'utiliser avec des intervals: extract(month from interval) + // et ajouter une fonction custom qui calcule plus précisément les intervals, comme doctrineum/date-interval + // https://packagist.org/packages/doctrineum/date-interval#3.1.0 (mais composer fait un conflit de dépendance) $groupBy = $qb->getDQLPart('groupBy'); diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/RequestorAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/RequestorAggregator.php index 06d09f776..916596b03 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/RequestorAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/RequestorAggregator.php @@ -8,14 +8,7 @@ use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Contracts\Translation\TranslatorInterface; -/** - * les regroupements suivants seront effecturés: - * - le demandeur est un usager concerné - * - le demander est un usager, mais non concerné - * - le demandeur est un tiers - * - le parcours ne comporte pas de demandeur - */ -class RequestorAggregator implements AggregatorInterface +final class RequestorAggregator implements AggregatorInterface { private TranslatorInterface $translator; @@ -43,9 +36,7 @@ class RequestorAggregator implements AggregatorInterface */ public function getQueryKeys($data): array { - return [ - 'requestor_aggregator' - ]; + return ['requestor_aggregator']; } /** @@ -107,7 +98,7 @@ class RequestorAggregator implements AggregatorInterface $qb->groupBy('requestor_aggregator'); } - // TODO 'order by' ne fonctionne pas, l'ordre n'est pas terrible + // TODO 'order by' does not works ! } /** diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/RequestorFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/RequestorFilter.php index 180775f01..571e36e15 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/RequestorFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/RequestorFilter.php @@ -11,7 +11,7 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Contracts\Translation\TranslatorInterface; -class RequestorFilter implements FilterInterface +final class RequestorFilter implements FilterInterface { private const REQUESTOR_CHOICES = [