From d30ac75995e0191b7bbba5b05be96775283a92b7 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 19 Sep 2022 11:22:41 +0200 Subject: [PATCH 1/3] exports: create workAction goalResult aggregator --- .../SocialWorkAggregators/GoalAggregator.php | 10 +- .../GoalResultAggregator.php | 94 +++++++++++++++++++ .../ResultAggregator.php | 12 ++- .../services/exports_social_actions.yaml | 7 ++ .../translations/messages.fr.yml | 5 +- 5 files changed, 118 insertions(+), 10 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalResultAggregator.php diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalAggregator.php index 4310dcac2..21c13cef9 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalAggregator.php @@ -52,7 +52,7 @@ final class GoalAggregator implements AggregatorInterface } } - public function applyOn() + public function applyOn(): string { return Declarations::SOCIAL_WORK_ACTION_TYPE; } @@ -71,16 +71,18 @@ final class GoalAggregator implements AggregatorInterface $g = $this->goalRepository->find($value); - return $this->translatableStringHelper->localize($g->getTitle()); + return $this->translatableStringHelper->localize( + $g->getTitle() + ); }; } - public function getQueryKeys($data) + public function getQueryKeys($data): array { return ['goal_aggregator']; } - public function getTitle() + public function getTitle(): string { return 'Group social work actions by goal'; } diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalResultAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalResultAggregator.php new file mode 100644 index 000000000..86bfcd71a --- /dev/null +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalResultAggregator.php @@ -0,0 +1,94 @@ +resultRepository = $resultRepository; + $this->translatableStringHelper = $translatableStringHelper; + } + + + /** + * @inheritDoc + */ + public function getLabels($key, array $values, $data) + { + return function ($value): string { + if ('_header' === $value) { + return 'Goal and result Type'; + } + + //$g = $this->resultRepository->find($value); + + return + $value + //$this->translatableStringHelper->localize( + // $g->getTitle() + //) + ; + }; + } + + /** + * @inheritDoc + */ + public function getQueryKeys($data): array + { + return ['goal_result_aggregator']; + } + + /** + * @inheritDoc + */ + public function buildForm(FormBuilderInterface $builder) + { + // no form + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return 'Group social work actions by goal and result'; + } + + /** + * @inheritDoc + */ + public function addRole(): ?string + { + return null; + } + + /** + * @inheritDoc + */ + public function alterQuery(QueryBuilder $qb, $data) + { + // TODO: Implement alterQuery() method. + } + + /** + * @inheritDoc + */ + public function applyOn(): string + { + return Declarations::SOCIAL_WORK_ACTION_TYPE; + } +} \ No newline at end of file diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php index 47391ed69..2bbd8445c 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php @@ -60,7 +60,7 @@ final class ResultAggregator implements AggregatorInterface } } - public function applyOn() + public function applyOn(): string { return Declarations::SOCIAL_WORK_ACTION_TYPE; } @@ -77,18 +77,20 @@ final class ResultAggregator implements AggregatorInterface return 'Result Type'; } - $g = $this->resultRepository->find($value); + $r = $this->resultRepository->find($value); - return $this->translatableStringHelper->localize($g->getTitle()); + return $this->translatableStringHelper->localize( + $r->getTitle() + ); }; } - public function getQueryKeys($data) + public function getQueryKeys($data): array { return ['result_aggregator']; } - public function getTitle() + public function getTitle(): string { 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 d5f7376db..450899659 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml @@ -79,3 +79,10 @@ services: autoconfigure: true tags: - { name: chill.export_aggregator, alias: social_work_actions_result_aggregator } + + chill.person.export.aggregator_goalresult: + class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\GoalResultAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: social_work_actions_goal_result_aggregator } diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index dc53f4839..ca48fbb7a 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -560,8 +560,11 @@ Group by treating agent: Grouper les actions par agent traitant Group social work actions by action type: Grouper les actions par type Group social work actions by goal: Grouper les actions par objectif -Goal Type: Objectif Group social work actions by result: Grouper les actions par résultat +Group social work actions by goal and result: Grouper les actions par objectif et résultat +Goal Type: Objectif +Result Type: Résultat +Goal and result Type: Objectif et résultat ## evaluations filters/aggr Filter by evaluation type: Filtrer les évaluations par type From 37d49e1123595ec9cabe155e7a7f9125c7c6d455 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 19 Sep 2022 11:46:53 +0200 Subject: [PATCH 2/3] fix goal aggregator error --- .../Aggregator/SocialWorkAggregators/GoalAggregator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalAggregator.php index 21c13cef9..bc534c678 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalAggregator.php @@ -41,7 +41,7 @@ final class GoalAggregator implements AggregatorInterface $qb->join('acpw.goals', 'goal'); } - $qb->addSelect('goal.id as goal_aggregator'); + $qb->addSelect('IDENTITY(goal.goal) as goal_aggregator'); $groupBy = $qb->getDQLPart('groupBy'); @@ -70,7 +70,7 @@ final class GoalAggregator implements AggregatorInterface } $g = $this->goalRepository->find($value); - + return $this->translatableStringHelper->localize( $g->getTitle() ); From 91af01336a1b21acdcf06e972cda9c4f6a3c2aa2 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 19 Sep 2022 13:46:24 +0200 Subject: [PATCH 3/3] fix goalResult aggregator --- .../GoalResultAggregator.php | 78 +++++++++++++++---- .../ResultAggregator.php | 14 +--- 2 files changed, 64 insertions(+), 28 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalResultAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalResultAggregator.php index 86bfcd71a..aeced53d7 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalResultAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/GoalResultAggregator.php @@ -5,20 +5,26 @@ namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators; use Chill\MainBundle\Export\AggregatorInterface; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Export\Declarations; +use Chill\PersonBundle\Repository\SocialWork\GoalRepository; +use Chill\PersonBundle\Repository\SocialWork\ResultRepository; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; class GoalResultAggregator implements AggregatorInterface { - //private ResultRepository $resultRepository; + private ResultRepository $resultRepository; + + private GoalRepository $goalRepository; private TranslatableStringHelper $translatableStringHelper; public function __construct( - //ResultRepository $resultRepository, + ResultRepository $resultRepository, + GoalRepository $goalRepository, TranslatableStringHelper $translatableStringHelper ) { - //$this->resultRepository = $resultRepository; + $this->resultRepository = $resultRepository; + $this->goalRepository = $goalRepository; $this->translatableStringHelper = $translatableStringHelper; } @@ -28,19 +34,35 @@ class GoalResultAggregator implements AggregatorInterface */ public function getLabels($key, array $values, $data) { - return function ($value): string { - if ('_header' === $value) { - return 'Goal and result Type'; + return function ($value) use ($key): string { + switch ($key) { + case 'goal_aggregator': + + if ('_header' === $value) { + return 'Goal Type'; + } + + $g = $this->goalRepository->find($value); + + return $this->translatableStringHelper->localize( + $g->getTitle() + ); + + case 'result_aggregator': + + if ('_header' === $value) { + return 'Result Type'; + } + + $r = $this->resultRepository->find($value); + + return $this->translatableStringHelper->localize( + $r->getTitle() + ); + + default: + throw new \LogicException(); } - - //$g = $this->resultRepository->find($value); - - return - $value - //$this->translatableStringHelper->localize( - // $g->getTitle() - //) - ; }; } @@ -49,7 +71,10 @@ class GoalResultAggregator implements AggregatorInterface */ public function getQueryKeys($data): array { - return ['goal_result_aggregator']; + return [ + 'goal_aggregator', + 'result_aggregator' + ]; } /** @@ -81,7 +106,26 @@ class GoalResultAggregator implements AggregatorInterface */ public function alterQuery(QueryBuilder $qb, $data) { - // TODO: Implement alterQuery() method. + if (!in_array('goal', $qb->getAllAliases(), true)) { + $qb->join('acpw.goals', 'goal'); + } + + if (!in_array('goalresult', $qb->getAllAliases(), true)) { + $qb->join('goal.results', 'goalresult'); + } + + $qb->addSelect('IDENTITY(goal.goal) as goal_aggregator'); + $qb->addSelect('goalresult.id as result_aggregator'); + + $groupBy = $qb->getDQLPart('groupBy'); + + if (!empty($groupBy)) { + $qb->addGroupBy('goal_aggregator'); + } else { + $qb->groupBy('goal_aggregator'); + } + + $qb->addGroupBy('result_aggregator'); } /** diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php index 2bbd8445c..8f7ac0624 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ResultAggregator.php @@ -37,19 +37,11 @@ final class ResultAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { - if (!in_array('acpwresult', $qb->getAllAliases(), true)) { - $qb->join('acpw.results', 'acpwresult'); + if (!in_array('result', $qb->getAllAliases(), true)) { + $qb->join('acpw.results', 'result'); } - if (!in_array('goal', $qb->getAllAliases(), true)) { - $qb->join('acpw.goals', 'goal'); - } - - if (!in_array('goalresult', $qb->getAllAliases(), true)) { - $qb->join('goal.results', 'goalresult'); - } - - $qb->addSelect('acpwresult.id, IDENTITY(goal.results) as result_aggregator'); + $qb->addSelect('result.id as result_aggregator'); $groupBy = $qb->getDQLPart('groupBy');