mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Fix activity date filter: validation of form using RollingDate
This commit is contained in:
parent
68f56671a4
commit
6280453523
5
.changes/unreleased/Fixed-20231105-232608.yaml
Normal file
5
.changes/unreleased/Fixed-20231105-232608.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
kind: Fixed
|
||||||
|
body: Fix filter "activity by date"
|
||||||
|
time: 2023-11-05T23:26:08.685518729+01:00
|
||||||
|
custom:
|
||||||
|
Issue: "184"
|
@ -13,16 +13,12 @@ namespace Chill\ActivityBundle\Export\Filter;
|
|||||||
|
|
||||||
use Chill\ActivityBundle\Export\Declarations;
|
use Chill\ActivityBundle\Export\Declarations;
|
||||||
use Chill\MainBundle\Export\FilterInterface;
|
use Chill\MainBundle\Export\FilterInterface;
|
||||||
use Chill\MainBundle\Form\Type\Export\FilterType;
|
|
||||||
use Chill\MainBundle\Form\Type\PickRollingDateType;
|
use Chill\MainBundle\Form\Type\PickRollingDateType;
|
||||||
use Chill\MainBundle\Service\RollingDate\RollingDate;
|
use Chill\MainBundle\Service\RollingDate\RollingDate;
|
||||||
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
|
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
|
||||||
use Doctrine\ORM\Query\Expr;
|
use Doctrine\ORM\Query\Expr;
|
||||||
use Doctrine\ORM\QueryBuilder;
|
use Doctrine\ORM\QueryBuilder;
|
||||||
use Symfony\Component\Form\FormBuilderInterface;
|
use Symfony\Component\Form\FormBuilderInterface;
|
||||||
use Symfony\Component\Form\FormError;
|
|
||||||
use Symfony\Component\Form\FormEvent;
|
|
||||||
use Symfony\Component\Form\FormEvents;
|
|
||||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||||
|
|
||||||
class ActivityDateFilter implements FilterInterface
|
class ActivityDateFilter implements FilterInterface
|
||||||
@ -74,46 +70,6 @@ class ActivityDateFilter implements FilterInterface
|
|||||||
->add('date_to', PickRollingDateType::class, [
|
->add('date_to', PickRollingDateType::class, [
|
||||||
'label' => 'Activities before this date',
|
'label' => 'Activities before this date',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
|
|
||||||
/** @var \Symfony\Component\Form\FormInterface $filterForm */
|
|
||||||
$filterForm = $event->getForm()->getParent();
|
|
||||||
$enabled = $filterForm->get(FilterType::ENABLED_FIELD)->getData();
|
|
||||||
|
|
||||||
if (true === $enabled) {
|
|
||||||
// if the filter is enabled, add some validation
|
|
||||||
$form = $event->getForm();
|
|
||||||
$date_from = $form->get('date_from')->getData();
|
|
||||||
$date_to = $form->get('date_to')->getData();
|
|
||||||
|
|
||||||
// check that fields are not empty
|
|
||||||
if (null === $date_from) {
|
|
||||||
$form->get('date_from')->addError(new FormError(
|
|
||||||
$this->translator->trans('This field '
|
|
||||||
.'should not be empty')
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $date_to) {
|
|
||||||
$form->get('date_to')->addError(new FormError(
|
|
||||||
$this->translator->trans('This field '
|
|
||||||
.'should not be empty')
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
// check that date_from is before date_to
|
|
||||||
if (
|
|
||||||
(null !== $date_from && null !== $date_to)
|
|
||||||
&& $date_from >= $date_to
|
|
||||||
) {
|
|
||||||
$form->get('date_to')->addError(new FormError(
|
|
||||||
$this->translator->trans('This date should be after '
|
|
||||||
.'the date given in "Implied in an activity after '
|
|
||||||
.'this date" field')
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFormDefaultData(): array
|
public function getFormDefaultData(): array
|
||||||
|
Loading…
x
Reference in New Issue
Block a user