mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
exports: create intensity filter
This commit is contained in:
parent
da224ea4bc
commit
e728c00671
@ -44,8 +44,6 @@ class EmergencyFilter implements FilterInterface
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
dump($data, self::CHOICES);
|
||||
|
||||
foreach (self::CHOICES as $k => $v) {
|
||||
if ($v === $data['accepted_emergencies']) {
|
||||
$choice = $k;
|
||||
|
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\Export\Filter;
|
||||
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\PersonBundle\Export\Declarations;
|
||||
use Doctrine\ORM\Query\Expr\Andx;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class IntensityFilter implements FilterInterface
|
||||
{
|
||||
private const CHOICES = [
|
||||
'is occasional' => 'occasional',
|
||||
'is regular' => 'regular',
|
||||
];
|
||||
|
||||
private CONST DEFAULT_CHOICE = 'occasional';
|
||||
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('accepted_intensities', ChoiceType::class, [
|
||||
'choices' => self::CHOICES,
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'empty_data' => self::DEFAULT_CHOICE,
|
||||
'data' => self::DEFAULT_CHOICE,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return 'Filter by intensity';
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string'): array
|
||||
{
|
||||
foreach (self::CHOICES as $k => $v) {
|
||||
if ($v === $data['accepted_intensities']) {
|
||||
$choice = $k;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'Filtered by intensity: only %intensity%', [
|
||||
'%intensity%' => $this->translator->trans($choice)
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function addRole()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$where = $qb->getDQLPart('where');
|
||||
$clause = $qb->expr()->eq('acp.intensity', ':intensity');
|
||||
|
||||
if ($where instanceof Andx) {
|
||||
$where->add($clause);
|
||||
} else {
|
||||
$where = $qb->expr()->andX($clause);
|
||||
}
|
||||
|
||||
$qb->add('where', $where);
|
||||
$qb->setParameter('intensity', $data['accepted_intensities']);
|
||||
}
|
||||
|
||||
public function applyOn(): string
|
||||
{
|
||||
return Declarations::ACP_TYPE;
|
||||
}
|
||||
|
||||
}
|
@ -88,4 +88,11 @@ services:
|
||||
tags:
|
||||
- { name: chill.export_filter, alias: accompanyingcourse_emergency_filter }
|
||||
|
||||
chill.person.export.filter_intensity:
|
||||
class: Chill\PersonBundle\Export\Filter\IntensityFilter
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
tags:
|
||||
- { name: chill.export_filter, alias: accompanyingcourse_intensity_filter }
|
||||
|
||||
## Aggregators
|
@ -410,6 +410,15 @@ is emergency: le parcours est urgent
|
||||
is not emergency: le parcours n'est pas urgent
|
||||
"Filtered by emergency: only %emergency%": "Filtré par urgence: uniquement si %emergency%"
|
||||
|
||||
Filter by intensity: Filtrer par intensité
|
||||
Accepted intensities: ''
|
||||
is occasional: le parcours est ponctuel
|
||||
is regular: le parcours est régulier
|
||||
"Filtered by intensity: only %intensity%": "Filtré par intensité: uniquement si %intensity%"
|
||||
|
||||
|
||||
|
||||
|
||||
## aggregators
|
||||
Group people by nationality: Aggréger les personnes par nationalités
|
||||
Group by level: Grouper par niveau
|
||||
|
Loading…
x
Reference in New Issue
Block a user