mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Feature: [export] Add a rolling date on Acp "by step" filter
This commit is contained in:
parent
8159f91e25
commit
86be95ac43
@ -105,3 +105,8 @@ services:
|
||||
resource: '../Service/Import/'
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
|
||||
Chill\MainBundle\Service\RollingDate\:
|
||||
resource: '../Service/RollingDate/'
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
|
@ -12,31 +12,40 @@ declare(strict_types=1);
|
||||
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
|
||||
|
||||
use Chill\MainBundle\Export\FilterInterface;
|
||||
use Chill\MainBundle\Form\Type\PickRollingDateType;
|
||||
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
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;
|
||||
use function in_array;
|
||||
|
||||
class StepFilter implements FilterInterface
|
||||
{
|
||||
private const A = 'acp_filter_bystep_stephistories';
|
||||
|
||||
private const DEFAULT_CHOICE = AccompanyingPeriod::STEP_CONFIRMED;
|
||||
|
||||
private const P = 'acp_step_filter_date';
|
||||
|
||||
private const STEPS = [
|
||||
'Draft' => AccompanyingPeriod::STEP_DRAFT,
|
||||
'Confirmed' => AccompanyingPeriod::STEP_CONFIRMED,
|
||||
'Closed' => AccompanyingPeriod::STEP_CLOSED,
|
||||
];
|
||||
|
||||
private RollingDateConverterInterface $rollingDateConverter;
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
private $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
public function __construct(RollingDateConverterInterface $rollingDateConverter, TranslatorInterface $translator)
|
||||
{
|
||||
$this->rollingDateConverter = $rollingDateConverter;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
@ -47,17 +56,25 @@ class StepFilter implements FilterInterface
|
||||
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$where = $qb->getDQLPart('where');
|
||||
$clause = $qb->expr()->eq('acp.step', ':step');
|
||||
|
||||
if ($where instanceof Andx) {
|
||||
$where->add($clause);
|
||||
} else {
|
||||
$where = $qb->expr()->andX($clause);
|
||||
if (!in_array(self::A, $qb->getAllAliases(), true)) {
|
||||
$qb->leftJoin('acp.stepHistories', self::A);
|
||||
}
|
||||
|
||||
$qb->add('where', $where);
|
||||
$qb->setParameter('step', $data['accepted_steps']);
|
||||
$qb
|
||||
->andWhere(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->lte(self::A . '.startDate', ':' . self::P),
|
||||
$qb->expr()->orX(
|
||||
$qb->expr()->isNull(self::A . '.endDate'),
|
||||
$qb->expr()->lt(self::A . '.endDate', ':' . self::P)
|
||||
)
|
||||
)
|
||||
)
|
||||
->andWhere(
|
||||
$qb->expr()->in(self::A . '.step', ':acp_filter_by_step_steps')
|
||||
)
|
||||
->setParameter(self::P, $this->rollingDateConverter->convert($data['calc_date']))
|
||||
->setParameter('acp_filter_by_step_steps', $data['accepted_steps']);
|
||||
}
|
||||
|
||||
public function applyOn()
|
||||
@ -67,13 +84,17 @@ class StepFilter implements FilterInterface
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('accepted_steps', ChoiceType::class, [
|
||||
'choices' => self::STEPS,
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'empty_data' => self::DEFAULT_CHOICE,
|
||||
'data' => self::DEFAULT_CHOICE,
|
||||
]);
|
||||
$builder
|
||||
->add('accepted_steps', ChoiceType::class, [
|
||||
'choices' => self::STEPS,
|
||||
'multiple' => false,
|
||||
'expanded' => true,
|
||||
'empty_data' => self::DEFAULT_CHOICE,
|
||||
'data' => self::DEFAULT_CHOICE,
|
||||
])
|
||||
->add('calc_date', PickRollingDateType::class, [
|
||||
'label' => 'export.acp.filter.by_step.date_calc',
|
||||
]);
|
||||
}
|
||||
|
||||
public function describeAction($data, $format = 'string')
|
||||
|
Loading…
x
Reference in New Issue
Block a user