mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
exports: share referrer aggregator
This commit is contained in:
@@ -9,11 +9,13 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\Export\Aggregator\SocialWorkAggregators;
|
||||
namespace Chill\PersonBundle\Export\Aggregator;
|
||||
|
||||
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;
|
||||
|
||||
@@ -21,9 +23,14 @@ final class ReferrerAggregator implements AggregatorInterface
|
||||
{
|
||||
private UserRepository $userRepository;
|
||||
|
||||
public function __construct(UserRepository $userRepository)
|
||||
{
|
||||
private UserRender $userRender;
|
||||
|
||||
public function __construct(
|
||||
UserRepository $userRepository,
|
||||
UserRender $userRender
|
||||
) {
|
||||
$this->userRepository = $userRepository;
|
||||
$this->userRender = $userRender;
|
||||
}
|
||||
|
||||
public function addRole()
|
||||
@@ -33,8 +40,21 @@ final class ReferrerAggregator implements AggregatorInterface
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$qb->join('acpw.referrers', 'r');
|
||||
$qb->addSelect('r.id as referrer_aggregator');
|
||||
switch ($this->getBaseEntityAppliedOn($qb)) {
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
$groupBy = $qb->getDQLPart('groupBy');
|
||||
|
||||
@@ -46,9 +66,9 @@ final class ReferrerAggregator implements AggregatorInterface
|
||||
|
||||
}
|
||||
|
||||
public function applyOn()
|
||||
public function applyOn(): string
|
||||
{
|
||||
return Declarations::SOCIAL_WORK_ACTION_TYPE;
|
||||
return Declarations::ACP_SHARED;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
@@ -65,17 +85,25 @@ final class ReferrerAggregator implements AggregatorInterface
|
||||
|
||||
$r = $this->userRepository->find($value);
|
||||
|
||||
return $r->getUsername();
|
||||
return $this->userRender->renderString($r, []);
|
||||
};
|
||||
}
|
||||
|
||||
public function getQueryKeys($data)
|
||||
public function getQueryKeys($data): array
|
||||
{
|
||||
return ['referrer_aggregator'];
|
||||
}
|
||||
|
||||
public function getTitle()
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Group social work actions by referrers';
|
||||
return 'Group by referrers';
|
||||
}
|
||||
|
||||
private function getBaseEntityAppliedOn(QueryBuilder $qb): string
|
||||
{
|
||||
/** @var From $from */
|
||||
$from = $qb->getDQLPart('from');
|
||||
|
||||
return $from[0]->getAlias();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user