DX: simplify creatorJobFilter

This commit is contained in:
Julien Fastré 2022-11-02 13:05:12 +01:00
parent be75cdce55
commit be215bd135
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\Entity\UserJob;
use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Repository\UserJobRepositoryInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr\Andx;
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;
@ -25,10 +25,14 @@ class CreatorJobFilter implements FilterInterface
{ {
private TranslatableStringHelper $translatableStringHelper; private TranslatableStringHelper $translatableStringHelper;
private UserJobRepositoryInterface $userJobRepository;
public function __construct( public function __construct(
TranslatableStringHelper $translatableStringHelper TranslatableStringHelper $translatableStringHelper,
UserJobRepositoryInterface $userJobRepository
) { ) {
$this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
$this->userJobRepository = $userJobRepository;
} }
public function addRole(): ?string public function addRole(): ?string
@ -42,17 +46,9 @@ class CreatorJobFilter implements FilterInterface
$qb->join('acp.createdBy', 'acp_creator'); $qb->join('acp.createdBy', 'acp_creator');
} }
$where = $qb->getDQLPart('where'); $qb
$clause = $qb->expr()->in('acp_creator.userJob', ':creator_job'); ->andWhere($qb->expr()->in('acp_creator.userJob', ':creator_job'))
->setParameter('creator_job', $data['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']);
} }
public function applyOn(): string public function applyOn(): string
@ -64,6 +60,7 @@ class CreatorJobFilter implements FilterInterface
{ {
$builder->add('creator_job', EntityType::class, [ $builder->add('creator_job', EntityType::class, [
'class' => UserJob::class, 'class' => UserJob::class,
'choices' => $this->userJobRepository->findAllActive(),
'choice_label' => function (UserJob $j) { 'choice_label' => function (UserJob $j) {
return $this->translatableStringHelper->localize( return $this->translatableStringHelper->localize(
$j->getLabel() $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), '%jobs%' => implode(', ', $creatorJobs),
]]; ]];
} }

View File

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