referrer job aggregator for social work actions

This commit is contained in:
Julie Lenaerts 2022-07-27 21:19:13 +02:00
parent 30501a68e3
commit 562a5678ef
2 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1,86 @@
<?php
/**
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator;
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;
final class ReferrerJobAggregator implements AggregatorInterface
{
private UserJobRepository $userJobRepository;
private TranslatableStringHelper $translatableStringHelper;
public function __construct(UserJobRepository $userJobRepository, TranslatableStringHelper $translatableStringHelper)
{
$this->userJobRepository = $userJobRepository;
$this->translatableStringHelper = $translatableStringHelper;
}
public function addRole()
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.referrers', 'r');
$qb->addSelect('IDENTITY(r.userJob) as referrer_job_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('referrer_job_aggregator');
} else {
$qb->groupBy('referrer_job_aggregator');
}
}
public function applyOn()
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
public function getLabels($key, array $values, $data)
{
return function ($value): string {
if ('_header' === $value) {
return 'User job';
}
$j = $this->userJobRepository->find($value);
return $this->translatableStringHelper->localize(
$j->getLabel());
};
}
public function getQueryKeys($data)
{
return ['referrer_job_aggregator'];
}
public function getTitle()
{
return 'Group social work actions by referrer job';
}
}

View File

@ -43,3 +43,10 @@ services:
autoconfigure: true autoconfigure: true
tags: tags:
- { name: chill.export_aggregator, alias: social_work_actions_referrer_aggregator } - { name: chill.export_aggregator, alias: social_work_actions_referrer_aggregator }
chill.person.export.aggregator_referrer_job:
class: Chill\PersonBundle\Export\Aggregator\ReferrerJobAggregator
autowire: true
autoconfigure: true
tags:
- { name: chill.export_aggregator, alias: social_work_actions_referrer_job_aggregator }