From c396635163593bfe825de13f051bd3187ab606d2 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 2 Nov 2022 11:15:54 +0100 Subject: [PATCH] acp creator filter --- .../CreatorFilter.php | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/CreatorFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/CreatorFilter.php index c7e110f62..1ac6d5390 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/CreatorFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/CreatorFilter.php @@ -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