DX: [export] review on CreatorFilter, CreatorJobAggregator, CreatorJobFilter

This commit is contained in:
Julien Fastré 2022-11-03 12:39:19 +01:00
parent c05637bc72
commit 82d9ab8ca6
4 changed files with 11 additions and 23 deletions

View File

@ -62,15 +62,13 @@ class CreatorJobAggregator implements AggregatorInterface
{ {
return function ($value): string { return function ($value): string {
if ('_header' === $value) { if ('_header' === $value) {
return 'Job'; return 'export.aggregator.course.by_creator_job.Creator\'s job';
} }
if (null === $value) { if (null === $value || null === $j = $this->jobRepository->find($value)) {
return ''; return '';
} }
$j = $this->jobRepository->find($value);
return $this->translatableStringHelper->localize( return $this->translatableStringHelper->localize(
$j->getLabel() $j->getLabel()
); );

View File

@ -11,10 +11,10 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\PickUserDynamicType; use Chill\MainBundle\Form\Type\PickUserDynamicType;
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\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use function in_array; use function in_array;
@ -32,17 +32,9 @@ class CreatorFilter 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', ':creators'); ->andWhere($qb->expr()->in('acp_creator', ':creators'))
->setParameter('creators', $data['accepted_creators']);
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('creators', $data['accepted_creators']);
} }
public function applyOn(): string public function applyOn(): string
@ -55,20 +47,15 @@ class CreatorFilter implements FilterInterface
$builder $builder
->add('accepted_creators', PickUserDynamicType::class, [ ->add('accepted_creators', PickUserDynamicType::class, [
'multiple' => true, 'multiple' => true,
'label' => false,
]); ]);
} }
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {
$creators = [];
foreach ($data['accepted_creators'] as $c) {
$creators[] = $c;
}
return [ return [
'Filtered by creator: only %creators%', [ 'Filtered by creator: only %creators%', [
'%creators%' => implode(', ', $creators), '%creators%' => implode(', ', array_map(static fn (User $u) => $u->getLabel(), $data['accepted_creators'])),
], ]; ], ];
} }

View File

@ -68,6 +68,7 @@ class CreatorJobFilter implements FilterInterface
}, },
'multiple' => true, 'multiple' => true,
'expanded' => true, 'expanded' => true,
'label' => 'Job',
]); ]);
} }

View File

@ -1008,6 +1008,8 @@ export:
Calc date: Date de calcul de la composition du ménage Calc date: Date de calcul de la composition du ménage
by_number_of_action: by_number_of_action:
Number of actions: Nombre d'actions Number of actions: Nombre d'actions
by_creator_job:
Creator's job: Métier du créateur
course_work: course_work:
by_current_action: by_current_action:
Current action ?: Action en cours ? Current action ?: Action en cours ?