mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
exports: add new referrer filter, with mechanism to use it in acp or acpw context
This commit is contained in:
parent
b9186ed6e0
commit
c1f578a811
@ -21,4 +21,6 @@ abstract class Declarations
|
|||||||
public const PERSON_TYPE = 'person';
|
public const PERSON_TYPE = 'person';
|
||||||
|
|
||||||
public const ACP_TYPE = 'accompanying_period';
|
public const ACP_TYPE = 'accompanying_period';
|
||||||
|
|
||||||
|
public const ACP_SHARED = 'accompanying_period_shared';
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ class CountAccompanyingCourse implements ExportInterface, GroupedExportInterface
|
|||||||
|
|
||||||
public function supportsModifiers(): array
|
public function supportsModifiers(): array
|
||||||
{
|
{
|
||||||
return [Declarations::ACP_TYPE];
|
return [Declarations::ACP_TYPE, Declarations::ACP_SHARED];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getGroup(): string
|
public function getGroup(): string
|
||||||
|
161
src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php
Normal file
161
src/Bundle/ChillPersonBundle/Export/Filter/ReferrerFilter.php
Normal file
@ -0,0 +1,161 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Chill\PersonBundle\Export\Filter;
|
||||||
|
|
||||||
|
use Chill\MainBundle\Entity\User;
|
||||||
|
use Chill\MainBundle\Export\FilterInterface;
|
||||||
|
use Chill\MainBundle\Templating\Entity\UserRender;
|
||||||
|
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
|
||||||
|
use Chill\PersonBundle\Export\Declarations;
|
||||||
|
use Doctrine\ORM\Query\Expr\From;
|
||||||
|
use Doctrine\ORM\QueryBuilder;
|
||||||
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||||
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
|
use function PHPUnit\Framework\throwException;
|
||||||
|
|
||||||
|
class ReferrerFilter implements FilterInterface
|
||||||
|
{
|
||||||
|
private UserRender $userRender;
|
||||||
|
|
||||||
|
public function __construct(UserRender $userRender)
|
||||||
|
{
|
||||||
|
$this->userRender = $userRender;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function buildForm(FormBuilderInterface $builder)
|
||||||
|
{
|
||||||
|
$builder->add('accepted_referrers', EntityType::class, [
|
||||||
|
'class' => User::class,
|
||||||
|
'choice_label' => function (User $u) {
|
||||||
|
return $this->userRender->renderString($u, []);
|
||||||
|
},
|
||||||
|
'multiple' => true,
|
||||||
|
'expanded' => true
|
||||||
|
]);
|
||||||
|
/*
|
||||||
|
$builder->add('referrers', EntityType::class, [
|
||||||
|
'class' => User::class,
|
||||||
|
'choice_label' => function (User $u) {
|
||||||
|
return $this->userRender->renderString($u, []);
|
||||||
|
},
|
||||||
|
'multiple' => true,
|
||||||
|
'expanded' => true
|
||||||
|
]);
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function getTitle(): string
|
||||||
|
{
|
||||||
|
return 'Filtered by referrers';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function describeAction($data, $format = 'string')
|
||||||
|
{
|
||||||
|
$users = [];
|
||||||
|
|
||||||
|
foreach ($data['accepted_referrers'] as $r) {
|
||||||
|
$users[] = $r;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'Filtered by referrer: only %referrers%', [
|
||||||
|
'%referrers' => implode(", ou ", $users)
|
||||||
|
]];
|
||||||
|
/*
|
||||||
|
$referrers = [];
|
||||||
|
|
||||||
|
foreach ($data['referrers'] as $r) {
|
||||||
|
$referrers[] = $this->userRender->renderString($r, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['Filtered by referrers: only %referrers%', [
|
||||||
|
'%referrers%' => implode(', ou ', $referrers)
|
||||||
|
]];
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function addRole()
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function alterQuery(QueryBuilder $qb, $data)
|
||||||
|
{
|
||||||
|
|
||||||
|
$where = $qb->getDQLPart('where');
|
||||||
|
|
||||||
|
$from_alias = $this->getEntityFromQB($qb);
|
||||||
|
|
||||||
|
// Use querybuilder from alias to find which export context (indicator)
|
||||||
|
switch ($from_alias) {
|
||||||
|
case 'acp':
|
||||||
|
$clause = $qb->expr()->in('acp.user', ':referrers');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'acpw':
|
||||||
|
$qb->join('acpw.referrers', 'r');
|
||||||
|
$clause = $qb->expr()->in('r', ':referrers');
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new \Exception("Referrer filter doesn't apply on that entity");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($where instanceof Andx) {
|
||||||
|
$where->add($clause);
|
||||||
|
} else {
|
||||||
|
$where = $qb->expr()->andX($clause);
|
||||||
|
}
|
||||||
|
|
||||||
|
$qb->add('where', $where);
|
||||||
|
$qb->setParameter('referrers', $data['accepted_referrers']);
|
||||||
|
|
||||||
|
/*
|
||||||
|
$qb->join('acpw.referrers', 'r');
|
||||||
|
|
||||||
|
$where = $qb->getDQLPart('where');
|
||||||
|
$clause = $qb->expr()->in('r', ':referrers');
|
||||||
|
|
||||||
|
if ($where instanceof Andx) {
|
||||||
|
$where->add($clause);
|
||||||
|
} else {
|
||||||
|
$where = $qb->expr()->andX($clause);
|
||||||
|
}
|
||||||
|
|
||||||
|
$qb->add('where', $where);
|
||||||
|
$qb->setParameter('referrers', $data['referrers']);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getEntityFromQB(QueryBuilder $qb): string
|
||||||
|
{
|
||||||
|
/** @var From $from */
|
||||||
|
$from = $qb->getDQLPart('from');
|
||||||
|
|
||||||
|
return $from[0]->getAlias();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function applyOn()
|
||||||
|
{
|
||||||
|
return Declarations::ACP_SHARED;
|
||||||
|
}
|
||||||
|
}
|
@ -95,4 +95,11 @@ services:
|
|||||||
tags:
|
tags:
|
||||||
- { name: chill.export_filter, alias: accompanyingcourse_intensity_filter }
|
- { name: chill.export_filter, alias: accompanyingcourse_intensity_filter }
|
||||||
|
|
||||||
|
chill.person.export.filter_referrer:
|
||||||
|
class: Chill\PersonBundle\Export\Filter\ReferrerFilter
|
||||||
|
autowire: true
|
||||||
|
autoconfigure: true
|
||||||
|
tags:
|
||||||
|
- { name: chill.export_filter, alias: accompanyingcourse_referrer_filter }
|
||||||
|
|
||||||
## Aggregators
|
## Aggregators
|
@ -416,6 +416,10 @@ is occasional: le parcours est ponctuel
|
|||||||
is regular: le parcours est régulier
|
is regular: le parcours est régulier
|
||||||
"Filtered by intensity: only %intensity%": "Filtré par intensité: uniquement si %intensity%"
|
"Filtered by intensity: only %intensity%": "Filtré par intensité: uniquement si %intensity%"
|
||||||
|
|
||||||
|
Filtered by referrers: Filtrer par référent
|
||||||
|
Accepted referrers: Référents
|
||||||
|
"Filtered by referrer: only %referrers%": "Filtré par référent: uniquement %referrers%"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user