simplify alterquery

This commit is contained in:
Mathieu Jaumotte 2023-01-30 14:35:48 +01:00
parent 896b4cdfe3
commit d1e8e6c18e

View File

@ -52,18 +52,10 @@ class SocialWorkTypeFilter implements FilterInterface
public function alterQuery(QueryBuilder $qb, $data) public function alterQuery(QueryBuilder $qb, $data)
{ {
$where = $qb->getDQLPart('where');
if (count($data['actionType']) > 0) { if (count($data['actionType']) > 0) {
$clause = $qb->expr()->in('acpw.socialAction', ':actionType'); $qb
->andWhere($qb->expr()->in('acpw.socialAction', ':actionType'))
if ($where instanceof Andx) { ->setParameter('actionType', $data['actionType']);
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->setParameter('actionType', $data['actionType']);
} }
if (count($data['goal']) > 0) { if (count($data['goal']) > 0) {
@ -71,11 +63,9 @@ class SocialWorkTypeFilter implements FilterInterface
$qb->join('acpw.goals', 'goal'); $qb->join('acpw.goals', 'goal');
} }
$where->add( $qb
$qb->expr()->in('goal.id', ':goals') ->andWhere($qb->expr()->in('goal.id', ':goals'))
); ->setParameter('goals', $data['goal']);
$qb->setParameter('goals', $data['goal']);
} }
if (count($data['result']) > 0) { if (count($data['result']) > 0) {
@ -83,14 +73,10 @@ class SocialWorkTypeFilter implements FilterInterface
$qb->join('acpw.results', 'result'); $qb->join('acpw.results', 'result');
} }
$where->add( $qb
$qb->expr()->in('result.id', ':results') ->andWhere($qb->expr()->in('result.id', ':results'))
); ->setParameter('results', $data['result']);
$qb->setParameter('results', $data['result']);
} }
$qb->add('where', $where);
} }
public function applyOn(): string public function applyOn(): string