Merge branch '233-fix-filter-by-evaluation-type' into 'master'

Fix filter evaluation by evaluation type

Closes #233

See merge request Chill-Projet/chill-bundles!628
This commit is contained in:
Julien Fastré 2023-12-07 15:23:24 +00:00
commit 0e599a99a7
3 changed files with 19 additions and 15 deletions

View File

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

View File

@ -15,14 +15,14 @@ use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\SocialWork\Evaluation; use Chill\PersonBundle\Entity\SocialWork\Evaluation;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr\Andx; use Chill\PersonBundle\Repository\SocialWork\EvaluationRepositoryInterface;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
final readonly class EvaluationTypeFilter implements FilterInterface 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 public function addRole(): ?string
{ {
@ -31,16 +31,9 @@ final readonly class EvaluationTypeFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data) public function alterQuery(QueryBuilder $qb, $data)
{ {
$where = $qb->getDQLPart('where'); $qb->andWhere(
$clause = $qb->expr()->in('eval.evaluation', ':evaluationtype'); $qb->expr()->in('workeval.evaluation', ':evaluationtype')
);
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('evaluationtype', $data['accepted_evaluationtype']); $qb->setParameter('evaluationtype', $data['accepted_evaluationtype']);
} }
@ -51,11 +44,17 @@ final readonly class EvaluationTypeFilter implements FilterInterface
public function buildForm(FormBuilderInterface $builder) 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, [ $builder->add('accepted_evaluationtype', EntityType::class, [
'class' => Evaluation::class, 'class' => Evaluation::class,
'choices' => $evaluations,
'choice_label' => fn (Evaluation $ev): string => $this->translatableStringHelper->localize($ev->getTitle()), 'choice_label' => fn (Evaluation $ev): string => $this->translatableStringHelper->localize($ev->getTitle()),
'multiple' => true, 'multiple' => true,
'expanded' => true, 'expanded' => false,
'attr' => ['class' => 'select2'],
]); ]);
} }

View File

@ -69,10 +69,10 @@ final class EvaluationTypeFilterTest extends AbstractFilterTest
return [ return [
$em->createQueryBuilder() $em->createQueryBuilder()
->select('eval.id') ->select('workeval.id')
->from(AccompanyingPeriod::class, 'acp') ->from(AccompanyingPeriod::class, 'acp')
->join('acp.works', 'acpw') ->join('acp.works', 'acpw')
->join('acpw.accompanyingPeriodWorkEvaluations', 'eval'), ->join('acpw.accompanyingPeriodWorkEvaluations', 'workeval'),
]; ];
} }
} }