Fix filter evaluation by evaluation type

This commit is contained in:
Julien Fastré 2023-12-01 09:46:02 +01:00
parent 673518e0eb
commit 00de657cae
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
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\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'],
]);
}

View File

@ -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'),
];
}
}