From 00de657caedb9c2fcead27cf9e2573f86ec87f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 1 Dec 2023 09:46:02 +0100 Subject: [PATCH] Fix filter evaluation by evaluation type --- .../unreleased/Fixed-20231201-094510.yaml | 5 ++++ .../EvaluationTypeFilter.php | 25 +++++++++---------- .../EvaluationTypeFilterTest.php | 4 +-- 3 files changed, 19 insertions(+), 15 deletions(-) create mode 100644 .changes/unreleased/Fixed-20231201-094510.yaml diff --git a/.changes/unreleased/Fixed-20231201-094510.yaml b/.changes/unreleased/Fixed-20231201-094510.yaml new file mode 100644 index 000000000..b2239d12d --- /dev/null +++ b/.changes/unreleased/Fixed-20231201-094510.yaml @@ -0,0 +1,5 @@ +kind: Fixed +body: Fix "filter evaluation by evaluation type" (and add select2 to the list of evaluation types to pick) +time: 2023-12-01T09:45:10.744382859+01:00 +custom: + Issue: "233" diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/EvaluationTypeFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/EvaluationTypeFilter.php index eed856985..20472420c 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/EvaluationTypeFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/EvaluationTypeFilter.php @@ -15,14 +15,14 @@ use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Entity\SocialWork\Evaluation; use Chill\PersonBundle\Export\Declarations; -use Doctrine\ORM\Query\Expr\Andx; +use Chill\PersonBundle\Repository\SocialWork\EvaluationRepositoryInterface; use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\FormBuilderInterface; final readonly class EvaluationTypeFilter implements FilterInterface { - public function __construct(private TranslatableStringHelper $translatableStringHelper) {} + public function __construct(private TranslatableStringHelper $translatableStringHelper, private EvaluationRepositoryInterface $evaluationRepository) {} public function addRole(): ?string { @@ -31,16 +31,9 @@ final readonly class EvaluationTypeFilter implements FilterInterface public function alterQuery(QueryBuilder $qb, $data) { - $where = $qb->getDQLPart('where'); - $clause = $qb->expr()->in('eval.evaluation', ':evaluationtype'); - - if ($where instanceof Andx) { - $where->add($clause); - } else { - $where = $qb->expr()->andX($clause); - } - - $qb->add('where', $where); + $qb->andWhere( + $qb->expr()->in('workeval.evaluation', ':evaluationtype') + ); $qb->setParameter('evaluationtype', $data['accepted_evaluationtype']); } @@ -51,11 +44,17 @@ final readonly class EvaluationTypeFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { + $evaluations = $this->evaluationRepository->findAllActive(); + + usort($evaluations, fn (Evaluation $a, Evaluation $b) => $this->translatableStringHelper->localize($a->getTitle()) <=> $this->translatableStringHelper->localize($b->getTitle())); + $builder->add('accepted_evaluationtype', EntityType::class, [ 'class' => Evaluation::class, + 'choices' => $evaluations, 'choice_label' => fn (Evaluation $ev): string => $this->translatableStringHelper->localize($ev->getTitle()), 'multiple' => true, - 'expanded' => true, + 'expanded' => false, + 'attr' => ['class' => 'select2'], ]); } diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/EvaluationFilters/EvaluationTypeFilterTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/EvaluationFilters/EvaluationTypeFilterTest.php index 46c7ca853..601b67cdb 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Filter/EvaluationFilters/EvaluationTypeFilterTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Filter/EvaluationFilters/EvaluationTypeFilterTest.php @@ -69,10 +69,10 @@ final class EvaluationTypeFilterTest extends AbstractFilterTest return [ $em->createQueryBuilder() - ->select('eval.id') + ->select('workeval.id') ->from(AccompanyingPeriod::class, 'acp') ->join('acp.works', 'acpw') - ->join('acpw.accompanyingPeriodWorkEvaluations', 'eval'), + ->join('acpw.accompanyingPeriodWorkEvaluations', 'workeval'), ]; } }