diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index ee6c308e0..1e95e32d0 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -249,8 +249,8 @@ Country code: Code du pays # circles / scopes Choose the circle: Choisir le cercle -Scope: Service -Scopes: Services +Scope: Cercle +Scopes: Cercles #export diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/JobAggregator.php similarity index 64% rename from src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregator.php rename to src/Bundle/ChillPersonBundle/Export/Aggregator/JobAggregator.php index 843464fb6..9793dd875 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/UserJobAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/JobAggregator.php @@ -1,15 +1,16 @@ join('acp.job', 'j'); - $qb->addSelect('IDENTITY(acp.job) AS userjob_aggregator'); + switch ($this->getBaseEntityAppliedOn($qb)) { + + 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"); + } $groupBy = $qb->getDQLPart('groupBy'); if (!empty($groupBy)) { - $qb->addGroupBy('userjob_aggregator'); + $qb->addGroupBy('job_aggregator'); } else { - $qb->groupBy('userjob_aggregator'); + $qb->groupBy('job_aggregator'); } } @@ -96,6 +110,14 @@ final class UserJobAggregator implements AggregatorInterface */ public function applyOn(): string { - return Declarations::ACP_TYPE; + 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/AccompanyingCourseAggregators/UserScopeAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/ScopeAggregator.php similarity index 60% rename from src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/UserScopeAggregator.php rename to src/Bundle/ChillPersonBundle/Export/Aggregator/ScopeAggregator.php index 3fef5b4a9..d6d6d5a58 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/UserScopeAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/ScopeAggregator.php @@ -1,15 +1,16 @@ scopeRepository->find($value); - return $this->translatableStringHelper->localize($s->getName()); + return $this->translatableStringHelper->localize( + $s->getName() + ); }; } @@ -45,7 +48,7 @@ final class UserScopeAggregator implements AggregatorInterface */ public function getQueryKeys($data): array { - return ['userscope_aggregator']; + return ['scope_aggregator']; } /** @@ -77,15 +80,28 @@ final class UserScopeAggregator implements AggregatorInterface */ public function alterQuery(QueryBuilder $qb, $data) { - $qb->join('acp.scopes', 's'); - $qb->addSelect('s.id as userscope_aggregator'); + switch ($this->getBaseEntityAppliedOn($qb)) { + + 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"); + } $groupBy = $qb->getDQLPart('groupBy'); if (!empty($groupBy)) { - $qb->addGroupBy('userscope_aggregator'); + $qb->addGroupBy('scope_aggregator'); } else { - $qb->groupBy('userscope_aggregator'); + $qb->groupBy('scope_aggregator'); } } @@ -94,6 +110,14 @@ final class UserScopeAggregator implements AggregatorInterface */ public function applyOn(): string { - return Declarations::ACP_TYPE; + 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/SocialWorkAggregators/JobAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/JobAggregator.php deleted file mode 100644 index 2177d4554..000000000 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/JobAggregator.php +++ /dev/null @@ -1,86 +0,0 @@ -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 job_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('job_aggregator'); - } else { - $qb->groupBy('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 ['job_aggregator']; - } - - public function getTitle() - { - return 'Group social work actions by referrer job'; - } -} diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ScopeAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ScopeAggregator.php deleted file mode 100644 index aec969585..000000000 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ScopeAggregator.php +++ /dev/null @@ -1,86 +0,0 @@ -scopeRepository = $scopeRepository; - $this->translatableStringHelper = $translatableStringHelper; - } - - public function addRole() - { - return null; - } - - public function alterQuery(QueryBuilder $qb, $data) - { - $qb->join('acpw.referrers', 'r'); - $qb->addSelect('IDENTITY(r.mainScope) as scope_aggregator'); - - $groupBy = $qb->getDQLPart('groupBy'); - - if (!empty($groupBy)) { - $qb->addGroupBy('scope_aggregator'); - } else { - $qb->groupBy('scope_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 scope'; - } - - $s = $this->scopeRepository->find($value); - - return $this->translatableStringHelper->localize( - $s->getName()); - }; - } - - public function getQueryKeys($data) - { - return ['scope_aggregator']; - } - - public function getTitle() - { - return 'Group social work actions by referrer scope'; - } -} diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php index bac2656c6..5aac709c4 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php @@ -78,10 +78,8 @@ class ReferrerFilter implements FilterInterface $where = $qb->getDQLPart('where'); - $from_alias = $this->getEntityFromQB($qb); - // Use querybuilder from alias to find which export context (indicator) - switch ($from_alias) { + switch ($this->getBaseEntityAppliedOn($qb)) { case 'acp': $clause = $qb->expr()->in('acp.user', ':referrers'); break; @@ -92,7 +90,7 @@ class ReferrerFilter implements FilterInterface break; default: - throw new \Exception("Referrer filter doesn't apply on that entity"); + throw new \Exception("Does not apply on that base entity"); } if ($where instanceof Andx) { @@ -105,7 +103,7 @@ class ReferrerFilter implements FilterInterface $qb->setParameter('referrers', $data['accepted_referrers']); } - private function getEntityFromQB(QueryBuilder $qb): string + private function getBaseEntityAppliedOn(QueryBuilder $qb): string { /** @var From $from */ $from = $qb->getDQLPart('from'); diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml index 236c7fe96..726c84599 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_userscope: - class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\UserScopeAggregator + chill.person.export.aggregator_scope: + class: Chill\PersonBundle\Export\Aggregator\ScopeAggregator autowire: true autoconfigure: true tags: - - { name: chill.export_aggregator, alias: accompanyingcourse_userscope_aggregator } + - { name: chill.export_aggregator, alias: accompanyingcourse_scope_aggregator } - chill.person.export.aggregator_userjob: - class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\UserJobAggregator + chill.person.export.aggregator_job: + class: Chill\PersonBundle\Export\Aggregator\JobAggregator autowire: true autoconfigure: true tags: - - { name: chill.export_aggregator, alias: accompanyingcourse_userjob_aggregator } + - { name: chill.export_aggregator, alias: accompanyingcourse_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 1d4023b4d..b655afaa6 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml @@ -37,20 +37,6 @@ services: autoconfigure: true tags: - { name: chill.export_aggregator, alias: social_work_actions_referrer_aggregator } - - chill.person.export.aggregator_job: - class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\JobAggregator - autowire: true - autoconfigure: true - tags: - - { name: chill.export_aggregator, alias: social_work_actions_job_aggregator } - - chill.person.export.aggregator_scope: - class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\ScopeAggregator - autowire: true - autoconfigure: true - tags: - - { name: chill.export_aggregator, alias: social_work_actions_scope_aggregator } chill.person.export.aggregator_action_type: class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\ActionTypeAggregator