From 6e467a62d4949302b179490351f4ed059997b1a1 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 11 Aug 2022 11:58:54 +0200 Subject: [PATCH] exports: simplify with querybuilder method to getRootAlias --- .../Export/Aggregator/JobAggregator.php | 10 +--------- .../Export/Aggregator/ReferrerAggregator.php | 10 +--------- .../Export/Aggregator/ScopeAggregator.php | 10 +--------- .../Export/Filter/ReferrerFilter.php | 13 ++----------- 4 files changed, 5 insertions(+), 38 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/JobAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/JobAggregator.php index 9793dd875..d2334cfd1 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/JobAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/JobAggregator.php @@ -80,7 +80,7 @@ final class JobAggregator implements AggregatorInterface */ public function alterQuery(QueryBuilder $qb, $data) { - switch ($this->getBaseEntityAppliedOn($qb)) { + switch ($qb->getRootAlias()) { case 'acp': $qb->join('acp.job', 'j'); @@ -112,12 +112,4 @@ final class JobAggregator implements AggregatorInterface { return Declarations::ACP_SHARED; } - - private function getBaseEntityAppliedOn(QueryBuilder $qb): string - { - /** @var From $from */ - $from = $qb->getDQLPart('from'); - - return $from[0]->getAlias(); - } } \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/ReferrerAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/ReferrerAggregator.php index 3f9344212..bcf1e2f6c 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/ReferrerAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/ReferrerAggregator.php @@ -40,7 +40,7 @@ final class ReferrerAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { - switch ($this->getBaseEntityAppliedOn($qb)) { + switch ($qb->getRootAlias()) { case 'acp': $qb->join('acp.user', 'u'); @@ -98,12 +98,4 @@ final class ReferrerAggregator implements AggregatorInterface { return 'Group by referrers'; } - - private function getBaseEntityAppliedOn(QueryBuilder $qb): string - { - /** @var From $from */ - $from = $qb->getDQLPart('from'); - - return $from[0]->getAlias(); - } } diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/ScopeAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/ScopeAggregator.php index d6d6d5a58..968d3115a 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/ScopeAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/ScopeAggregator.php @@ -80,7 +80,7 @@ final class ScopeAggregator implements AggregatorInterface */ public function alterQuery(QueryBuilder $qb, $data) { - switch ($this->getBaseEntityAppliedOn($qb)) { + switch ($qb->getRootAlias()) { case 'acp': $qb->join('acp.scopes', 's'); @@ -112,12 +112,4 @@ final class ScopeAggregator implements AggregatorInterface { return Declarations::ACP_SHARED; } - - private function getBaseEntityAppliedOn(QueryBuilder $qb): string - { - /** @var From $from */ - $from = $qb->getDQLPart('from'); - - return $from[0]->getAlias(); - } } \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php index 5aac709c4..7d2a3dbb9 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php @@ -75,11 +75,10 @@ class ReferrerFilter implements FilterInterface */ public function alterQuery(QueryBuilder $qb, $data) { - $where = $qb->getDQLPart('where'); - // Use querybuilder from alias to find which export context (indicator) - switch ($this->getBaseEntityAppliedOn($qb)) { + switch ($qb->getRootAlias()) { + case 'acp': $clause = $qb->expr()->in('acp.user', ':referrers'); break; @@ -103,14 +102,6 @@ class ReferrerFilter implements FilterInterface $qb->setParameter('referrers', $data['accepted_referrers']); } - private function getBaseEntityAppliedOn(QueryBuilder $qb): string - { - /** @var From $from */ - $from = $qb->getDQLPart('from'); - - return $from[0]->getAlias(); - } - /** * @inheritDoc */