From d27c52b526509310b6765727100b3deb323157c9 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Thu, 11 Aug 2022 17:10:19 +0200 Subject: [PATCH] Split Job and Scope Aggregators --- .../JobAggregator.php | 103 ++++++++++++++++++ .../ScopeAggregator.php | 20 +--- .../JobAggregator.php | 20 +--- .../SocialWorkAggregators/ScopeAggregator.php | 103 ++++++++++++++++++ .../services/exports_accompanying_course.yaml | 12 +- .../services/exports_social_actions.yaml | 22 +++- 6 files changed, 238 insertions(+), 42 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobAggregator.php rename src/Bundle/ChillPersonBundle/Export/Aggregator/{ => AccompanyingCourseAggregators}/ScopeAggregator.php (78%) rename src/Bundle/ChillPersonBundle/Export/Aggregator/{ => SocialWorkAggregators}/JobAggregator.php (78%) create mode 100644 src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ScopeAggregator.php diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobAggregator.php new file mode 100644 index 000000000..31b3fca66 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/JobAggregator.php @@ -0,0 +1,103 @@ +jobRepository = $jobRepository; + $this->translatableStringHelper = $translatableStringHelper; + } + + /** + * @inheritDoc + */ + public function getLabels($key, array $values, $data) + { + return function($value): string { + if ($value === '_header') { + return 'Job'; + } + + $j = $this->jobRepository->find($value); + + return $this->translatableStringHelper->localize( + $j->getLabel() + ); + }; + } + + /** + * @inheritDoc + */ + public function getQueryKeys($data): array + { + return ['job_aggregator']; + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Group by user job'; + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->join('acp.job', 'j'); + + $qb->addSelect('IDENTITY(acp.job) AS job_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('job_aggregator'); + } else { + $qb->groupBy('job_aggregator'); + } + } + + /** + * @inheritDoc + */ + public function applyOn(): string + { + return Declarations::ACP_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/ScopeAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ScopeAggregator.php similarity index 78% rename from src/Bundle/ChillPersonBundle/Export/Aggregator/ScopeAggregator.php rename to src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ScopeAggregator.php index 968d3115a..5bddac42b 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/ScopeAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ScopeAggregator.php @@ -1,6 +1,6 @@ getRootAlias()) { + $qb->join('acp.scopes', 's'); - case 'acp': - $qb->join('acp.scopes', 's'); - $qb->addSelect('s.id as scope_aggregator'); - break; - - case 'acpw': - $qb->join('acpw.referrers', 'r'); - $qb->addSelect('IDENTITY(r.mainScope) as scope_aggregator'); - break; - - default: - throw new \Exception("Does not apply on that base entity"); - } + $qb->addSelect('s.id as scope_aggregator'); $groupBy = $qb->getDQLPart('groupBy'); @@ -110,6 +98,6 @@ final class ScopeAggregator implements AggregatorInterface */ public function applyOn(): string { - return Declarations::ACP_SHARED; + return Declarations::ACP_TYPE; } } \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/JobAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/JobAggregator.php similarity index 78% rename from src/Bundle/ChillPersonBundle/Export/Aggregator/JobAggregator.php rename to src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/JobAggregator.php index d2334cfd1..c8aa368b1 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/JobAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/JobAggregator.php @@ -1,6 +1,6 @@ getRootAlias()) { + $qb->join('acpw.referrers', 'u'); - case 'acp': - $qb->join('acp.job', 'j'); - $qb->addSelect('IDENTITY(acp.job) AS job_aggregator'); - break; - - case 'acpw': - $qb->join('acpw.referrers', 'r'); - $qb->addSelect('IDENTITY(r.userJob) as job_aggregator'); - break; - - default: - throw new \Exception("Does not apply on that base entity"); - } + $qb->addSelect('IDENTITY(u.userJob) as job_aggregator'); $groupBy = $qb->getDQLPart('groupBy'); @@ -110,6 +98,6 @@ final class JobAggregator implements AggregatorInterface */ public function applyOn(): string { - return Declarations::ACP_SHARED; + return Declarations::SOCIAL_WORK_ACTION_TYPE; } } \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ScopeAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ScopeAggregator.php new file mode 100644 index 000000000..ca968f20e --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ScopeAggregator.php @@ -0,0 +1,103 @@ +scopeRepository = $scopeRepository; + $this->translatableStringHelper = $translatableStringHelper; + } + + /** + * @inheritDoc + */ + public function getLabels($key, array $values, $data) + { + return function ($value): string { + if ($value === '_header') { + return 'Scope'; + } + + $s = $this->scopeRepository->find($value); + + return $this->translatableStringHelper->localize( + $s->getName() + ); + }; + } + + /** + * @inheritDoc + */ + public function getQueryKeys($data): array + { + return ['scope_aggregator']; + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Group by user scope'; + } + + /** + * @inheritDoc + */ + public function addRole() + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->join('acpw.referrers', 'u'); + + $qb->addSelect('IDENTITY(u.mainScope) as scope_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('scope_aggregator'); + } else { + $qb->groupBy('scope_aggregator'); + } + } + + /** + * @inheritDoc + */ + public function applyOn(): string + { + return Declarations::SOCIAL_WORK_ACTION_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml index 25b19caf8..155ad11df 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml @@ -150,19 +150,19 @@ services: - { name: chill.export_filter, alias: accompanyingcourse_openbetweendates_filter } ## Aggregators - chill.person.export.aggregator_scope: - class: Chill\PersonBundle\Export\Aggregator\ScopeAggregator + chill.person.export.aggregator_referrer_scope: + class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\ScopeAggregator autowire: true autoconfigure: true tags: - - { name: chill.export_aggregator, alias: accompanyingcourse_scope_aggregator } + - { name: chill.export_aggregator, alias: accompanyingcourse_referrer_scope_aggregator } - chill.person.export.aggregator_job: - class: Chill\PersonBundle\Export\Aggregator\JobAggregator + chill.person.export.aggregator_referrer_job: + class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\JobAggregator autowire: true autoconfigure: true tags: - - { name: chill.export_aggregator, alias: accompanyingcourse_job_aggregator } + - { name: chill.export_aggregator, alias: accompanyingcourse_referrer_job_aggregator } chill.person.export.aggregator_socialissue: class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\SocialIssueAggregator diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml index 9879736db..ef86732ff 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml @@ -30,12 +30,12 @@ services: tags: - { name: chill.export_filter, alias: social_work_actions_job_filter } - chill.person.export.filter_treating_agent: + chill.person.export.filter_treatingagent: class: Chill\PersonBundle\Export\Filter\SocialWorkFilters\ReferrerFilter autowire: true autoconfigure: true tags: - - { name: chill.export_filter, alias: social_work_actions_treating_agent_filter } + - { name: chill.export_filter, alias: social_work_actions_treatingagent_filter } ## AGGREGATORS chill.person.export.aggregator_action_type: @@ -45,12 +45,26 @@ services: tags: - { name: chill.export_aggregator, alias: social_work_actions_action_type_aggregator } - chill.person.export.aggregator_treating_agent: + chill.person.export.aggregator_treatingagent_scope: + class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\ScopeAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: social_work_actions_treatingagent_scope_aggregator } + + chill.person.export.aggregator_treatingagent_job: + class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\JobAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: social_work_actions_treatingagent_job_aggregator } + + chill.person.export.aggregator_treatingagent: class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\ReferrerAggregator autowire: true autoconfigure: true tags: - - { name: chill.export_aggregator, alias: social_work_actions_treating_agent_aggregator } + - { name: chill.export_aggregator, alias: social_work_actions_treatingagent_aggregator } chill.person.export.aggregator_goal: class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\GoalAggregator