acp creator filter

This commit is contained in:
Julie Lenaerts 2022-11-02 11:15:54 +01:00 committed by Julien Fastré
parent eeb84d5cfb
commit c396635163

View File

@ -12,9 +12,12 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\PickUserDynamicType;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
class CreatorFilter implements FilterInterface
{
@ -25,11 +28,21 @@ class CreatorFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$qb
->andWhere(
$qb->expr()->in('', ':')
)
->setParameter('', $data[]);
if (!in_array('acp_creator', $qb->getAllAliases(), true)) {
$qb->join('acp.createdBy', 'acp_creator');
}
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('acp_creator', ':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
@ -39,13 +52,24 @@ class CreatorFilter implements FilterInterface
public function buildForm(FormBuilderInterface $builder)
{
$builder->add();
$builder
->add('accepted_creators', PickUserDynamicType::class, [
'multiple' => true,
]);
}
public function describeAction($data, $format = 'string'): array
{
return ['', [
]];
$creators = [];
foreach ($data['accepted_creators'] as $c) {
$creators[] = $c;
}
return [
'Filtered by creator: only %creators%', [
'%creators%' => implode(', ', $creators),
], ];
}
public function getTitle(): string