From 70488a935d9622601cd3c9df7f91cea3acce40b0 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 11 Aug 2022 11:59:35 +0200 Subject: [PATCH] exports: test if a join is already loaded when a specific join has to be shared between combined filters/aggregators, we need to check if it has been already loaded. we cannot load it into indicator because result is wrong --- .../HouseholdAggregators/ChildrenNumberAggregator.php | 4 ++++ .../Aggregator/HouseholdAggregators/CompositionAggregator.php | 4 ++++ src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php | 1 - .../Export/Filter/HouseholdFilters/CompositionFilter.php | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php index c629fe0bf..df50b76f0 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php @@ -76,6 +76,10 @@ class ChildrenNumberAggregator implements AggregatorInterface */ public function alterQuery(QueryBuilder $qb, $data) { + if (!in_array('composition', $qb->getAllAliases())) { + $qb->join('household.compositions', 'composition'); + } + $qb->addSelect('composition.numberOfChildren AS childrennumber_aggregator'); $groupBy = $qb->getDQLPart('groupBy'); diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php index 3e292ceec..2c6ab174f 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php @@ -83,6 +83,10 @@ class CompositionAggregator implements AggregatorInterface */ public function alterQuery(QueryBuilder $qb, $data) { + if (!in_array('composition', $qb->getAllAliases())) { + $qb->join('household.compositions', 'composition'); + } + $qb->addSelect('IDENTITY(composition.householdCompositionType) AS composition_aggregator'); $groupBy = $qb->getDQLPart('groupBy'); diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php b/src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php index c9b2b541a..5bc333e2a 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountHousehold.php @@ -107,7 +107,6 @@ class CountHousehold implements ExportInterface, GroupedExportInterface ->join('acppart.person', 'person') ->join('person.householdParticipations', 'householdmember') ->join('householdmember.household', 'household') - ->join('household.compositions', 'composition') ; $qb->select('COUNT(DISTINCT householdmember.household) AS export_result'); diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/HouseholdFilters/CompositionFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/HouseholdFilters/CompositionFilter.php index f8a36e4b9..78aba8bf7 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/HouseholdFilters/CompositionFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/HouseholdFilters/CompositionFilter.php @@ -85,6 +85,10 @@ class CompositionFilter implements FilterInterface */ public function alterQuery(QueryBuilder $qb, $data) { + if (!in_array('composition', $qb->getAllAliases())) { + $qb->join('household.compositions', 'composition'); + } + $where = $qb->getDQLPart('where'); $clause = $qb->expr()->andX(