From d1e8e6c18e4ace26f56777335e999c9b45967f51 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 30 Jan 2023 14:35:48 +0100 Subject: [PATCH 1/2] simplify alterquery --- .../SocialWorkTypeFilter.php | 32 ++++++------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php index efc005be0..ba4eaf6b8 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php @@ -52,18 +52,10 @@ class SocialWorkTypeFilter implements FilterInterface public function alterQuery(QueryBuilder $qb, $data) { - $where = $qb->getDQLPart('where'); - if (count($data['actionType']) > 0) { - $clause = $qb->expr()->in('acpw.socialAction', ':actionType'); - - if ($where instanceof Andx) { - $where->add($clause); - } else { - $where = $qb->expr()->andX($clause); - } - - $qb->setParameter('actionType', $data['actionType']); + $qb + ->andWhere($qb->expr()->in('acpw.socialAction', ':actionType')) + ->setParameter('actionType', $data['actionType']); } if (count($data['goal']) > 0) { @@ -71,11 +63,9 @@ class SocialWorkTypeFilter implements FilterInterface $qb->join('acpw.goals', 'goal'); } - $where->add( - $qb->expr()->in('goal.id', ':goals') - ); - - $qb->setParameter('goals', $data['goal']); + $qb + ->andWhere($qb->expr()->in('goal.id', ':goals')) + ->setParameter('goals', $data['goal']); } if (count($data['result']) > 0) { @@ -83,14 +73,10 @@ class SocialWorkTypeFilter implements FilterInterface $qb->join('acpw.results', 'result'); } - $where->add( - $qb->expr()->in('result.id', ':results') - ); - - $qb->setParameter('results', $data['result']); + $qb + ->andWhere($qb->expr()->in('result.id', ':results')) + ->setParameter('results', $data['result']); } - - $qb->add('where', $where); } public function applyOn(): string From d893e3a664503116ad12db38b93ef626434891b0 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 13 Mar 2023 15:40:51 +0100 Subject: [PATCH 2/2] Fixed: [export] query in goal and results filter https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/700 --- .../SocialWorkTypeFilter.php | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php index ba4eaf6b8..a59220d74 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/SocialWorkTypeFilter.php @@ -19,7 +19,6 @@ use Chill\PersonBundle\Entity\SocialWork\SocialAction; use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Templating\Entity\SocialActionRender; use Doctrine\ORM\EntityManagerInterface; -use Doctrine\ORM\Query\Expr\Andx; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\CallbackTransformer; use Symfony\Component\Form\Extension\Core\Type\HiddenType; @@ -59,23 +58,31 @@ class SocialWorkTypeFilter implements FilterInterface } if (count($data['goal']) > 0) { - if (!in_array('goal', $qb->getAllAliases(), true)) { - $qb->join('acpw.goals', 'goal'); + if (!in_array('acpw_goal', $qb->getAllAliases(), true)) { + $qb->join('acpw.goals', 'acpw_goal'); } - $qb - ->andWhere($qb->expr()->in('goal.id', ':goals')) - ->setParameter('goals', $data['goal']); - } + $orX = $qb->expr()->orX(); + foreach ($data['goal'] as $goal) { - if (count($data['result']) > 0) { - if (!in_array('result', $qb->getAllAliases(), true)) { - $qb->join('acpw.results', 'result'); + /** @var Goal $goal */ + $andX = $qb->expr()->andX(); + $andX->add($qb->expr()->eq('acpw_goal.goal', $goalId = ':goal_'.uniqid())); + $qb->setParameter($goalId, $goal); + + if (count($data['result']) > 0) { + $orXResult = $qb->expr()->orX(); + foreach ($data['result'] as $result) { + + /** @var Result $result */ + $orXResult->add($qb->expr()->isMemberOf($resultId = ':result_'.uniqid(), 'acpw_goal.results')); + $qb->setParameter($resultId, $result); + } + $andX->add($orXResult); + } + $orX->add($andX); } - - $qb - ->andWhere($qb->expr()->in('result.id', ':results')) - ->setParameter('results', $data['result']); + $qb->andWhere($orX); } }