mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fix filter evaluation by evaluation type
This commit is contained in:
parent
673518e0eb
commit
00de657cae
5
.changes/unreleased/Fixed-20231201-094510.yaml
Normal file
5
.changes/unreleased/Fixed-20231201-094510.yaml
Normal 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"
|
@ -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'],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user