exports: fix choice forms builder with multiple selections

This commit is contained in:
Mathieu Jaumotte 2022-07-25 16:19:54 +02:00
parent 43bedc41a7
commit ddac410b2e
4 changed files with 35 additions and 21 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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