From ed1dde4713f4be32c113734b04dc3877692d9a2e Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Tue, 9 Aug 2022 11:30:42 +0200 Subject: [PATCH] exports: share referrer aggregator --- .../ReferrerAggregator.php | 50 +++++++++++++++---- .../services/exports_accompanying_course.yaml | 8 +++ .../services/exports_social_actions.yaml | 7 --- .../translations/messages.fr.yml | 1 + 4 files changed, 48 insertions(+), 18 deletions(-) rename src/Bundle/ChillPersonBundle/Export/Aggregator/{SocialWorkAggregators => }/ReferrerAggregator.php (52%) diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ReferrerAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/ReferrerAggregator.php similarity index 52% rename from src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ReferrerAggregator.php rename to src/Bundle/ChillPersonBundle/Export/Aggregator/ReferrerAggregator.php index a7ea78c3b..3f9344212 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/ReferrerAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/ReferrerAggregator.php @@ -9,11 +9,13 @@ declare(strict_types=1); -namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators; +namespace Chill\PersonBundle\Export\Aggregator; use Chill\MainBundle\Export\AggregatorInterface; use Chill\MainBundle\Repository\UserRepository; +use Chill\MainBundle\Templating\Entity\UserRender; use Chill\PersonBundle\Export\Declarations; +use Doctrine\ORM\Query\Expr\From; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -21,9 +23,14 @@ final class ReferrerAggregator implements AggregatorInterface { private UserRepository $userRepository; - public function __construct(UserRepository $userRepository) - { + private UserRender $userRender; + + public function __construct( + UserRepository $userRepository, + UserRender $userRender + ) { $this->userRepository = $userRepository; + $this->userRender = $userRender; } public function addRole() @@ -33,8 +40,21 @@ final class ReferrerAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { - $qb->join('acpw.referrers', 'r'); - $qb->addSelect('r.id as referrer_aggregator'); + switch ($this->getBaseEntityAppliedOn($qb)) { + + case 'acp': + $qb->join('acp.user', 'u'); + $qb->addSelect('u.id AS referrer_aggregator'); + break; + + case 'acpw': + $qb->join('acpw.referrers', 'r'); + $qb->addSelect('r.id AS referrer_aggregator'); + break; + + default: + throw new \Exception("Does not apply on that base entity"); + } $groupBy = $qb->getDQLPart('groupBy'); @@ -46,9 +66,9 @@ final class ReferrerAggregator implements AggregatorInterface } - public function applyOn() + public function applyOn(): string { - return Declarations::SOCIAL_WORK_ACTION_TYPE; + return Declarations::ACP_SHARED; } public function buildForm(FormBuilderInterface $builder) @@ -65,17 +85,25 @@ final class ReferrerAggregator implements AggregatorInterface $r = $this->userRepository->find($value); - return $r->getUsername(); + return $this->userRender->renderString($r, []); }; } - public function getQueryKeys($data) + public function getQueryKeys($data): array { return ['referrer_aggregator']; } - public function getTitle() + public function getTitle(): string { - return 'Group social work actions by referrers'; + return 'Group by referrers'; + } + + private function getBaseEntityAppliedOn(QueryBuilder $qb): string + { + /** @var From $from */ + $from = $qb->getDQLPart('from'); + + return $from[0]->getAlias(); } } diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml index 019bf6fd1..592df7573 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_accompanying_course.yaml @@ -233,3 +233,11 @@ services: autoconfigure: true tags: - { name: chill.export_aggregator, alias: accompanyingcourse_intensity_aggregator } + + chill.person.export.aggregator_referrer: + class: Chill\PersonBundle\Export\Aggregator\ReferrerAggregator + autowire: true + autoconfigure: true + tags: + - { name: chill.export_aggregator, alias: accompanyingcourse_referrer_aggregator } + diff --git a/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml b/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml index b655afaa6..266b8db75 100644 --- a/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/exports_social_actions.yaml @@ -31,13 +31,6 @@ services: - { name: chill.export_filter, alias: social_work_actions_job_filter } ## AGGREGATORS - chill.person.export.aggregator_referrer: - class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\ReferrerAggregator - autowire: true - autoconfigure: true - tags: - - { name: chill.export_aggregator, alias: social_work_actions_referrer_aggregator } - chill.person.export.aggregator_action_type: class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\ActionTypeAggregator autowire: true diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 8e3c7f389..3d30b5c9f 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -504,6 +504,7 @@ Filtered by active at least one day between dates: Filtrer les parcours actifs a Filtered by referrers: Filtrer par référent Accepted referrers: Référents "Filtered by referrer: only %referrers%": "Filtré par référent: uniquement %referrers%" +Group by referrers: Grouper par référent Filtered by opened between dates: Filtrer les parcours ouverts entre deux dates Date from: Date de début