referrer aggregator

This commit is contained in:
Julie Lenaerts 2022-07-27 21:07:05 +02:00
parent 5c82ccc49d
commit 30501a68e3
2 changed files with 99 additions and 5 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\UserRepository;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
use LogicException;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
final class ReferrerAggregator implements AggregatorInterface
{
private UserRepository $userRepository;
public function __construct(UserRepository $userRepository)
{
$this->userRepository = $userRepository;
}
public function addRole()
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.referrers', 'r');
$qb->addSelect('r.id as referrer_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('referrer_aggregator');
} else {
$qb->groupBy('referrer_aggregator');
}
}
public function applyOn()
{
return Declarations::SOCIAL_WORK_ACTION_TYPE;
}
public function buildForm(FormBuilderInterface $builder)
{
// no form
}
public function getLabels($key, array $values, $data)
{
dump($values);
return function ($value): string {
if ('_header' === $value) {
return 'Referrer';
}
$r = $this->userRepository->find($value);
return $r->getUsername();
};
}
public function getQueryKeys($data)
{
return ['referrer_aggregator'];
}
public function getTitle()
{
return 'Group social work actions by referrers';
}
}

View File

@ -30,8 +30,16 @@ services:
- { name: chill.export_filter, alias: social_work_actions_userscope_filter } - { name: chill.export_filter, alias: social_work_actions_userscope_filter }
chill.person.export.filter_userjob: chill.person.export.filter_userjob:
class: Chill\PersonBundle\Export\Filter\UserJobFilter class: Chill\PersonBundle\Export\Filter\UserJobFilter
autowire: true autowire: true
autoconfigure: true autoconfigure: true
tags: tags:
- { name: chill.export_filter, alias: social_work_actions_userjob_filter } - { name: chill.export_filter, alias: social_work_actions_userjob_filter }
## AGGREGATORS
chill.person.export.aggregator_referrer:
class: Chill\PersonBundle\Export\Aggregator\ReferrerAggregator
autowire: true
autoconfigure: true
tags:
- { name: chill.export_aggregator, alias: social_work_actions_referrer_aggregator }