exports: add new step filter

This commit is contained in:
Mathieu Jaumotte 2022-07-20 13:47:15 +02:00
parent 7f1dadc136
commit b608976326
3 changed files with 103 additions and 9 deletions

View File

@ -0,0 +1,85 @@
<?php
namespace Chill\PersonBundle\Export\Filter;
use Chill\MainBundle\Export\ExportElementValidatedInterface;
use Chill\MainBundle\Export\FilterInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person;
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\Component\Validator\Context\ExecutionContextInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class StepFilter implements FilterInterface
{
private const STEPS = [
'Draft' => AccompanyingPeriod::STEP_DRAFT,
'Confirmed' => AccompanyingPeriod::STEP_CONFIRMED,
'Closed' => AccompanyingPeriod::STEP_CLOSED,
];
private const DEFAULT_CHOICE = AccompanyingPeriod::STEP_CONFIRMED;
/**
* @var TranslatorInterface
*/
protected $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('accepted_step', ChoiceType::class, [
'choices' => self::STEPS,
'multiple' => false,
'expanded' => true,
'empty_data' => self::DEFAULT_CHOICE,
'data' => self::DEFAULT_CHOICE,
]);
}
public function getTitle()
{
return 'Filter by step';
}
public function describeAction($data, $format = 'string')
{
$step = array_flip(self::STEPS)[$data['accepted_step']];
return ["Filtered by steps: only %step%", [
'%step%' => $this->translator->trans($step)
]];
}
public function addRole()
{
return null;
}
public function alterQuery(QueryBuilder $qb, $data)
{
$where = $qb->getDQLPart('where');
$clause = $qb->expr()->eq('acp.step', ':step');
// override original where clause
$where = $qb->expr()->andX($clause);
$qb->add('where', $where);
$qb->setParameter('step', $data['accepted_step']);
}
public function applyOn()
{
return Declarations::ACP_TYPE;
}
}

View File

@ -61,19 +61,24 @@ services:
chill.person.export.filter_userscope:
class: Chill\PersonBundle\Export\Filter\UserScopeFilter
arguments:
$translator: '@translator'
$translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper'
autowire: true
autoconfigure: true
tags:
- { name: chill.export_filter, alias: accompanyingcourse_userscope_filter }
chill.person.export.filter_userjob:
class: Chill\PersonBundle\Export\Filter\UserJobFilter
arguments:
$translator: '@translator'
$translatableStringHelper: '@Chill\MainBundle\Templating\TranslatableStringHelper'
autowire: true
autoconfigure: true
tags:
- { name: chill.export_filter, alias: accompanyingcourse_userjob_filter }
chill.person.export.filter_step:
class: Chill\PersonBundle\Export\Filter\StepFilter
autowire: true
autoconfigure: true
tags:
- { name: chill.export_filter, alias: accompanyingcourse_step_filter }
chill.person.export.aggregator_nationality:
class: Chill\PersonBundle\Export\Aggregator\NationalityAggregator

View File

@ -384,6 +384,10 @@ Filter by user job: Filtrer par métier du référent
Accepted userjob: Métiers
"Filtered by user jobs: only %jobs%": "Filtré par métier du référent: uniquement %jobs%"
Filter by step: Filtrer par statut du parcours
Accepted step: Statuts
"Filtered by steps: only %step%": "Filtré par statut du parcours: uniquement %step%"
## aggregators
Group people by nationality: Aggréger les personnes par nationalités
Group by level: Grouper par niveau
@ -536,9 +540,9 @@ occasional: ponctuel
regular: régulier
Confidential: confidentiel
confidential: confidentiel
Draft: brouillon
Confirmed: en file active
Closed: Cloturé
Draft: Brouillon
Confirmed: En file active
Closed: Clôturé
# Accompanying Course
Accompanying Course: Parcours d'accompagnement