diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/ActionTypeAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/ActionTypeAggregator.php new file mode 100644 index 000000000..df6a9f98f --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/ActionTypeAggregator.php @@ -0,0 +1,85 @@ +socialActionRepository = $socialActionRepository; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->join('acpw.socialAction', 'sa'); + $qb->addSelect('sa.id as action_type_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('action_type_aggregator'); + } else { + $qb->groupBy('action_type_aggregator'); + } + + } + + public function applyOn() + { + return Declarations::SOCIAL_WORK_ACTION_TYPE; + } + + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + public function getLabels($key, array $values, $data) + { + //TODO certain social actions have the same title as other, but are linked to different social issues, should we make a visual distinction? + return function ($value): string { + if ('_header' === $value) { + return 'Social Action Type'; + } + + $sa = $this->socialActionRepository->find($value); + + return $sa->getTitle()['fr']; + }; + } + + public function getQueryKeys($data) + { + return ['action_type_aggregator']; + } + + public function getTitle() + { + return 'Group social work actions by action type'; + } +} diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/GoalAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/GoalAggregator.php new file mode 100644 index 000000000..bc26a113d --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/GoalAggregator.php @@ -0,0 +1,81 @@ +goalRepository = $goalRepository; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->join('acpw.goals', 'g'); + $qb->addSelect('g.id as goal_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('goal_aggregator'); + } else { + $qb->groupBy('goal_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 'Goal Type'; + } + + $g = $this->goalRepository->find($value); + + return $g->getTitle()['fr']; + }; + } + + public function getQueryKeys($data) + { + return ['goal_aggregator']; + } + + public function getTitle() + { + return 'Group social work actions by goal'; + } +} diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/ResultAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/ResultAggregator.php new file mode 100644 index 000000000..ef5740a00 --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/ResultAggregator.php @@ -0,0 +1,81 @@ +resultRepository = $resultRepository; + } + + public function addRole() + { + return null; + } + + public function alterQuery(QueryBuilder $qb, $data) + { + $qb->join('acpw.results', 'r'); + $qb->addSelect('r.id as result_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('result_aggregator'); + } else { + $qb->groupBy('result_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 'Result Type'; + } + + $g = $this->resultRepository->find($value); + + return $g->getTitle()['fr']; + }; + } + + public function getQueryKeys($data) + { + return ['result_aggregator']; + } + + public function getTitle() + { + return 'Group social work actions by result'; + } +} diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml index beefb0756..9ea903758 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml @@ -57,3 +57,24 @@ services: autoconfigure: true tags: - { name: chill.export_aggregator, alias: social_work_actions_referrer_scope_aggregator } + + chill.person.export.aggregator_action_type: + class: Chill\PersonBundle\Export\Aggregator\ActionTypeAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: social_work_actions_action_type_aggregator } + + chill.person.export.aggregator_goal: + class: Chill\PersonBundle\Export\Aggregator\GoalAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: social_work_actions_goal_aggregator } + + chill.person.export.aggregator_result: + class: Chill\PersonBundle\Export\Aggregator\ResultAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: social_work_actions_result_aggregator }