DX: simplify creatorJobFilter

This commit is contained in:
Julien Fastré 2022-11-02 13:05:12 +01:00
parent 2767075be7
commit 6687742e23
2 changed files with 13 additions and 14 deletions

View File

@ -13,9 +13,9 @@ namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Entity\UserJob;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Repository\UserJobRepositoryInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface;
@ -25,10 +25,14 @@ class CreatorJobFilter implements FilterInterface
{
private TranslatableStringHelper $translatableStringHelper;
private UserJobRepositoryInterface $userJobRepository;
public function __construct(
TranslatableStringHelper $translatableStringHelper
TranslatableStringHelper $translatableStringHelper,
UserJobRepositoryInterface $userJobRepository
) {
$this->translatableStringHelper = $translatableStringHelper;
$this->userJobRepository = $userJobRepository;
}
public function addRole(): ?string
@ -42,17 +46,9 @@ class CreatorJobFilter implements FilterInterface
$qb->join('acp.createdBy', 'acp_creator');
}
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('acp_creator.userJob', ':creator_job');
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('creator_job', $data['creator_job']);
$qb
->andWhere($qb->expr()->in('acp_creator.userJob', ':creator_job'))
->setParameter('creator_job', $data['creator_job']);
}
public function applyOn(): string
@ -64,6 +60,7 @@ class CreatorJobFilter implements FilterInterface
{
$builder->add('creator_job', EntityType::class, [
'class' => UserJob::class,
'choices' => $this->userJobRepository->findAllActive(),
'choice_label' => function (UserJob $j) {
return $this->translatableStringHelper->localize(
$j->getLabel()
@ -84,7 +81,7 @@ class CreatorJobFilter implements FilterInterface
);
}
return ['Filtered by creator job: only %jobs%', [
return ['export.filter.course.creator_job.Filtered by creator job: only %jobs%', [
'%jobs%' => implode(', ', $creatorJobs),
]];
}

View File

@ -1025,6 +1025,8 @@ export:
Having a temporarily location: Ayant une localisation temporaire
Having a person's location: Ayant une localisation auprès d'un usager
Calculation date: Date de la localisation
creator_job:
'Filtered by creator job: only %jobs%': 'Filtré par métier du créateur: seulement %jobs%'
list:
person_with_acp:
List peoples having an accompanying period: Liste des personnes ayant un parcours d'accompagnement