diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/ReferrerJobAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/ReferrerJobAggregator.php new file mode 100644 index 000000000..672ede59a --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/ReferrerJobAggregator.php @@ -0,0 +1,86 @@ +userJobRepository = $userJobRepository; + $this->translatableStringHelper = $translatableStringHelper; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->join('acpw.referrers', 'r'); + $qb->addSelect('IDENTITY(r.userJob) as referrer_job_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('referrer_job_aggregator'); + } else { + $qb->groupBy('referrer_job_aggregator'); + } + + } + + public function applyOn() + { + return Declarations::SOCIAL_WORK_ACTION_TYPE; + } + + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + public function getLabels($key, array $values, $data) + { + return function ($value): string { + if ('_header' === $value) { + return 'User job'; + } + + $j = $this->userJobRepository->find($value); + + return $this->translatableStringHelper->localize( + $j->getLabel()); + }; + } + + public function getQueryKeys($data) + { + return ['referrer_job_aggregator']; + } + + public function getTitle() + { + return 'Group social work actions by referrer job'; + } +} diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml index 96e14d99a..5ac5a0afa 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml @@ -43,3 +43,10 @@ services: autoconfigure: true tags: - { name: chill.export_aggregator, alias: social_work_actions_referrer_aggregator } + + chill.person.export.aggregator_referrer_job: + class: Chill\PersonBundle\Export\Aggregator\ReferrerJobAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: social_work_actions_referrer_job_aggregator }