issue641: simplify alterQuery where clause in concerned filters

This commit is contained in:
Mathieu Jaumotte 2022-10-16 13:53:05 +02:00
parent a46c85d66c
commit 6d40ef279f
4 changed files with 8 additions and 45 deletions

View File

@ -15,7 +15,6 @@ use Chill\ActivityBundle\Export\Declarations;
use Chill\MainBundle\Export\FilterInterface;
use Chill\PersonBundle\Form\Type\Select2SocialActionType;
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
@ -36,22 +35,14 @@ class BySocialActionFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$where = $qb->getDQLPart('where');
if (!in_array('actsocialaction', $qb->getAllAliases(), true)) {
$qb->join('activity.socialActions', 'actsocialaction');
}
$clause = $qb->expr()->in('actsocialaction.id', ':socialactions');
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('socialactions', $data['accepted_socialactions']);
$qb ->andWhere($clause)
->setParameter('socialactions', $data['accepted_socialactions']);
}
public function applyOn(): string

View File

@ -15,7 +15,6 @@ use Chill\ActivityBundle\Export\Declarations;
use Chill\MainBundle\Export\FilterInterface;
use Chill\PersonBundle\Form\Type\Select2SocialIssueType;
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
@ -36,22 +35,14 @@ class BySocialIssueFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data)
{
$where = $qb->getDQLPart('where');
if (!in_array('actsocialissue', $qb->getAllAliases(), true)) {
$qb->join('activity.socialIssues', 'actsocialissue');
}
$clause = $qb->expr()->in('actsocialissue.id', ':socialissues');
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('socialissues', $data['accepted_socialissues']);
$qb ->andWhere($clause)
->setParameter('socialissues', $data['accepted_socialissues']);
}
public function applyOn(): string

View File

@ -16,7 +16,6 @@ use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Form\Type\Select2SocialActionType;
use Chill\PersonBundle\Templating\Entity\SocialActionRender;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use function in_array;
@ -50,17 +49,10 @@ class SocialActionFilter implements FilterInterface
$qb->join('acpw.socialAction', 'acpwsocialaction');
}
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('acpwsocialaction.id', ':socialactions');
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('socialactions', $data['accepted_socialactions']);
$qb ->andWhere($clause)
->setParameter('socialactions', $data['accepted_socialactions']);
}
public function applyOn(): string

View File

@ -17,7 +17,6 @@ use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Form\Type\Select2SocialIssueType;
use Chill\PersonBundle\Templating\Entity\SocialIssueRender;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
@ -55,20 +54,10 @@ class SocialIssueFilter implements FilterInterface
$qb->join('acp.socialIssues', 'acpsocialissue');
}
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->in('acpsocialissue.id', ':socialissues');
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter(
'socialissues',
$this->addParentIssues($data['accepted_socialissues'])
);
$qb ->andWhere($clause)
->setParameter('socialissues', $this->addParentIssues($data['accepted_socialissues']));
}
public function applyOn()