mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
split ReferrerAggregator
This commit is contained in:
parent
93eb9220a7
commit
312a23e91f
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace Chill\PersonBundle\Export\Aggregator;
|
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
|
||||||
|
|
||||||
use Chill\MainBundle\Export\AggregatorInterface;
|
use Chill\MainBundle\Export\AggregatorInterface;
|
||||||
use Chill\MainBundle\Repository\UserRepository;
|
use Chill\MainBundle\Repository\UserRepository;
|
||||||
@ -40,21 +40,9 @@ final class ReferrerAggregator implements AggregatorInterface
|
|||||||
|
|
||||||
public function alterQuery(QueryBuilder $qb, $data)
|
public function alterQuery(QueryBuilder $qb, $data)
|
||||||
{
|
{
|
||||||
switch ($qb->getRootAlias()) {
|
$qb->join('acp.user', 'u');
|
||||||
|
|
||||||
case 'acp':
|
$qb->addSelect('u.id AS referrer_aggregator');
|
||||||
$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");
|
|
||||||
}
|
|
||||||
|
|
||||||
$groupBy = $qb->getDQLPart('groupBy');
|
$groupBy = $qb->getDQLPart('groupBy');
|
||||||
|
|
||||||
@ -68,7 +56,7 @@ final class ReferrerAggregator implements AggregatorInterface
|
|||||||
|
|
||||||
public function applyOn(): string
|
public function applyOn(): string
|
||||||
{
|
{
|
||||||
return Declarations::ACP_SHARED;
|
return Declarations::ACP_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildForm(FormBuilderInterface $builder)
|
public function buildForm(FormBuilderInterface $builder)
|
@ -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';
|
||||||
|
}
|
||||||
|
}
|
@ -235,7 +235,7 @@ services:
|
|||||||
- { name: chill.export_aggregator, alias: accompanyingcourse_intensity_aggregator }
|
- { name: chill.export_aggregator, alias: accompanyingcourse_intensity_aggregator }
|
||||||
|
|
||||||
chill.person.export.aggregator_referrer:
|
chill.person.export.aggregator_referrer:
|
||||||
class: Chill\PersonBundle\Export\Aggregator\ReferrerAggregator
|
class: Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators\ReferrerAggregator
|
||||||
autowire: true
|
autowire: true
|
||||||
autoconfigure: true
|
autoconfigure: true
|
||||||
tags:
|
tags:
|
||||||
|
@ -35,7 +35,7 @@ services:
|
|||||||
autowire: true
|
autowire: true
|
||||||
autoconfigure: true
|
autoconfigure: true
|
||||||
tags:
|
tags:
|
||||||
- { name: chill.export_filter, alias: social_work_actions_referrer_filter }
|
- { name: chill.export_filter, alias: social_work_actions_treating_agent_filter }
|
||||||
|
|
||||||
## AGGREGATORS
|
## AGGREGATORS
|
||||||
chill.person.export.aggregator_action_type:
|
chill.person.export.aggregator_action_type:
|
||||||
@ -44,6 +44,13 @@ services:
|
|||||||
autoconfigure: true
|
autoconfigure: true
|
||||||
tags:
|
tags:
|
||||||
- { name: chill.export_aggregator, alias: social_work_actions_action_type_aggregator }
|
- { 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:
|
chill.person.export.aggregator_goal:
|
||||||
class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\GoalAggregator
|
class: Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators\GoalAggregator
|
||||||
|
Loading…
x
Reference in New Issue
Block a user