From 3b68997c6951f1b7265e8e169c9ec20c4bdeb9ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 2 Nov 2022 16:42:23 +0100 Subject: [PATCH] Feature: [export][evaluation] Group evaluation by start date --- .../ByStartDateAggregator.php | 54 +++++++++++++++++-- .../translations/messages.fr.yml | 4 +- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/EvaluationAggregators/ByStartDateAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/EvaluationAggregators/ByStartDateAggregator.php index e64245d53..a41fe2451 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/EvaluationAggregators/ByStartDateAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/EvaluationAggregators/ByStartDateAggregator.php @@ -14,10 +14,23 @@ namespace Chill\PersonBundle\Export\Aggregator\EvaluationAggregators; use Chill\MainBundle\Export\AggregatorInterface; use Chill\PersonBundle\Export\Declarations; use Doctrine\ORM\QueryBuilder; +use LogicException; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Contracts\Translation\TranslatorInterface; class ByStartDateAggregator implements AggregatorInterface { + private const CHOICES = [ + 'by month' => 'month', + 'by week' => 'week', + 'by year' => 'year', + ]; + + private const DEFAULT_CHOICE = 'year'; + + private TranslatorInterface $translator; + public function addRole(): ?string { return null; @@ -25,8 +38,29 @@ class ByStartDateAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { - $qb->addSelect('AS eval_by_start_date_aggregator') - ->addGroupBy('eval_by_start_date_aggregator'); + switch ($data['frequency']) { + case 'month': + $fmt = 'YYYY-MM'; + + break; + + case 'week': + $fmt = 'YYYY-IW'; + + break; + + case 'year': + $fmt = 'YYYY'; + + break; + + default: + throw new LogicException(sprintf("The frequency data '%s' is invalid.", $data['frequency'])); + } + + $qb->addSelect(sprintf("TO_CHAR(workeval.startDate, '%s') AS eval_by_start_date_aggregator", $fmt)); + $qb->addGroupBy(' eval_by_start_date_aggregator'); + $qb->addOrderBy(' eval_by_start_date_aggregator', 'ASC'); } public function applyOn(): string @@ -36,15 +70,27 @@ class ByStartDateAggregator implements AggregatorInterface public function buildForm(FormBuilderInterface $builder) { - // No form needed + $builder->add('frequency', ChoiceType::class, [ + 'choices' => self::CHOICES, + 'multiple' => false, + 'expanded' => true, + 'empty_data' => self::DEFAULT_CHOICE, + 'data' => self::DEFAULT_CHOICE, + ]); } public function getLabels($key, array $values, $data) { return static function ($value): string { if ('_header' === $value) { + return 'export.aggregator.eval.by_start_date_period.Start date period'; + } + + if (null === $value) { return ''; } + + return $value; }; } @@ -55,6 +101,6 @@ class ByStartDateAggregator implements AggregatorInterface public function getTitle(): string { - return 'Group by start date evaluations'; + return 'export.aggregator.eval.by_start_date_period.Group by start date evaluations'; } } diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 8f6622986..7780c76dd 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -587,7 +587,6 @@ end period date: Date de fin de la période "Filtered by end date: between %start_date% and %end_date%": "Filtré par la date de fin: comprise entre %start_date% et %end_date%" Filter by current evaluations: Filtrer les évaluations en cours "Filtered by current evaluations": "Filtré: uniquement les évaluations en cours" -Group by start date evaluations: Grouper les évaluations par semaine/mois/année de la date de début Group by end date evaluations: Grouper les évaluations par semaine/mois/année de la date de fin Group by max date evaluations: Grouper les évaluations par semaine/mois/année de la date d'échéance @@ -1023,6 +1022,9 @@ export: Group evaluations having end date: Grouper les évaluations en cours (avec ou sans date de fin) enddate is specified: la date de fin est spécifiée enddate is not specified: la date de fin n'est pas spécifiée + by_start_date_period: + Start date period: Début (par periode) + Group by start date evaluations: Grouper les évaluations par semaine/mois/année de la date de début filter: course: by_user_scope: