creator job aggregator

This commit is contained in:
Julie Lenaerts 2022-11-02 13:17:03 +01:00
parent f40aa89d08
commit 5acf2a1986

View File

@ -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()
);
};
}