exports: create origin filter

This commit is contained in:
Mathieu Jaumotte 2022-07-25 12:36:22 +02:00
parent 04ca61be81
commit e56520f4b1
3 changed files with 106 additions and 0 deletions

View File

@ -0,0 +1,95 @@
<?php
namespace Chill\PersonBundle\Export\Filter;
use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin;
use Chill\PersonBundle\Export\Declarations;
use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder;
use phpDocumentor\Reflection\Types\Boolean;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface;
class OriginFilter implements FilterInterface
{
/**
* @var TranslatableStringHelper
*/
private TranslatableStringHelper $translatableStringHelper;
public function __construct(
TranslatableStringHelper $translatableStringHelper
) {
$this->translatableStringHelper = $translatableStringHelper;
}
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('accepted_origins', EntityType::class, [
'class' => Origin::class,
'choice_label' => function (Origin $o) {
return $this->translatableStringHelper->localize($o->getLabel());
},
'multiple' => false,
'expanded' => true
]);
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return 'Filter by origin';
}
/**
* @inheritDoc
*/
public function describeAction($data, $format = 'string'): array
{
return ['Filtered by origins: only %origin%', [
'%origin%' => $this->translatableStringHelper->localize(
$data['accepted_origins']->getLabel())
]];
}
/**
* @inheritDoc
*/
public function addRole()
{
return null;
}
/**
* @inheritDoc
*/
public function alterQuery(QueryBuilder $qb, $data)
{
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->eq('acp.origin', ':origin');
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
$qb->setParameter('origin', $data['accepted_origins']);
}
/**
* @inheritDoc
*/
public function applyOn(): string
{
return Declarations::ACP_TYPE;
}
}

View File

@ -86,6 +86,13 @@ services:
autoconfigure: true
tags:
- { name: chill.export_filter, alias: accompanyingcourse_step_filter }
chill.person.export.filter_origin:
class: Chill\PersonBundle\Export\Filter\OriginFilter
autowire: true
autoconfigure: true
tags:
- { name: chill.export_filter, alias: accompanyingcourse_origin_filter }
chill.person.export.aggregator_nationality:
class: Chill\PersonBundle\Export\Aggregator\NationalityAggregator

View File

@ -390,6 +390,10 @@ Filter by step: Filtrer par statut du parcours
Accepted steps: Statuts
"Filtered by steps: only %step%": "Filtré par statut du parcours: uniquement %step%"
Filter by origin: Filtrer par origine du parcours
Accepted origins: Origines
"Filtered by origins: only %origin%": "Filtré par origine du parcours: uniquement %origin%"
## aggregators
Group people by nationality: Aggréger les personnes par nationalités
Group by level: Grouper par niveau