From 4e12684f9807bc0b623eb882de9ba547bd2f5f97 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 11 Aug 2022 18:09:25 +0200 Subject: [PATCH] add condition on join clause to improve combined Filters/Aggregators --- .../EvaluationAggregator.php | 8 ++++---- .../SocialActionAggregator.php | 4 +++- .../AccompanyingCourseFilters/SocialActionFilter.php | 7 ++++--- .../Export/Filter/SocialWorkFilters/JobFilter.php | 4 ++-- .../Export/Filter/SocialWorkFilters/ScopeFilter.php | 4 ++-- 5 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/EvaluationAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/EvaluationAggregator.php index f02368fde..3f98c7003 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/EvaluationAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/EvaluationAggregator.php @@ -78,10 +78,10 @@ final class EvaluationAggregator implements AggregatorInterface */ public function alterQuery(QueryBuilder $qb, $data) { - $qb - ->join('acp.works', 'acpw') - ->join('acpw.accompanyingPeriodWorkEvaluations', 'we') - ; + if (!in_array('acpw', $qb->getAllAliases())) { + $qb->join('acp.works', 'acpw'); + } + $qb->join('acpw.accompanyingPeriodWorkEvaluations', 'we'); $qb->addSelect('IDENTITY(we.evaluation) AS evaluation_aggregator'); diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/SocialActionAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/SocialActionAggregator.php index 4be8c027d..a9257bd8e 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/SocialActionAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/SocialActionAggregator.php @@ -76,7 +76,9 @@ final class SocialActionAggregator implements AggregatorInterface */ public function alterQuery(QueryBuilder $qb, $data) { - $qb->join('acp.works', 'acpw'); + if (!in_array('acpw', $qb->getAllAliases())) { + $qb->join('acp.works', 'acpw'); + } $qb->addSelect('IDENTITY(acpw.socialAction) AS socialaction_aggregator'); // DISTINCT ?? diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php index 3f61b017f..d96d0ca44 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/SocialActionFilter.php @@ -69,9 +69,10 @@ class SocialActionFilter implements FilterInterface public function alterQuery(QueryBuilder $qb, $data) { - $qb->join('acp.works', 'acpw') - ->join('acpw.socialAction', 'sa') - ; + if (!in_array('acpw', $qb->getAllAliases())) { + $qb->join('acp.works', 'acpw'); + } + $qb->join('acpw.socialAction', 'sa'); $where = $qb->getDQLPart('where'); $clause = $qb->expr()->in('sa.id', ':socialactions'); diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/JobFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/JobFilter.php index 0202a9be0..80efd03e3 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/JobFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/JobFilter.php @@ -72,10 +72,10 @@ class JobFilter implements FilterInterface public function alterQuery(QueryBuilder $qb, $data) { - $qb->join('acpw.referrers', 'r'); + $qb->join('acpw.referrers', 'u'); $where = $qb->getDQLPart('where'); - $clause = $qb->expr()->in('r.userJob', ':job'); + $clause = $qb->expr()->in('u.userJob', ':job'); if ($where instanceof Andx) { $where->add($clause); diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/ScopeFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/ScopeFilter.php index 228c3ea92..6588efc18 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/ScopeFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/SocialWorkFilters/ScopeFilter.php @@ -71,10 +71,10 @@ class ScopeFilter implements FilterInterface public function alterQuery(QueryBuilder $qb, $data) { - $qb->join('acpw.referrers', 'r'); + $qb->join('acpw.referrers', 'u'); $where = $qb->getDQLPart('where'); - $clause = $qb->expr()->in('r.mainScope', ':scope'); + $clause = $qb->expr()->in('u.mainScope', ':scope'); if ($where instanceof Andx) { $where->add($clause);