From ddac410b2e5be2db7542dc92f89c5d0d4baf3ce7 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 25 Jul 2022 16:19:54 +0200 Subject: [PATCH] exports: fix choice forms builder with multiple selections --- .../Export/Filter/ClosingMotiveFilter.php | 17 +++++++++++------ .../Export/Filter/OriginFilter.php | 15 ++++++++++----- .../Export/Filter/StepFilter.php | 18 +++++++++++------- .../translations/messages.fr.yml | 6 +++--- 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/ClosingMotiveFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/ClosingMotiveFilter.php index b4fc3f94d..7ff78d41b 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/ClosingMotiveFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/ClosingMotiveFilter.php @@ -34,8 +34,8 @@ class ClosingMotiveFilter implements FilterInterface 'choice_label' => function (ClosingMotive $cm) { return $this->translatableStringHelper->localize($cm->getName()); }, - 'multiple' => false, - 'expanded' => false + 'multiple' => true, + 'expanded' => true, ]); } @@ -52,10 +52,15 @@ class ClosingMotiveFilter implements FilterInterface */ public function describeAction($data, $format = 'string'): array { + $motives = []; + + foreach ($data['accepted_closingmotives'] as $k => $v) { + $motives[] = $this->translatableStringHelper->localize($v->getName()); + } + return [ - 'Filtered by closingmotive: only %closingmotive%', [ - '%closingmotive%' => $this->translatableStringHelper->localize( - $data['accepted_closingmotives']->getName()) + 'Filtered by closingmotive: only %closingmotives%', [ + '%closingmotives%' => implode(', ou ', $motives) ]]; } @@ -73,7 +78,7 @@ class ClosingMotiveFilter implements FilterInterface public function alterQuery(QueryBuilder $qb, $data) { $where = $qb->getDQLPart('where'); - $clause = $qb->expr()->eq('acp.closingMotive', ':closingmotive'); + $clause = $qb->expr()->in('acp.closingMotive', ':closingmotive'); if ($where instanceof Andx) { $where->add($clause); diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/OriginFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/OriginFilter.php index 01cbdfb89..936767009 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/OriginFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/OriginFilter.php @@ -35,7 +35,7 @@ class OriginFilter implements FilterInterface 'choice_label' => function (Origin $o) { return $this->translatableStringHelper->localize($o->getLabel()); }, - 'multiple' => false, + 'multiple' => true, 'expanded' => true ]); } @@ -53,9 +53,14 @@ class OriginFilter implements FilterInterface */ public function describeAction($data, $format = 'string'): array { - return ['Filtered by origins: only %origin%', [ - '%origin%' => $this->translatableStringHelper->localize( - $data['accepted_origins']->getLabel()) + $origins = []; + + foreach ($data['accepted_origins'] as $v) { + $origins[] = $this->translatableStringHelper->localize($v->getLabel()); + } + + return ['Filtered by origins: only %origins%', [ + '%origins%' => implode(', ou ', $origins) ]]; } @@ -73,7 +78,7 @@ class OriginFilter implements FilterInterface public function alterQuery(QueryBuilder $qb, $data) { $where = $qb->getDQLPart('where'); - $clause = $qb->expr()->eq('acp.origin', ':origin'); + $clause = $qb->expr()->in('acp.origin', ':origin'); if ($where instanceof Andx) { $where->add($clause); diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/StepFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/StepFilter.php index e3fbc19d5..98d496714 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/StepFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/StepFilter.php @@ -39,10 +39,8 @@ class StepFilter implements FilterInterface { $builder->add('accepted_steps', ChoiceType::class, [ 'choices' => self::STEPS, - 'multiple' => false, + 'multiple' => true, 'expanded' => true, - 'empty_data' => self::DEFAULT_CHOICE, - 'data' => self::DEFAULT_CHOICE, ]); } @@ -53,10 +51,16 @@ class StepFilter implements FilterInterface public function describeAction($data, $format = 'string') { - $step = array_flip(self::STEPS)[$data['accepted_steps']]; + $steps = []; - return ["Filtered by steps: only %step%", [ - '%step%' => $this->translator->trans($step) + foreach ($data['accepted_steps'] as $v) { + $steps[] = $this->translator->trans( + array_flip(self::STEPS)[$v] + ); + } + + return ["Filtered by steps: only %steps%", [ + '%steps%' => implode(', ou ', $steps) ]]; } @@ -68,7 +72,7 @@ class StepFilter implements FilterInterface public function alterQuery(QueryBuilder $qb, $data) { $where = $qb->getDQLPart('where'); - $clause = $qb->expr()->eq('acp.step', ':step'); + $clause = $qb->expr()->in('acp.step', ':step'); if ($where instanceof Andx) { $where->add($clause); diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 75da040d0..c755126de 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -388,15 +388,15 @@ Accepted socialissues: Problématiques sociales Filter by step: Filtrer par statut du parcours Accepted steps: Statuts -"Filtered by steps: only %step%": "Filtré par statut du parcours: uniquement %step%" +"Filtered by steps: only %steps%": "Filtré par statut du parcours: uniquement %steps%" Filter by origin: Filtrer par origine du parcours Accepted origins: Origines -"Filtered by origins: only %origin%": "Filtré par origine du parcours: uniquement %origin%" +"Filtered by origins: only %origins%": "Filtré par origine du parcours: uniquement %origins%" Filter by closing motive: Filtrer par motif de fermeture Accepted closingmotives: Motifs de clôture -"Filtered by closingmotive: only %closingmotive%": "Filtré par motif de clôture: uniquement %closingmotive%" +"Filtered by closingmotive: only %closingmotives%": "Filtré par motif de clôture: uniquement %closingmotives%" Filter by confidential: Filtrer par confidentialité Accepted confidentials: Choix possibles