From b790e2fcf199482faed7710fcae2f19197d0e703 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Tue, 14 Nov 2023 14:18:50 +0100 Subject: [PATCH] complete aggregators --- .../CreatorAggregator.php | 29 +++++++++---- .../CreatorJobAggregator.php | 42 ++++++++++++++++--- .../CreatorScopeAggregator.php | 42 ++++++++++++++++--- .../translations/messages.fr.yml | 5 ++- 4 files changed, 96 insertions(+), 22 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/CreatorAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/CreatorAggregator.php index afe416f9f..9d03e3ba1 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/CreatorAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/CreatorAggregator.php @@ -12,7 +12,8 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators; use Chill\MainBundle\Export\AggregatorInterface; -use Chill\MainBundle\Templating\TranslatableStringHelper; +use Chill\MainBundle\Repository\UserRepository; +use Chill\MainBundle\Templating\Entity\UserRender; use Chill\PersonBundle\Export\Declarations; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -22,7 +23,8 @@ class CreatorAggregator implements AggregatorInterface private const PREFIX = 'acpw_aggr_creator'; public function __construct( - private readonly TranslatableStringHelper $translatableStringHelper + private UserRepository $userRepository, + private UserRender $userRender ) {} public function addRole(): ?string @@ -32,7 +34,11 @@ class CreatorAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { - $qb; + $p = self::PREFIX; + + $qb + ->addSelect("IDENTITY(acpw.createdBy) AS {$p}_select") + ->addGroupBy("{$p}_select"); } public function applyOn(): string @@ -40,10 +46,7 @@ class CreatorAggregator implements AggregatorInterface return Declarations::SOCIAL_WORK_ACTION_TYPE; } - public function buildForm(FormBuilderInterface $builder) - { - $builder->add(); - } + public function buildForm(FormBuilderInterface $builder) {} public function getFormDefaultData(): array { @@ -53,13 +56,23 @@ class CreatorAggregator implements AggregatorInterface public function getLabels($key, array $values, mixed $data) { return function ($value): string { + if ('_header' === $value) { + return 'export.aggregator.course_work.by_creator.Creator'; + }; + if (null === $value || '' === $value) { + return ''; + } + + $r = $this->userRepository->find($value); + + return $this->userRender->renderString($r, ['absence' => false, 'user_job' => false, 'main_scope' => false]); }; } public function getQueryKeys($data): array { - return []; + return [self::PREFIX.'_select']; } public function getTitle(): string diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/CreatorJobAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/CreatorJobAggregator.php index ea53c4f80..fd5444b62 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/CreatorJobAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/CreatorJobAggregator.php @@ -11,9 +11,12 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators; +use Chill\MainBundle\Entity\User\UserJobHistory; use Chill\MainBundle\Export\AggregatorInterface; +use Chill\MainBundle\Repository\UserJobRepository; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Export\Declarations; +use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -22,6 +25,7 @@ class CreatorJobAggregator implements AggregatorInterface private const PREFIX = 'acpw_aggr_creator_job'; public function __construct( + private readonly UserJobRepository $jobRepository, private readonly TranslatableStringHelper $translatableStringHelper ) {} @@ -32,7 +36,26 @@ class CreatorJobAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { - $qb; + $p = self::PREFIX; + + $qb + ->leftJoin( + UserJobHistory::class, + "{$p}_history", + Join::WITH, + $qb->expr()->andX( + $qb->expr()->eq("{$p}_history.user", "acpw.createdBy"), + $qb->expr()->andX( + $qb->expr()->lte("{$p}_history.startDate", "acpw.createdAt"), + $qb->expr()->orX( + $qb->expr()->isNull("{$p}_history.endDate"), + $qb->expr()->gt("{$p}_history.endDate", "acpw.createdAt") + ) + ) + ) + ) + ->addSelect("IDENTITY({$p}_history.job) AS {$p}_select") + ->addGroupBy("{$p}_select"); } public function applyOn(): string @@ -40,10 +63,7 @@ class CreatorJobAggregator implements AggregatorInterface return Declarations::SOCIAL_WORK_ACTION_TYPE; } - public function buildForm(FormBuilderInterface $builder) - { - $builder->add(); - } + public function buildForm(FormBuilderInterface $builder) {} public function getFormDefaultData(): array { @@ -53,13 +73,23 @@ class CreatorJobAggregator implements AggregatorInterface public function getLabels($key, array $values, mixed $data) { return function ($value): string { + if ('_header' === $value) { + return 'export.aggregator.course_work.by_creator_job.Creator\'s job'; + } + if (null === $value || '' === $value || null === $j = $this->jobRepository->find($value)) { + return ''; + } + + return $this->translatableStringHelper->localize( + $j->getLabel() + ); }; } public function getQueryKeys($data): array { - return []; + return [self::PREFIX.'_select']; } public function getTitle(): string diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/CreatorScopeAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/CreatorScopeAggregator.php index e8eab62d4..fdbbf56a4 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/CreatorScopeAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/SocialWorkAggregators/CreatorScopeAggregator.php @@ -11,9 +11,12 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators; +use Chill\MainBundle\Entity\User\UserScopeHistory; use Chill\MainBundle\Export\AggregatorInterface; +use Chill\MainBundle\Repository\ScopeRepository; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Export\Declarations; +use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -22,6 +25,7 @@ class CreatorScopeAggregator implements AggregatorInterface private const PREFIX = 'acpw_aggr_creator_scope'; public function __construct( + private readonly ScopeRepository $scopeRepository, private readonly TranslatableStringHelper $translatableStringHelper ) {} @@ -32,7 +36,26 @@ class CreatorScopeAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { - $qb; + $p = self::PREFIX; + + $qb + ->leftJoin( + UserScopeHistory::class, + "{$p}_history", + Join::WITH, + $qb->expr()->andX( + $qb->expr()->eq("{$p}_history.user", "acpw.createdBy"), + $qb->expr()->andX( + $qb->expr()->lte("{$p}_history.startDate", "acpw.createdAt"), + $qb->expr()->orX( + $qb->expr()->isNull("{$p}_history.endDate"), + $qb->expr()->gt("{$p}_history.endDate", "acpw.createdAt") + ) + ) + ) + ) + ->addSelect("IDENTITY({$p}_history.scope) AS {$p}_select") + ->addGroupBy("{$p}_select"); } public function applyOn(): string @@ -40,10 +63,7 @@ class CreatorScopeAggregator implements AggregatorInterface return Declarations::SOCIAL_WORK_ACTION_TYPE; } - public function buildForm(FormBuilderInterface $builder) - { - $builder->add(); - } + public function buildForm(FormBuilderInterface $builder) {} public function getFormDefaultData(): array { @@ -53,13 +73,23 @@ class CreatorScopeAggregator implements AggregatorInterface public function getLabels($key, array $values, mixed $data) { return function ($value): string { + if ('_header' === $value) { + return 'export.aggregator.course_work.by_creator_scope.Creator\'s scope'; + } + if (null === $value || '' === $value || null === $s = $this->scopeRepository->find($value)) { + return ''; + } + + return $this->translatableStringHelper->localize( + $s->getName() + ); }; } public function getQueryKeys($data): array { - return []; + return [self::PREFIX.'_select']; } public function getTitle(): string diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 878ff7970..12705cb29 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -1096,10 +1096,13 @@ export: header: Tiers traitant by_creator: title: Grouper les actions par créateur + Creator: Créateur de l'action by_creator_job: title: Grouper les actions par métier du créateur + Creator's job: Métier du créateur by_creator_scope: title: Grouper les actions par service du créateur + Creator's scope: Service du créateur eval: by_end_date: @@ -1224,8 +1227,6 @@ export: title: Filtrer les actions par créateur Creators: Créateur de l'action "Filtered by creator: only %creators%": "Filtré par créateur de l'action: uniquement %creators%" - #Calc date: Date à laquelle le créateur ... - #calc_date_help: Il s'agit de la date à laquelle le créateur ... by_creator_job: title: Filtrer les actions par métier du créateur "Filtered by creator job: only %jobs%'": "Filtré par métier du créateur: uniquement %jobs%"