split ReferrerAggregator

This commit is contained in:
Mathieu Jaumotte 2022-08-11 16:56:18 +02:00
parent 93eb9220a7
commit 312a23e91f
4 changed files with 102 additions and 18 deletions

View File

@ -9,7 +9,7 @@
declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator;
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Repository\UserRepository;
@ -40,21 +40,9 @@ final class ReferrerAggregator implements AggregatorInterface
public function alterQuery(QueryBuilder $qb, $data)
{
switch ($qb->getRootAlias()) {
$qb->join('acp.user', 'u');
case 'acp':
$qb->join('acp.user', 'u');
$qb->addSelect('u.id AS referrer_aggregator');
break;
case 'acpw':
$qb->join('acpw.referrers', 'r');
$qb->addSelect('r.id AS referrer_aggregator');
break;
default:
throw new \Exception("Does not apply on that base entity");
}
$qb->addSelect('u.id AS referrer_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
@ -68,7 +56,7 @@ final class ReferrerAggregator implements AggregatorInterface
public function applyOn(): string
{
return Declarations::ACP_SHARED;
return Declarations::ACP_TYPE;
}
public function buildForm(FormBuilderInterface $builder)

View File

@ -0,0 +1,89 @@
<?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\SocialWorkAggregators;
use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Repository\UserRepository;
use Chill\MainBundle\Templating\Entity\UserRender;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr\From;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
final class ReferrerAggregator implements AggregatorInterface
{
private UserRepository $userRepository;
private UserRender $userRender;
public function __construct(
UserRepository $userRepository,
UserRender $userRender
) {
$this->userRepository = $userRepository;
$this->userRender = $userRender;
}
public function addRole()
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$qb->join('acpw.referrers', 'u');
$qb->addSelect('u.id AS referrer_aggregator');
$groupBy = $qb->getDQLPart('groupBy');
if (!empty($groupBy)) {
$qb->addGroupBy('referrer_aggregator');
} else {
$qb->groupBy('referrer_aggregator');
}
}
public function applyOn(): string
{
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 'Referrer';
}
$r = $this->userRepository->find($value);
return $this->userRender->renderString($r, []);
};
}
public function getQueryKeys($data): array
{
return ['referrer_aggregator'];
}
public function getTitle(): string
{
return 'Group by treating agent';
}
}

View File

@ -235,7 +235,7 @@ services:
- { name: chill.export_aggregator, alias: accompanyingcourse_intensity_aggregator }
chill.person.export.aggregator_referrer:
class: Chill\PersonBundle\Export\Aggregator\ReferrerAggregator
class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\ReferrerAggregator
autowire: true
autoconfigure: true
tags:

View File

@ -35,7 +35,7 @@ services:
autowire: true
autoconfigure: true
tags:
- { name: chill.export_filter, alias: social_work_actions_referrer_filter }
- { name: chill.export_filter, alias: social_work_actions_treating_agent_filter }
## AGGREGATORS
chill.person.export.aggregator_action_type:
@ -44,6 +44,13 @@ services:
autoconfigure: true
tags:
- { name: chill.export_aggregator, alias: social_work_actions_action_type_aggregator }
chill.person.export.aggregator_treating_agent:
class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\ReferrerAggregator
autowire: true
autoconfigure: true
tags:
- { name: chill.export_aggregator, alias: social_work_actions_treating_agent_aggregator }
chill.person.export.aggregator_goal:
class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\GoalAggregator