mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
acp creator filter
This commit is contained in:
parent
eeb84d5cfb
commit
c396635163
@ -12,9 +12,12 @@ declare(strict_types=1);
|
|||||||
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
|
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
|
||||||
|
|
||||||
use Chill\MainBundle\Export\FilterInterface;
|
use Chill\MainBundle\Export\FilterInterface;
|
||||||
|
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;
|
||||||
|
|
||||||
class CreatorFilter implements FilterInterface
|
class CreatorFilter implements FilterInterface
|
||||||
{
|
{
|
||||||
@ -25,11 +28,21 @@ class CreatorFilter implements FilterInterface
|
|||||||
|
|
||||||
public function alterQuery(QueryBuilder $qb, $data)
|
public function alterQuery(QueryBuilder $qb, $data)
|
||||||
{
|
{
|
||||||
$qb
|
if (!in_array('acp_creator', $qb->getAllAliases(), true)) {
|
||||||
->andWhere(
|
$qb->join('acp.createdBy', 'acp_creator');
|
||||||
$qb->expr()->in('', ':')
|
}
|
||||||
)
|
|
||||||
->setParameter('', $data[]);
|
$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
|
public function applyOn(): string
|
||||||
@ -39,13 +52,24 @@ class CreatorFilter implements FilterInterface
|
|||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder)
|
public function buildForm(FormBuilderInterface $builder)
|
||||||
{
|
{
|
||||||
$builder->add();
|
$builder
|
||||||
|
->add('accepted_creators', PickUserDynamicType::class, [
|
||||||
|
'multiple' => true,
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function describeAction($data, $format = 'string'): array
|
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
|
public function getTitle(): string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user