From cf9b9b3c75ea6c4800a203834f4d0cca04c15082 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 21 Sep 2022 17:28:36 +0200 Subject: [PATCH] [person][export] Fixed: use left join for related entities in accompanying course aggregators --- CHANGELOG.md | 1 + .../AdministrativeLocationAggregator.php | 15 +++++-------- .../ClosingMotiveAggregator.php | 22 +++++++------------ .../ConfidentialAggregator.php | 9 +------- .../DurationAggregator.php | 11 ++-------- .../EmergencyAggregator.php | 9 +------- .../EvaluationAggregator.php | 17 ++++++-------- .../IntensityAggregator.php | 9 +------- .../JobAggregator.php | 15 +++++-------- .../OriginAggregator.php | 15 +++++-------- .../ReferrerAggregator.php | 15 +++++-------- .../RequestorAggregator.php | 10 +-------- .../ScopeAggregator.php | 15 +++++-------- .../SocialActionAggregator.php | 16 ++++++-------- .../SocialIssueAggregator.php | 12 +++------- .../StepAggregator.php | 11 +++------- .../EvaluationTypeAggregator.php | 17 ++++++-------- .../ActionTypeAggregator.php | 13 +++++------ .../SocialWorkAggregators/GoalAggregator.php | 21 ++++++++---------- .../SocialWorkAggregators/JobAggregator.php | 17 ++++++-------- .../ReferrerAggregator.php | 15 +++++-------- .../ResultAggregator.php | 17 ++++++-------- .../SocialWorkAggregators/ScopeAggregator.php | 15 +++++-------- .../Export/Export/CountEvaluation.php | 2 +- 24 files changed, 113 insertions(+), 206 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fa9e2bb0..df4dab422 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to * [activity][export] Feature: improve label for aliases in "Filter by activity type" * [activity][export] DX/Feature: use of an `ActivityTypeRepositoryInterface` instead of the old-style EntityRepository * [person][export] Fixed: some inconsistency with date filter on accompanying courses +* [person][export] Fixed: use left join for related entities in accompanying course aggregators ## Test releases diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/AdministrativeLocationAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/AdministrativeLocationAggregator.php index 13185c2a2..c0d20e7c7 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/AdministrativeLocationAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/AdministrativeLocationAggregator.php @@ -40,18 +40,11 @@ class AdministrativeLocationAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { if (!in_array('acploc', $qb->getAllAliases(), true)) { - $qb->join('acp.administrativeLocation', 'acploc'); + $qb->leftJoin('acp.administrativeLocation', 'acploc'); } $qb->addSelect('IDENTITY(acp.administrativeLocation) AS location_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('location_aggregator'); - } else { - $qb->groupBy('location_aggregator'); - } + $qb->addGroupBy('location_aggregator'); } public function applyOn(): string @@ -71,6 +64,10 @@ class AdministrativeLocationAggregator implements AggregatorInterface return 'Administrative location'; } + if (null === $value) { + return ''; + } + $l = $this->locationRepository->find($value); return $l->getName() . ' (' . $this->translatableStringHelper->localize($l->getLocationType()->getTitle()) . ')'; diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ClosingMotiveAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ClosingMotiveAggregator.php index 033ba4365..f9923c554 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ClosingMotiveAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ClosingMotiveAggregator.php @@ -15,6 +15,7 @@ use Chill\MainBundle\Export\AggregatorInterface; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive; use Chill\PersonBundle\Export\Declarations; +use Chill\PersonBundle\Repository\AccompanyingPeriod\ClosingMotiveRepository; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -26,10 +27,10 @@ class ClosingMotiveAggregator implements AggregatorInterface private TranslatableStringHelper $translatableStringHelper; public function __construct( - EntityManagerInterface $em, + ClosingMotiveRepository $motiveRepository, TranslatableStringHelper $translatableStringHelper ) { - $this->motiveRepository = $em->getRepository(ClosingMotive::class); + $this->motiveRepository = $motiveRepository; $this->translatableStringHelper = $translatableStringHelper; } @@ -40,19 +41,8 @@ class ClosingMotiveAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { - if (!in_array('acpmotive', $qb->getAllAliases(), true)) { - $qb->join('acp.closingMotive', 'acpmotive'); - } - $qb->addSelect('IDENTITY(acp.closingMotive) AS closingmotive_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('closingmotive_aggregator'); - } else { - $qb->groupBy('closingmotive_aggregator'); - } + $qb->addGroupBy('closingmotive_aggregator'); } public function applyOn(): string @@ -72,6 +62,10 @@ class ClosingMotiveAggregator implements AggregatorInterface return 'Closing motive'; } + if (NULL === $value) { + return ''; + } + $cm = $this->motiveRepository->find($value); return $this->translatableStringHelper->localize( diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ConfidentialAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ConfidentialAggregator.php index ec9bdd348..a2a4919aa 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ConfidentialAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ConfidentialAggregator.php @@ -35,14 +35,7 @@ class ConfidentialAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { $qb->addSelect('acp.confidential AS confidential_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('confidential_aggregator'); - } else { - $qb->groupBy('confidential_aggregator'); - } + $qb->addGroupBy('confidential_aggregator'); } public function applyOn(): string diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/DurationAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/DurationAggregator.php index b43b0ba11..ee54da2af 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/DurationAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/DurationAggregator.php @@ -44,15 +44,8 @@ final class DurationAggregator implements AggregatorInterface // et ajouter une fonction custom qui calcule plus précisément les intervals, comme doctrineum/date-interval // https://packagist.org/packages/doctrineum/date-interval#3.1.0 (mais composer fait un conflit de dépendance) - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('duration_aggregator'); - } else { - $qb->groupBy('duration_aggregator'); - } - - $qb->orderBy('duration_aggregator'); + $qb->addGroupBy('duration_aggregator'); + $qb->addOrderBy('duration_aggregator'); } public function applyOn(): string diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/EmergencyAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/EmergencyAggregator.php index f59491ec5..297faf049 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/EmergencyAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/EmergencyAggregator.php @@ -35,14 +35,7 @@ class EmergencyAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { $qb->addSelect('acp.emergency AS emergency_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('emergency_aggregator'); - } else { - $qb->groupBy('emergency_aggregator'); - } + $qb->addGroupBy('emergency_aggregator'); } public function applyOn(): string diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/EvaluationAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/EvaluationAggregator.php index 120506aae..292303cea 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/EvaluationAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/EvaluationAggregator.php @@ -41,22 +41,15 @@ final class EvaluationAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { if (!in_array('acpw', $qb->getAllAliases(), true)) { - $qb->join('acp.works', 'acpw'); + $qb->leftJoin('acp.works', 'acpw'); } if (!in_array('workeval', $qb->getAllAliases(), true)) { - $qb->join('acpw.accompanyingPeriodWorkEvaluations', 'workeval'); + $qb->leftJoin('acpw.accompanyingPeriodWorkEvaluations', 'workeval'); } $qb->addSelect('IDENTITY(workeval.evaluation) AS evaluation_aggregator'); - - $groupby = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('evaluation_aggregator'); - } else { - $qb->groupBy('evaluation_aggregator'); - } + $qb->addGroupBy('evaluation_aggregator'); } public function applyOn(): string @@ -76,6 +69,10 @@ final class EvaluationAggregator implements AggregatorInterface return 'Evaluation'; } + if (null === $value) { + return ''; + } + $e = $this->evaluationRepository->find($value); return $this->translatableStringHelper->localize( diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/IntensityAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/IntensityAggregator.php index 711f7ec0d..c418ea39f 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/IntensityAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/IntensityAggregator.php @@ -35,14 +35,7 @@ class IntensityAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { $qb->addSelect('acp.intensity AS intensity_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('intensity_aggregator'); - } else { - $qb->groupBy('intensity_aggregator'); - } + $qb->addGroupBy('intensity_aggregator'); } public function applyOn(): string diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobAggregator.php index 7634ea37f..0809f7654 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobAggregator.php @@ -40,18 +40,11 @@ final class JobAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { if (!in_array('acpjob', $qb->getAllAliases(), true)) { - $qb->join('acp.job', 'acpjob'); + $qb->leftJoin('acp.job', 'acpjob'); } $qb->addSelect('IDENTITY(acp.job) AS job_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('job_aggregator'); - } else { - $qb->groupBy('job_aggregator'); - } + $qb->addGroupBy('job_aggregator'); } public function applyOn(): string @@ -71,6 +64,10 @@ final class JobAggregator implements AggregatorInterface return 'Job'; } + if (null === $value) { + return ''; + } + $j = $this->jobRepository->find($value); return $this->translatableStringHelper->localize( diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/OriginAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/OriginAggregator.php index 925160a2d..c7a178fa3 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/OriginAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/OriginAggregator.php @@ -42,18 +42,11 @@ final class OriginAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { if (!in_array('acporigin', $qb->getAllAliases(), true)) { - $qb->join('acp.origin', 'acporigin'); + $qb->leftJoin('acp.origin', 'acporigin'); } $qb->addSelect('acporigin.id AS origin_aggregator'); - - $groupby = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('origin_aggregator'); - } else { - $qb->groupBy('origin_aggregator'); - } + $qb->addGroupBy('origin_aggregator'); } public function applyOn(): string @@ -73,6 +66,10 @@ final class OriginAggregator implements AggregatorInterface return 'Origin'; } + if (null === $value) { + return ''; + } + $o = $this->repository->find($value); return $this->translatableStringHelper->localize( diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerAggregator.php index 22eca6f76..7851fe203 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerAggregator.php @@ -40,18 +40,11 @@ final class ReferrerAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { if (!in_array('acpuser', $qb->getAllAliases(), true)) { - $qb->join('acp.user', 'acpuser'); + $qb->leftJoin('acp.user', 'acpuser'); } $qb->addSelect('acpuser.id AS referrer_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('referrer_aggregator'); - } else { - $qb->groupBy('referrer_aggregator'); - } + $qb->addGroupBy('referrer_aggregator'); } public function applyOn(): string @@ -71,6 +64,10 @@ final class ReferrerAggregator implements AggregatorInterface return 'Referrer'; } + if (null === $value) { + return ''; + } + $r = $this->userRepository->find($value); return $this->userRender->renderString($r, []); diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/RequestorAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/RequestorAggregator.php index 80195bdcc..2f716c92a 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/RequestorAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/RequestorAggregator.php @@ -57,15 +57,7 @@ final class RequestorAggregator implements AggregatorInterface END ) AS requestor_aggregator "); - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('requestor_aggregator'); - } else { - $qb->groupBy('requestor_aggregator'); - } - - // TODO 'order by' does not works ! + $qb->addGroupBy('requestor_aggregator'); } public function applyOn(): string diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ScopeAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ScopeAggregator.php index 5b2901921..0ff6aa747 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ScopeAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ScopeAggregator.php @@ -40,18 +40,11 @@ final class ScopeAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { if (!in_array('acpscope', $qb->getAllAliases(), true)) { - $qb->join('acp.scopes', 'acpscope'); + $qb->leftJoin('acp.scopes', 'acpscope'); } $qb->addSelect('acpscope.id as scope_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('scope_aggregator'); - } else { - $qb->groupBy('scope_aggregator'); - } + $qb->addGroupBy('scope_aggregator'); } public function applyOn(): string @@ -71,6 +64,10 @@ final class ScopeAggregator implements AggregatorInterface return 'Scope'; } + if (null === $value) { + return ''; + } + $s = $this->scopeRepository->find($value); return $this->translatableStringHelper->localize( diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/SocialActionAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/SocialActionAggregator.php index 39ad085e3..dc8d2cfb3 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/SocialActionAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/SocialActionAggregator.php @@ -41,18 +41,12 @@ final class SocialActionAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { if (!in_array('acpw', $qb->getAllAliases(), true)) { + // here, we will only see accompanying period linked with a socialAction $qb->join('acp.works', 'acpw'); } - $qb->addSelect('IDENTITY(acpw.socialAction) AS socialaction_aggregator'); // DISTINCT ?? - - $groupby = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('socialaction_aggregator'); - } else { - $qb->groupBy('socialaction_aggregator'); - } + $qb->addSelect('IDENTITY(acpw.socialAction) AS socialaction_aggregator'); + $qb->addGroupBy('socialaction_aggregator'); } public function applyOn(): string @@ -72,6 +66,10 @@ final class SocialActionAggregator implements AggregatorInterface return 'Social action'; } + if (null === $value) { + return ''; + } + $sa = $this->actionRepository->find($value); return $this->actionRender->renderString($sa, []); diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/SocialIssueAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/SocialIssueAggregator.php index ac5ac94c0..98fdbad0c 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/SocialIssueAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/SocialIssueAggregator.php @@ -40,18 +40,12 @@ final class SocialIssueAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { if (!in_array('acpsocialissue', $qb->getAllAliases(), true)) { + // we will see accompanying period linked with social issues $qb->join('acp.socialIssues', 'acpsocialissue'); } - + $qb->addSelect('acpsocialissue.id as socialissue_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('socialissue_aggregator'); - } else { - $qb->groupBy('socialissue_aggregator'); - } + $qb->addGroupBy('socialissue_aggregator'); } public function applyOn(): string diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/StepAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/StepAggregator.php index 5c923fdc2..2a1a3db25 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/StepAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/StepAggregator.php @@ -41,15 +41,9 @@ final class StepAggregator implements AggregatorInterface //, FilterInterface public function alterQuery(QueryBuilder $qb, $data) { $qb->addSelect('acp.step AS step_aggregator'); + $qb->addGroupBy('step_aggregator'); - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('step_aggregator'); - } else { - $qb->groupBy('step_aggregator'); - } - + /* // add date in where clause $where = $qb->getDQLPart('where'); @@ -69,6 +63,7 @@ final class StepAggregator implements AggregatorInterface //, FilterInterface $qb->add('where', $where); $qb->setParameter('ondate', $data['on_date'], Types::DATE_MUTABLE); + */ } public function applyOn(): string diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/EvaluationAggregators/EvaluationTypeAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/EvaluationAggregators/EvaluationTypeAggregator.php index bf0f48ab4..29420d5c9 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/EvaluationAggregators/EvaluationTypeAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/EvaluationAggregators/EvaluationTypeAggregator.php @@ -39,15 +39,8 @@ class EvaluationTypeAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { - $qb->addSelect('IDENTITY(workeval.evaluation) AS evaluationtype_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('evaluationtype_aggregator'); - } else { - $qb->groupBy('evaluationtype_aggregator'); - } + $qb->addSelect('IDENTITY(workeval.evaluation) AS eval_evaluationtype_aggregator'); + $qb->addGroupBy('eval_evaluationtype_aggregator'); } public function applyOn(): string @@ -67,6 +60,10 @@ class EvaluationTypeAggregator implements AggregatorInterface return 'Evaluation type'; } + if (null === $value) { + return ''; + } + $ev = $this->evaluationRepository->find($value); return $this->translatableStringHelper->localize($ev->getTitle()); @@ -75,7 +72,7 @@ class EvaluationTypeAggregator implements AggregatorInterface public function getQueryKeys($data): array { - return ['evaluationtype_aggregator']; + return ['eval_evaluationtype_aggregator']; } public function getTitle(): string diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ActionTypeAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ActionTypeAggregator.php index fb64b3e01..37d50bf51 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ActionTypeAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ActionTypeAggregator.php @@ -44,14 +44,7 @@ final class ActionTypeAggregator implements AggregatorInterface } $qb->addSelect('acpwsocialaction.id as action_type_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('action_type_aggregator'); - } else { - $qb->groupBy('action_type_aggregator'); - } + $qb->addGroupBy('action_type_aggregator'); } public function applyOn() @@ -71,6 +64,10 @@ final class ActionTypeAggregator implements AggregatorInterface return 'Social Action Type'; } + if (null === $value) { + return ''; + } + $sa = $this->socialActionRepository->find($value); return $this->actionRender->renderString($sa, []); diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalAggregator.php index bc534c678..0f418a678 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalAggregator.php @@ -38,18 +38,11 @@ final class GoalAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { if (!in_array('goal', $qb->getAllAliases(), true)) { - $qb->join('acpw.goals', 'goal'); + $qb->leftJoin('acpw.goals', 'goal'); } - $qb->addSelect('IDENTITY(goal.goal) as goal_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('goal_aggregator'); - } else { - $qb->groupBy('goal_aggregator'); - } + $qb->addSelect('IDENTITY(goal.goal) as acpw_goal_aggregator'); + $qb->addGroupBy('acpw_goal_aggregator'); } public function applyOn(): string @@ -69,8 +62,12 @@ final class GoalAggregator implements AggregatorInterface return 'Goal Type'; } + if (null === $value) { + return ''; + } + $g = $this->goalRepository->find($value); - + return $this->translatableStringHelper->localize( $g->getTitle() ); @@ -79,7 +76,7 @@ final class GoalAggregator implements AggregatorInterface public function getQueryKeys($data): array { - return ['goal_aggregator']; + return ['acpw_goal_aggregator']; } public function getTitle(): string diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/JobAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/JobAggregator.php index 4d27aa873..ca2e36d97 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/JobAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/JobAggregator.php @@ -40,18 +40,11 @@ final class JobAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { if (!in_array('acpwuser', $qb->getAllAliases(), true)) { - $qb->join('acpw.referrers', 'acpwuser'); + $qb->leftJoin('acpw.referrers', 'acpwuser'); } - $qb->addSelect('IDENTITY(acpwuser.userJob) as job_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('job_aggregator'); - } else { - $qb->groupBy('job_aggregator'); - } + $qb->addSelect('IDENTITY(acpwuser.userJob) as job_aggregator') + ->addGroupBy('job_aggregator'); } public function applyOn(): string @@ -71,6 +64,10 @@ final class JobAggregator implements AggregatorInterface return 'Job'; } + if (null === $value) { + return ''; + } + $j = $this->jobRepository->find($value); return $this->translatableStringHelper->localize( diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ReferrerAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ReferrerAggregator.php index 35e1e218d..46ef78035 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ReferrerAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ReferrerAggregator.php @@ -40,18 +40,11 @@ final class ReferrerAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { if (!in_array('acpwuser', $qb->getAllAliases(), true)) { - $qb->join('acpw.referrers', 'acpwuser'); + $qb->leftJoin('acpw.referrers', 'acpwuser'); } $qb->addSelect('acpwuser.id AS referrer_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('referrer_aggregator'); - } else { - $qb->groupBy('referrer_aggregator'); - } + $qb->addGroupBy('referrer_aggregator'); } public function applyOn(): string @@ -71,6 +64,10 @@ final class ReferrerAggregator implements AggregatorInterface return 'Referrer'; } + if (null === $value) { + return ''; + } + $r = $this->userRepository->find($value); return $this->userRender->renderString($r, []); diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php index 8f7ac0624..054b0ab55 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php @@ -41,15 +41,8 @@ final class ResultAggregator implements AggregatorInterface $qb->join('acpw.results', 'result'); } - $qb->addSelect('result.id as result_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('result_aggregator'); - } else { - $qb->groupBy('result_aggregator'); - } + $qb->addSelect('result.id AS acpw_result_aggregator'); + $qb->addGroupBy('acpw_result_aggregator'); } public function applyOn(): string @@ -69,6 +62,10 @@ final class ResultAggregator implements AggregatorInterface return 'Result Type'; } + if (null === $value) { + return ''; + } + $r = $this->resultRepository->find($value); return $this->translatableStringHelper->localize( @@ -79,7 +76,7 @@ final class ResultAggregator implements AggregatorInterface public function getQueryKeys($data): array { - return ['result_aggregator']; + return ['acpw_result_aggregator']; } public function getTitle(): string diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ScopeAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ScopeAggregator.php index ee479d503..1cf29d46f 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ScopeAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ScopeAggregator.php @@ -40,18 +40,11 @@ final class ScopeAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { if (!in_array('acpwuser', $qb->getAllAliases(), true)) { - $qb->join('acpw.referrers', 'acpwuser'); + $qb->leftJoin('acpw.referrers', 'acpwuser'); } $qb->addSelect('IDENTITY(acpwuser.mainScope) as scope_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('scope_aggregator'); - } else { - $qb->groupBy('scope_aggregator'); - } + $qb->addGroupBy('scope_aggregator'); } public function applyOn(): string @@ -71,6 +64,10 @@ final class ScopeAggregator implements AggregatorInterface return 'Scope'; } + if (null === $value) { + return ''; + } + $s = $this->scopeRepository->find($value); return $this->translatableStringHelper->localize( diff --git a/src/Bundle/ChillPersonBundle/Export/Export/CountEvaluation.php b/src/Bundle/ChillPersonBundle/Export/Export/CountEvaluation.php index 7178a54c8..634b351cf 100644 --- a/src/Bundle/ChillPersonBundle/Export/Export/CountEvaluation.php +++ b/src/Bundle/ChillPersonBundle/Export/Export/CountEvaluation.php @@ -98,7 +98,7 @@ class CountEvaluation implements ExportInterface, GroupedExportInterface $qb->join('acpw.accompanyingPeriodWorkEvaluations', 'workeval'); } - $qb->select('COUNT(workeval.id) AS export_result'); + $qb->select('COUNT(DISTINCT workeval.id) AS export_result'); return $qb; }