exports: add new MaxDate Filter for evaluation

This commit is contained in:
Mathieu Jaumotte 2022-08-10 10:57:32 +02:00
parent 955d4a9e7a
commit 8efbf02f64
4 changed files with 116 additions and 1 deletions

View File

@ -11,7 +11,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\CustomFieldsBundle\Form\Type\ChoicesType;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Export\FilterInterface;

View File

@ -0,0 +1,103 @@
<?php
namespace Chill\PersonBundle\Export\Filter\EvaluationFilters;
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 MaxDateFilter implements FilterInterface
{
private const MAXDATE_CHOICES = [
'is specified' => true,
'is not specified' => false,
];
private TranslatorInterface $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
/**
* @inheritDoc
*/
public function buildForm(FormBuilderInterface $builder)
{
$builder->add('maxdate', ChoiceType::class, [
'choices' => self::MAXDATE_CHOICES,
'multiple' => false,
'expanded' => true
]);
}
/**
* @inheritDoc
*/
public function getTitle(): string
{
return 'Filter by maxdate';
}
/**
* @inheritDoc
*/
public function describeAction($data, $format = 'string'): array
{
foreach (self::MAXDATE_CHOICES as $k => $v) {
if ($v === $data['maxdate']) {
$choice = $k;
}
}
return ['Filtered by maxdate: only %choice%', [
'%choice%' => $this->translator->trans($choice)
]];
}
/**
* @inheritDoc
*/
public function addRole()
{
return null;
}
/**
* @inheritDoc
*/
public function alterQuery(QueryBuilder $qb, $data)
{
$where = $qb->getDQLPart('where');
if ($data['maxdate'] === true) {
$clause = $qb->expr()->isNotNull('eval.maxDate');
} else {
$clause = $qb->expr()->isNull('eval.maxDate');
}
if ($where instanceof Andx) {
$where->add($clause);
} else {
$where = $qb->expr()->andX($clause);
}
$qb->add('where', $where);
dump($data['maxdate']);
}
/**
* @inheritDoc
*/
public function applyOn(): string
{
return Declarations::EVAL_TYPE;
}
}

View File

@ -16,6 +16,13 @@ services:
tags:
- { name: chill.export_filter, alias: accompanyingcourse_evaluationtype_filter }
chill.person.export.filter_maxdate:
class: Chill\PersonBundle\Export\Filter\EvaluationFilters\MaxDateFilter
autowire: true
autoconfigure: true
tags:
- { name: chill.export_filter, alias: accompanyingcourse_maxdate_filter }
## Aggregators
chill.person.export.aggregator_evaluationtype:
class: Chill\PersonBundle\Export\Aggregator\EvaluationAggregators\EvaluationTypeAggregator

View File

@ -521,6 +521,12 @@ Accepted evaluationtype: Évaluations
Group by evaluation type: Grouper par type d'évaluation
Evaluation type: Type d'évaluation
Filter by maxdate: Filtrer par date d'échéance
Maxdate: ''
is specified: La date d'échéance est spécifiée
is not specified: La date d'échéance n'est pas spécifiée
"Filtered by maxdate: only %choice%": "Filtré par date d'échéance: uniquement si %choice%"
## aggregators
Group people by nationality: Grouper les personnes par nationalités
Group by level: Grouper par niveau