diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php index 7629a7b60..0cf7f979d 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php @@ -50,17 +50,23 @@ class SocialWorkTypeFilter implements FilterInterface $builder ->add('actionType', HiddenType::class) ->get('actionType') - ->addModelTransformer($this->iterableToIdTransformer(SocialAction::class)) + ->addModelTransformer( + $this->iterableToIdTransformer(SocialAction::class) + ) ; $builder ->add('goal', HiddenType::class) ->get('goal') - ->addModelTransformer($this->iterableToIdTransformer(Goal::class)) + ->addModelTransformer( + $this->iterableToIdTransformer(Goal::class) + ) ; $builder ->add('result', HiddenType::class) ->get('result') - ->addModelTransformer($this->iterableToIdTransformer(Result::class)) + ->addModelTransformer( + $this->iterableToIdTransformer(Result::class) + ) ; } @@ -90,27 +96,35 @@ class SocialWorkTypeFilter implements FilterInterface public function getTitle(): string { - return 'Filter by type of action, objectives and results'; + return 'Filter by type of action, goals and results'; } public function describeAction($data, $format = 'string'): array { $actionTypes = []; - $objectives = []; + $goals = []; $results = []; foreach ($data['actionType'] as $at) { - $actionTypes[] = $at->getTitle(); - } - foreach ($data['objectives'] as $o) { - $objectives[] = $o->getTitle(); - } - foreach ($data['results'] as $r) { - $results[] = $r->getTitle(); + $actionTypes[] = $this->translatableStringHelper->localize( + $at->getTitle() + ); } - return ['Filtered by referrers: only %actionTypes%', [ - '%actionTypes%' => implode(', ou ', $actionTypes) + foreach ($data['goal'] as $g) { + $goals[] = $this->translatableStringHelper->localize( + $g->getTitle() + ); + } + + foreach ($data['result'] as $r) { + $results[] = $this->translatableStringHelper->localize( + $r->getTitle() + ); + } + + return ['Filtered actions by type, goals and results: %selected%', [ + '%selected%' => implode(', ', array_merge($actionTypes, $goals, $results)) ]]; } @@ -122,28 +136,44 @@ class SocialWorkTypeFilter implements FilterInterface public function alterQuery(QueryBuilder $qb, $data) { $where = $qb->getDQLPart('where'); - $clause = $qb->expr()->eq('acpw.socialAction',':actionType'); - /* - if (!empty($data['goal'])) { - $clause - $qb->expr()->in('acpw.goals', ':goals'); + if (count($data['actionType']) > 0) { + $clause = $qb->expr()->in('acpw.socialAction', ':actionType'); + + if ($where instanceof Andx) { + $where->add($clause); + } else { + $where = $qb->expr()->andX($clause); + } + + $qb->setParameter('actionType', $data['actionType']); } - $qb->expr()->in('acpw.results', ':results'); - */ - if ($where instanceof Andx) { - $where->add($clause); - } else { - $where = $qb->expr()->andX($clause); + if (count($data['goal']) > 0) { + if (!in_array('goal', $qb->getAllAliases(), true)) { + $qb->join('acpw.goals', 'goal'); + } + + $where->add( + $qb->expr()->in('goal.id', ':goals') + ); + + $qb->setParameter('goals', $data['goal']); + } + + if (count($data['result']) > 0) { + if (!in_array('result', $qb->getAllAliases(), true)) { + $qb->join('acpw.results', 'result'); + } + + $where->add( + $qb->expr()->in('result.id', ':results') + ); + + $qb->setParameter('results', $data['result']); } $qb->add('where', $where); - $qb->setParameters([ - 'actionType' => $data['actionType'], - 'goal' => $data['goal'], - 'result' => $data['result'], - ]); } public function applyOn(): string diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 98facddf9..05e9a82a0 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -456,7 +456,9 @@ Filter by socialaction: Filtrer les parcours par action d'accompagnement Accepted socialactions: Actions d'accompagnement "Filtered by socialactions: only %socialactions%": "Filtré par action d'accompagnement: uniquement %socialactions%" Group by social action: Grouper les parcours par action d'accompagnement -Filter by type of action, objectives and results: "Filtrer les actions par type, objectif et résultat" + +Filter by type of action, goals and results: "Filtrer les actions par type, objectif et résultat" +'Filtered actions by type, goals and results: %selected%': "Actions filtrées par: %selected%" Filter by evaluation: Filtrer les parcours par évaluation Accepted evaluations: Évaluations