From 5acf2a198680c2f3faa79d669853af5c5751952d Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 2 Nov 2022 13:17:03 +0100 Subject: [PATCH] creator job aggregator --- .../CreatorJobAggregator.php | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/CreatorJobAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/CreatorJobAggregator.php index c473bf7a1..3bae64fec 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/CreatorJobAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/CreatorJobAggregator.php @@ -12,12 +12,27 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators; use Chill\MainBundle\Export\AggregatorInterface; +use Chill\MainBundle\Repository\UserJobRepository; +use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Export\Declarations; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; +use function in_array; class CreatorJobAggregator implements AggregatorInterface { + private UserJobRepository $jobRepository; + + private TranslatableStringHelper $translatableStringHelper; + + public function __construct( + UserJobRepository $jobRepository, + TranslatableStringHelper $translatableStringHelper + ) { + $this->jobRepository = $jobRepository; + $this->translatableStringHelper = $translatableStringHelper; + } + public function addRole(): ?string { return null; @@ -25,7 +40,11 @@ class CreatorJobAggregator implements AggregatorInterface public function alterQuery(QueryBuilder $qb, $data) { - $qb->addSelect('AS acp_creator_job_aggregator') + if (!in_array('acp_creator', $qb->getAllAliases(), true)) { + $qb->leftJoin('acp.createdBy', 'acp_creator'); + } + + $qb->addSelect('IDENTITY(acp_creator.userJob) AS acp_creator_job_aggregator') ->addGroupBy('acp_creator_job_aggregator'); } @@ -41,10 +60,20 @@ class CreatorJobAggregator implements AggregatorInterface public function getLabels($key, array $values, $data) { - return static function ($value): string { + return function ($value): string { if ('_header' === $value) { + return 'Job'; + } + + if (null === $value) { return ''; } + + $j = $this->jobRepository->find($value); + + return $this->translatableStringHelper->localize( + $j->getLabel() + ); }; }