From 68bfb082fc9a482c268fb9100c23c5a2b15bae10 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 14 Nov 2022 15:38:14 +0100 Subject: [PATCH] chill-bundles#25: replace ChillDateType by PickRollingDateType batch/serial replacing untested --- .../Export/Filter/ActivityDateFilter.php | 34 +++++++++++------ .../src/Export/Filter/ByDateFilter.php | 34 +++++++++++------ .../Export/Filter/BetweenDatesFilter.php | 33 ++++++++++------ .../GeographicalUnitStatAggregator.php | 24 ++++++++---- .../ReferrerAggregator.php | 20 ++++++---- .../ReferrerScopeAggregator.php | 20 ++++++---- .../ChildrenNumberAggregator.php | 20 ++++++---- .../CompositionAggregator.php | 20 ++++++---- .../ByHouseholdCompositionAggregator.php | 24 ++++++++---- .../GeographicalUnitAggregator.php | 20 ++++++---- .../HouseholdPositionAggregator.php | 19 +++++++--- .../ActiveOnDateFilter.php | 23 +++++++---- .../ActiveOneDayBetweenDatesFilter.php | 33 ++++++++++------ .../GeographicalUnitStatFilter.php | 22 +++++++---- .../HasNoReferrerFilter.php | 25 ++++++++---- .../HasTemporaryLocationFilter.php | 22 ++++++++--- .../ReferrerFilter.php | 23 +++++++---- .../AccompanyingCourseFilters/StepFilter.php | 8 +++- .../UserJobFilter.php | 20 ++++++---- .../UserScopeFilter.php | 20 ++++++---- .../EvaluationFilters/ByEndDateFilter.php | 33 ++++++++++------ .../EvaluationFilters/ByStartDateFilter.php | 33 ++++++++++------ .../HouseholdFilters/CompositionFilter.php | 22 +++++++---- .../Export/Filter/PersonFilters/AgeFilter.php | 19 +++++++--- .../Filter/PersonFilters/BirthdateFilter.php | 38 +++++++++++++------ .../PersonFilters/DeadOrAliveFilter.php | 21 +++++++--- .../Filter/PersonFilters/DeathdateFilter.php | 33 +++++++++++----- .../PersonFilters/GeographicalUnitFilter.php | 22 +++++++---- .../ResidentialAddressAtThirdpartyFilter.php | 24 ++++++++---- .../ResidentialAddressAtUserFilter.php | 21 +++++++--- .../Export/Filter/ReportDateFilter.php | 33 +++++++++++----- 31 files changed, 512 insertions(+), 251 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ActivityDateFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ActivityDateFilter.php index 1f3a52cc5..edfa9b030 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/ActivityDateFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ActivityDateFilter.php @@ -13,9 +13,10 @@ namespace Chill\ActivityBundle\Export\Filter; use Chill\ActivityBundle\Export\Declarations; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Form\Type\Export\FilterType; -use DateTime; use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -26,11 +27,16 @@ use Symfony\Contracts\Translation\TranslatorInterface; class ActivityDateFilter implements FilterInterface { + private RollingDateConverterInterface $rollingDateConverter; + protected TranslatorInterface $translator; - public function __construct(TranslatorInterface $translator) - { + public function __construct( + TranslatorInterface $translator, + RollingDateConverterInterface $rollingDateConverter + ) { $this->translator = $translator; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -54,8 +60,12 @@ class ActivityDateFilter implements FilterInterface } $qb->add('where', $where); - $qb->setParameter('date_from', $data['date_from']); - $qb->setParameter('date_to', $data['date_to']); + $qb->setParameter('date_from', + $this->rollingDateConverter->convert($data['date_from']) + ); + $qb->setParameter('date_to', + $this->rollingDateConverter->convert($data['date_to']) + ); } public function applyOn(): string @@ -66,13 +76,13 @@ class ActivityDateFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { $builder - ->add('date_from', ChillDateType::class, [ + ->add('date_from', PickRollingDateType::class, [ 'label' => 'Activities after this date', - 'data' => new DateTime(), + 'data' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), ]) - ->add('date_to', ChillDateType::class, [ + ->add('date_to', PickRollingDateType::class, [ 'label' => 'Activities before this date', - 'data' => new DateTime(), + 'data' => new RollingDate(RollingDate::T_TODAY), ]); $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { @@ -121,8 +131,8 @@ class ActivityDateFilter implements FilterInterface return [ 'Filtered by date of activity: only between %date_from% and %date_to%', [ - '%date_from%' => $data['date_from']->format('d-m-Y'), - '%date_to%' => $data['date_to']->format('d-m-Y'), + '%date_from%' => $this->rollingDateConverter->convert($data['date_from'])->format('d-m-Y'), + '%date_to%' => $this->rollingDateConverter->convert($data['date_to'])->format('d-m-Y'), ], ]; } diff --git a/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByDateFilter.php b/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByDateFilter.php index a7595281d..fca4dece8 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByDateFilter.php +++ b/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByDateFilter.php @@ -13,9 +13,10 @@ namespace Chill\AsideActivityBundle\Export\Filter; use Chill\AsideActivityBundle\Export\Declarations; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Form\Type\Export\FilterType; -use DateTime; use Doctrine\ORM\Query\Expr\Andx; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -26,11 +27,16 @@ use Symfony\Contracts\Translation\TranslatorInterface; class ByDateFilter implements FilterInterface { + private RollingDateConverterInterface $rollingDateConverter; + protected TranslatorInterface $translator; - public function __construct(TranslatorInterface $translator) - { + public function __construct( + RollingDateConverterInterface $rollingDateConverter, + TranslatorInterface $translator + ) { $this->translator = $translator; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -54,8 +60,12 @@ class ByDateFilter implements FilterInterface } $qb->add('where', $where); - $qb->setParameter('date_from', $data['date_from']); - $qb->setParameter('date_to', $data['date_to']); + $qb->setParameter('date_from', + $this->rollingDateConverter->convert($data['date_from']) + ); + $qb->setParameter('date_to', + $this->rollingDateConverter->convert($data['date_to']) + ); } public function applyOn(): string @@ -66,13 +76,13 @@ class ByDateFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { $builder - ->add('date_from', ChillDateType::class, [ + ->add('date_from', PickRollingDateType::class, [ 'label' => 'export.filter.Aside activities after this date', - 'data' => new DateTime(), + 'data' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), ]) - ->add('date_to', ChillDateType::class, [ + ->add('date_to', PickRollingDateType::class, [ 'label' => 'export.filter.Aside activities before this date', - 'data' => new DateTime(), + 'data' => new RollingDate(RollingDate::T_TODAY), ]); $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { @@ -119,8 +129,8 @@ class ByDateFilter implements FilterInterface public function describeAction($data, $format = 'string'): array { return ['export.filter.Filtered by aside activities between %dateFrom% and %dateTo%', [ - '%dateFrom%' => $data['date_from']->format('d-m-Y'), - '%dateTo%' => $data['date_to']->format('d-m-Y'), + '%dateFrom%' => $this->rollingDateConverter->convert($data['date_from'])->format('d-m-Y'), + '%dateTo%' => $this->rollingDateConverter->convert($data['date_to'])->format('d-m-Y'), ]]; } diff --git a/src/Bundle/ChillCalendarBundle/Export/Filter/BetweenDatesFilter.php b/src/Bundle/ChillCalendarBundle/Export/Filter/BetweenDatesFilter.php index 65707d9e4..01bfad033 100644 --- a/src/Bundle/ChillCalendarBundle/Export/Filter/BetweenDatesFilter.php +++ b/src/Bundle/ChillCalendarBundle/Export/Filter/BetweenDatesFilter.php @@ -13,15 +13,22 @@ namespace Chill\CalendarBundle\Export\Filter; use Chill\CalendarBundle\Export\Declarations; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; -use DateTime; -use Doctrine\DBAL\Types\Types; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Doctrine\ORM\Query\Expr\Andx; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; class BetweenDatesFilter implements FilterInterface { + private RollingDateConverterInterface $rollingDateConverter; + + public function __construct(RollingDateConverterInterface $rollingDateConverter) + { + $this->rollingDateConverter = $rollingDateConverter; + } + public function addRole(): ?string { return null; @@ -43,9 +50,13 @@ class BetweenDatesFilter implements FilterInterface } $qb->add('where', $where); - $qb->setParameter('dateFrom', $data['date_from'], Types::DATE_MUTABLE); + $qb->setParameter('dateFrom', + $this->rollingDateConverter->convert($data['date_from']) + ); // modify dateTo so that entire day is also taken into account up until the beginning of the next day. - $qb->setParameter('dateTo', $data['date_to']->modify('+1 day'), Types::DATE_MUTABLE); + $qb->setParameter('dateTo', + $this->rollingDateConverter->convert($data['date_to'])->modify('+1 day') + ); } public function applyOn(): string @@ -56,19 +67,19 @@ class BetweenDatesFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { $builder - ->add('date_from', ChillDateType::class, [ - 'data' => new DateTime(), + ->add('date_from', PickRollingDateType::class, [ + 'data' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), ]) - ->add('date_to', ChillDateType::class, [ - 'data' => new DateTime(), + ->add('date_to', PickRollingDateType::class, [ + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } public function describeAction($data, $format = 'string'): array { return ['Filtered by appointments between %dateFrom% and %dateTo%', [ - '%dateFrom%' => $data['date_from']->format('d-m-Y'), - '%dateTo%' => $data['date_to']->format('d-m-Y'), + '%dateFrom%' => $this->rollingDateConverter->convert($data['date_from'])->format('d-m-Y'), + '%dateTo%' => $this->rollingDateConverter->convert($data['date_to'])->format('d-m-Y'), ]]; } diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/GeographicalUnitStatAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/GeographicalUnitStatAggregator.php index 891ce63e0..59a39ab12 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/GeographicalUnitStatAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/GeographicalUnitStatAggregator.php @@ -15,12 +15,13 @@ use Chill\MainBundle\Entity\Address; use Chill\MainBundle\Entity\GeographicalUnit; use Chill\MainBundle\Entity\GeographicalUnitLayer; use Chill\MainBundle\Export\AggregatorInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Repository\GeographicalUnitLayerRepositoryInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress; use Chill\PersonBundle\Export\Declarations; -use DateTimeImmutable; use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; @@ -34,12 +35,16 @@ final class GeographicalUnitStatAggregator implements AggregatorInterface private TranslatableStringHelperInterface $translatableStringHelper; + private RollingDateConverterInterface $rollingDateConverter; + public function __construct( GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository, - TranslatableStringHelperInterface $translatableStringHelper + TranslatableStringHelperInterface $translatableStringHelper, + RollingDateConverterInterface $rollingDateConverter ) { $this->geographicalUnitLayerRepository = $geographicalUnitLayerRepository; $this->translatableStringHelper = $translatableStringHelper; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -62,7 +67,9 @@ final class GeographicalUnitStatAggregator implements AggregatorInterface ) ); - $qb->setParameter('acp_geog_aggregator_date', $data['date_calc']); + $qb->setParameter('acp_geog_aggregator_date', + $this->rollingDateConverter->convert($data['date_calc']) + ); } // link between location history and person @@ -81,7 +88,9 @@ final class GeographicalUnitStatAggregator implements AggregatorInterface ) ); - $qb->setParameter('acp_geog_aggregator_date', $data['date_calc']); + $qb->setParameter('acp_geog_aggregator_date', + $this->rollingDateConverter->convert($data['date_calc']) + ); } // we finally find an address @@ -122,11 +131,10 @@ final class GeographicalUnitStatAggregator implements AggregatorInterface public function buildForm(FormBuilderInterface $builder) { $builder - ->add('date_calc', ChillDateType::class, [ + ->add('date_calc', PickRollingDateType::class, [ 'label' => 'Compute geographical location at date', 'required' => true, - 'data' => new DateTimeImmutable('today'), - 'input' => 'datetime_immutable', + 'data' => new RollingDate(RollingDate::T_TODAY), ]) ->add('level', EntityType::class, [ 'label' => 'Geographical layer', diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerAggregator.php index 327b76a65..84da976c6 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerAggregator.php @@ -12,11 +12,12 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators; use Chill\MainBundle\Export\AggregatorInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Repository\UserRepository; use Chill\MainBundle\Templating\Entity\UserRender; use Chill\PersonBundle\Export\Declarations; -use DateTimeImmutable; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -30,12 +31,16 @@ final class ReferrerAggregator implements AggregatorInterface private UserRepository $userRepository; + private RollingDateConverterInterface $rollingDateConverter; + public function __construct( UserRepository $userRepository, - UserRender $userRender + UserRender $userRender, + RollingDateConverterInterface $rollingDateConverter ) { $this->userRepository = $userRepository; $this->userRender = $userRender; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -61,7 +66,9 @@ final class ReferrerAggregator implements AggregatorInterface ) ) ) - ->setParameter(self::P, $data['date_calc']); + ->setParameter(self::P, + $this->rollingDateConverter->convert($data['date_calc']) + ); } public function applyOn(): string @@ -72,9 +79,8 @@ final class ReferrerAggregator implements AggregatorInterface public function buildForm(FormBuilderInterface $builder) { $builder - ->add('date_calc', ChillDateType::class, [ - 'input' => 'datetime_immutable', - 'data' => new DateTimeImmutable('now'), + ->add('date_calc', PickRollingDateType::class, [ + 'data' => new RollingDate(RollingDate::T_TODAY), 'label' => 'export.aggregator.course.by_referrer.Computation date for referrer', 'required' => true, ]); diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregator.php index 506bee66f..16ff76e3d 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregator.php @@ -12,11 +12,12 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators; use Chill\MainBundle\Export\AggregatorInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Repository\ScopeRepositoryInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Export\Declarations; -use DateTimeImmutable; use Doctrine\ORM\QueryBuilder; use LogicException; use Symfony\Component\Form\FormBuilderInterface; @@ -29,12 +30,16 @@ class ReferrerScopeAggregator implements AggregatorInterface private TranslatableStringHelperInterface $translatableStringHelper; + private RollingDateConverterInterface $rollingDateConverter; + public function __construct( ScopeRepositoryInterface $scopeRepository, - TranslatableStringHelperInterface $translatableStringHelper + TranslatableStringHelperInterface $translatableStringHelper, + RollingDateConverterInterface $rollingDateConverter ) { $this->scopeRepository = $scopeRepository; $this->translatableStringHelper = $translatableStringHelper; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -64,7 +69,9 @@ class ReferrerScopeAggregator implements AggregatorInterface ) ) ) - ->setParameter($dateCalc, $data['date_calc']); + ->setParameter($dateCalc, + $this->rollingDateConverter->convert($data['date_calc']) + ); // add groups $qb @@ -79,9 +86,8 @@ class ReferrerScopeAggregator implements AggregatorInterface public function buildForm(FormBuilderInterface $builder) { - $builder->add('date_calc', ChillDateType::class, [ - 'input' => 'datetime_immutable', - 'data' => new DateTimeImmutable('now'), + $builder->add('date_calc', PickRollingDateType::class, [ + 'data' => new RollingDate(RollingDate::T_TODAY), 'label' => 'export.aggregator.course.by_user_scope.Computation date for referrer', 'required' => true, ]); diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php index 8024cb08b..aa2e9b4b6 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php @@ -12,10 +12,10 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Aggregator\HouseholdAggregators; use Chill\MainBundle\Export\AggregatorInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\PersonBundle\Export\Declarations; -use DateTime; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -26,10 +26,14 @@ class ChildrenNumberAggregator implements AggregatorInterface { private TranslatorInterface $translator; + private RollingDateConverterInterface $rollingDateConverter; + public function __construct( - TranslatorInterface $translator + TranslatorInterface $translator, + RollingDateConverterInterface $rollingDateConverter ) { $this->translator = $translator; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -55,7 +59,9 @@ class ChildrenNumberAggregator implements AggregatorInterface ->addSelect('composition_children.numberOfChildren AS childrennumber_aggregator') ->addGroupBy('childrennumber_aggregator'); - $qb->setParameter('ondate_composition_children', $data['on_date'], Types::DATE_MUTABLE); + $qb->setParameter('ondate_composition_children', + $this->rollingDateConverter->convert($data['on_date']) + ); } public function applyOn(): string @@ -65,8 +71,8 @@ class ChildrenNumberAggregator implements AggregatorInterface public function buildForm(FormBuilderInterface $builder) { - $builder->add('on_date', ChillDateType::class, [ - 'data' => new DateTime('now'), + $builder->add('on_date', PickRollingDateType::class, [ + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php index ad7b7030f..1917a51b3 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php @@ -12,12 +12,12 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Aggregator\HouseholdAggregators; use Chill\MainBundle\Export\AggregatorInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Repository\Household\HouseholdCompositionTypeRepository; -use DateTime; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -29,12 +29,16 @@ class CompositionAggregator implements AggregatorInterface private HouseholdCompositionTypeRepository $typeRepository; + private RollingDateConverterInterface $rollingDateConverter; + public function __construct( HouseholdCompositionTypeRepository $typeRepository, - TranslatableStringHelper $translatableStringHelper + TranslatableStringHelper $translatableStringHelper, + RollingDateConverterInterface $rollingDateConverter ) { $this->typeRepository = $typeRepository; $this->translatableStringHelper = $translatableStringHelper; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -60,7 +64,9 @@ class CompositionAggregator implements AggregatorInterface ->addSelect('IDENTITY(composition_type.householdCompositionType) AS composition_aggregator') ->addGroupBy('composition_aggregator'); - $qb->setParameter('ondate_composition_type', $data['on_date'], Types::DATE_MUTABLE); + $qb->setParameter('ondate_composition_type', + $this->rollingDateConverter->convert($data['on_date']) + ); } public function applyOn(): string @@ -70,8 +76,8 @@ class CompositionAggregator implements AggregatorInterface public function buildForm(FormBuilderInterface $builder) { - $builder->add('on_date', ChillDateType::class, [ - 'data' => new DateTime('now'), + $builder->add('on_date', PickRollingDateType::class, [ + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/ByHouseholdCompositionAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/ByHouseholdCompositionAggregator.php index 7a1aaaa49..576f52626 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/ByHouseholdCompositionAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/ByHouseholdCompositionAggregator.php @@ -12,12 +12,13 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators; use Chill\MainBundle\Export\AggregatorInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\Household\HouseholdComposition; use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Repository\Household\HouseholdCompositionTypeRepositoryInterface; -use DateTimeImmutable; use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -30,10 +31,16 @@ class ByHouseholdCompositionAggregator implements AggregatorInterface private TranslatableStringHelperInterface $translatableStringHelper; - public function __construct(HouseholdCompositionTypeRepositoryInterface $householdCompositionTypeRepository, TranslatableStringHelperInterface $translatableStringHelper) - { + private RollingDateConverterInterface $rollingDateConverter; + + public function __construct( + RollingDateConverterInterface $rollingDateConverter, + HouseholdCompositionTypeRepositoryInterface $householdCompositionTypeRepository, + TranslatableStringHelperInterface $translatableStringHelper + ) { $this->householdCompositionTypeRepository = $householdCompositionTypeRepository; $this->translatableStringHelper = $translatableStringHelper; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -71,7 +78,9 @@ class ByHouseholdCompositionAggregator implements AggregatorInterface ) ) ->addSelect("IDENTITY({$p}_compo.householdCompositionType) AS {$p}_select") - ->setParameter("{$p}_date", $data['date_calc']) + ->setParameter("{$p}_date", + $this->rollingDateConverter->convert($data['date_calc']) + ) ->addGroupBy("{$p}_select"); } @@ -82,10 +91,9 @@ class ByHouseholdCompositionAggregator implements AggregatorInterface public function buildForm(FormBuilderInterface $builder) { - $builder->add('date_calc', ChillDateType::class, [ + $builder->add('date_calc', PickRollingDateType::class, [ 'label' => 'export.aggregator.person.by_household_composition.Calc date', - 'input_format' => 'datetime_immutable', - 'data' => new DateTimeImmutable('now'), + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/GeographicalUnitAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/GeographicalUnitAggregator.php index 3513625e9..dd6f10035 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/GeographicalUnitAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/GeographicalUnitAggregator.php @@ -14,11 +14,12 @@ namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators; use Chill\MainBundle\Entity\GeographicalUnit; use Chill\MainBundle\Entity\GeographicalUnitLayer; use Chill\MainBundle\Export\AggregatorInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Repository\GeographicalUnitLayerRepositoryInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Export\Declarations; -use DateTimeImmutable; use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\QueryBuilder; use LogicException; @@ -31,12 +32,16 @@ class GeographicalUnitAggregator implements AggregatorInterface private TranslatableStringHelperInterface $translatableStringHelper; + private RollingDateConverterInterface $rollingDateConverter; + public function __construct( GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository, - TranslatableStringHelperInterface $translatableStringHelper + TranslatableStringHelperInterface $translatableStringHelper, + RollingDateConverterInterface $rollingDateConverter ) { $this->geographicalUnitLayerRepository = $geographicalUnitLayerRepository; $this->translatableStringHelper = $translatableStringHelper; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -68,7 +73,9 @@ class GeographicalUnitAggregator implements AggregatorInterface $qb->expr()->in('person_geog_agg_geog_unit.layer', ':person_geog_agg_layers') ) ) - ->setParameter('person_geog_agg_date', $data['date_calc']) + ->setParameter('person_geog_agg_date', + $this->rollingDateConverter->convert($data['date_calc']) + ) ->setParameter('person_geog_agg_layers', $data['level']) ->addSelect('person_geog_agg_geog_unit.unitName AS geog_unit_name') ->addSelect('person_geog_agg_geog_unit.unitRefId AS geog_unit_key') @@ -84,11 +91,10 @@ class GeographicalUnitAggregator implements AggregatorInterface public function buildForm(FormBuilderInterface $builder) { $builder - ->add('date_calc', ChillDateType::class, [ + ->add('date_calc', PickRollingDateType::class, [ 'label' => 'Address valid at this date', 'required' => true, - 'data' => new DateTimeImmutable('today'), - 'input' => 'datetime_immutable', + 'data' => new RollingDate(RollingDate::T_TODAY), ]) ->add('level', EntityType::class, [ 'label' => 'Geographical layer', diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/HouseholdPositionAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/HouseholdPositionAggregator.php index 2001466ab..0d986bdea 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/HouseholdPositionAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/HouseholdPositionAggregator.php @@ -13,12 +13,13 @@ namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators; use Chill\MainBundle\Export\AggregatorInterface; use Chill\MainBundle\Export\ExportElementValidatedInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Entity\Household\HouseholdMember; use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Repository\Household\PositionRepository; -use DateTime; use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -34,14 +35,18 @@ final class HouseholdPositionAggregator implements AggregatorInterface, ExportEl private TranslatorInterface $translator; + private RollingDateConverterInterface $rollingDateConverter; + public function __construct( TranslatorInterface $translator, TranslatableStringHelper $translatableStringHelper, - PositionRepository $positionRepository + PositionRepository $positionRepository, + RollingDateConverterInterface $rollingDateConverter ) { $this->translator = $translator; $this->positionRepository = $positionRepository; $this->translatableStringHelper = $translatableStringHelper; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -67,7 +72,9 @@ final class HouseholdPositionAggregator implements AggregatorInterface, ExportEl ) )); - $qb->setParameter('date', $data['date_position']); + $qb->setParameter('date', + $this->rollingDateConverter->convert($data['date_position']) + ); $qb->addSelect('IDENTITY(householdmember.position) AS household_position_aggregator'); $qb->addGroupBy('household_position_aggregator'); @@ -80,9 +87,9 @@ final class HouseholdPositionAggregator implements AggregatorInterface, ExportEl public function buildForm(FormBuilderInterface $builder) { - $builder->add('date_position', ChillDateType::class, [ + $builder->add('date_position', PickRollingDateType::class, [ 'label' => 'Household position in relation to this date', - 'data' => new DateTime(), + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ActiveOnDateFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ActiveOnDateFilter.php index 7fa92c0ae..55fe56d59 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ActiveOnDateFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ActiveOnDateFilter.php @@ -12,16 +12,23 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\PersonBundle\Export\Declarations; -use DateTime; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Query\Expr\Andx; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; class ActiveOnDateFilter implements FilterInterface { + private RollingDateConverterInterface $rollingDateConverter; + + public function __construct(RollingDateConverterInterface $rollingDateConverter) + { + $this->rollingDateConverter = $rollingDateConverter; + } + public function addRole(): ?string { return null; @@ -46,7 +53,9 @@ class ActiveOnDateFilter implements FilterInterface } $qb->add('where', $where); - $qb->setParameter('ondate', $data['on_date'], Types::DATE_MUTABLE); + $qb->setParameter('ondate', + $this->rollingDateConverter->convert($data['on_date']) + ); } public function applyOn(): string @@ -57,15 +66,15 @@ class ActiveOnDateFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { $builder - ->add('on_date', ChillDateType::class, [ - 'data' => new DateTime(), + ->add('on_date', PickRollingDateType::class, [ + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } public function describeAction($data, $format = 'string'): array { return ['Filtered by actives courses: active on %ondate%', [ - '%ondate%' => $data['on_date']->format('d-m-Y'), + '%ondate%' => $this->rollingDateConverter->convert($data['on_date'])->format('d-m-Y'), ]]; } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ActiveOneDayBetweenDatesFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ActiveOneDayBetweenDatesFilter.php index bf6698f60..4d1a9ad23 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ActiveOneDayBetweenDatesFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ActiveOneDayBetweenDatesFilter.php @@ -12,15 +12,22 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\PersonBundle\Export\Declarations; -use DateTime; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; class ActiveOneDayBetweenDatesFilter implements FilterInterface { + private RollingDateConverterInterface $rollingDateConverter; + + public function __construct(RollingDateConverterInterface $rollingDateConverter) + { + $this->rollingDateConverter = $rollingDateConverter; + } + public function addRole(): ?string { return null; @@ -31,8 +38,12 @@ class ActiveOneDayBetweenDatesFilter implements FilterInterface $clause = "OVERLAPSI (acp.openingDate, acp.closingDate), (:datefrom, :dateto) = 'TRUE'"; $qb->andWhere($clause); - $qb->setParameter('datefrom', $data['date_from'], Types::DATE_MUTABLE); - $qb->setParameter('dateto', $data['date_to'], Types::DATE_MUTABLE); + $qb->setParameter('datefrom', + $this->rollingDateConverter->convert($data['date_from']) + ); + $qb->setParameter('dateto', + $this->rollingDateConverter->convert($data['date_to']) + ); } public function applyOn(): string @@ -43,19 +54,19 @@ class ActiveOneDayBetweenDatesFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { $builder - ->add('date_from', ChillDateType::class, [ - 'data' => new DateTime(), + ->add('date_from', PickRollingDateType::class, [ + 'data' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), ]) - ->add('date_to', ChillDateType::class, [ - 'data' => new DateTime(), + ->add('date_to', PickRollingDateType::class, [ + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } public function describeAction($data, $format = 'string'): array { return ['Filtered by actives courses: at least one day between %datefrom% and %dateto%', [ - '%datefrom%' => $data['date_from']->format('d-m-Y'), - '%dateto%' => $data['date_to']->format('d-m-Y'), + '%datefrom%' => $this->rollingDateConverter->convert($data['date_from'])->format('d-m-Y'), + '%dateto%' => $this->rollingDateConverter->convert($data['date_to'])->format('d-m-Y'), ]]; } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php index ee420e63e..55e710f8e 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php @@ -15,14 +15,15 @@ use Chill\MainBundle\Entity\Address; use Chill\MainBundle\Entity\GeographicalUnit; use Chill\MainBundle\Entity\GeographicalUnit\SimpleGeographicalUnitDTO; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Repository\GeographicalUnitLayerRepositoryInterface; use Chill\MainBundle\Repository\GeographicalUnitRepositoryInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress; use Chill\PersonBundle\Export\Declarations; -use DateTimeImmutable; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; @@ -41,16 +42,20 @@ class GeographicalUnitStatFilter implements FilterInterface private TranslatableStringHelperInterface $translatableStringHelper; + private RollingDateConverterInterface $rollingDateConverter; + public function __construct( EntityManagerInterface $em, GeographicalUnitRepositoryInterface $geographicalUnitRepository, GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository, - TranslatableStringHelperInterface $translatableStringHelper + TranslatableStringHelperInterface $translatableStringHelper, + RollingDateConverterInterface $rollingDateConverter ) { $this->em = $em; $this->geographicalUnitRepository = $geographicalUnitRepository; $this->geographicalUnitLayerRepository = $geographicalUnitLayerRepository; $this->translatableStringHelper = $translatableStringHelper; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -83,7 +88,9 @@ class GeographicalUnitStatFilter implements FilterInterface $qb ->andWhere($qb->expr()->exists($subQueryDql)) - ->setParameter('acp_geog_filter_date', $data['date_calc']) + ->setParameter('acp_geog_filter_date', + $this->rollingDateConverter->convert($data['date_calc']) + ) ->setParameter('acp_geog_filter_units', array_map(static fn (SimpleGeographicalUnitDTO $unitDTO) => $unitDTO->id, $data['units'])); } @@ -95,11 +102,10 @@ class GeographicalUnitStatFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { $builder - ->add('date_calc', ChillDateType::class, [ + ->add('date_calc', PickRollingDateType::class, [ 'label' => 'Compute geographical location at date', 'required' => true, - 'data' => new DateTimeImmutable('today'), - 'input' => 'datetime_immutable', + 'data' => new RollingDate(RollingDate::T_TODAY), ]) ->add('units', ChoiceType::class, [ 'label' => 'Geographical unit', @@ -119,7 +125,7 @@ class GeographicalUnitStatFilter implements FilterInterface public function describeAction($data, $format = 'string'): array { return ['Filtered by geographic unit: computed at %date%, only in %units%', [ - '%date%' => $data['date_calc']->format('d-m-Y'), + '%date%' => $this->rollingDateConverter->convert($data['date_calc'])->format('d-m-Y'), '%units' => implode( ', ', array_map( diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasNoReferrerFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasNoReferrerFilter.php index 303c789af..ff30b6312 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasNoReferrerFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasNoReferrerFilter.php @@ -12,16 +12,24 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod\UserHistory; use Chill\PersonBundle\Export\Declarations; -use DateTimeImmutable; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; class HasNoReferrerFilter implements FilterInterface { + private RollingDateConverterInterface $rollingDateConverter; + + public function __construct( + RollingDateConverterInterface $rollingDateConverter + ) { + $this->rollingDateConverter = $rollingDateConverter; + } + public function addRole(): ?string { return null; @@ -41,7 +49,9 @@ class HasNoReferrerFilter implements FilterInterface AND uh.accompanyingPeriod = acp ) ') - ->setParameter('has_no_referrer_filter_date', $data['calc_date'], Types::DATE_IMMUTABLE); + ->setParameter('has_no_referrer_filter_date', + $this->rollingDateConverter->convert($data['calc_date']) + ); } public function applyOn(): string @@ -52,17 +62,16 @@ class HasNoReferrerFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder) { $builder - ->add('calc_date', ChillDateType::class, [ + ->add('calc_date', PickRollingDateType::class, [ 'label' => 'Has no referrer on this date', - 'data' => new DateTimeImmutable(), - 'input' => 'datetime_immutable', + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } public function describeAction($data, $format = 'string'): array { return ['Filtered acp which has no referrer on date: %date%', [ - '%date%' => $data['calc_date']->format('d-m-Y'), + '%date%' => $this->rollingDateConverter->convert($data['calc_date'])->format('d-m-Y'), ]]; } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasTemporaryLocationFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasTemporaryLocationFilter.php index 2ae1ad2a0..3dfbea9c2 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasTemporaryLocationFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasTemporaryLocationFilter.php @@ -12,9 +12,10 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\PersonBundle\Export\Declarations; -use DateTimeImmutable; use Doctrine\ORM\QueryBuilder; use LogicException; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; @@ -22,6 +23,14 @@ use Symfony\Component\Form\FormBuilderInterface; class HasTemporaryLocationFilter implements FilterInterface { + private RollingDateConverterInterface $rollingDateConverter; + + public function __construct( + RollingDateConverterInterface $rollingDateConverter + ) { + $this->rollingDateConverter = $rollingDateConverter; + } + public function addRole(): ?string { return null; @@ -33,7 +42,9 @@ class HasTemporaryLocationFilter implements FilterInterface ->join('acp.locationHistories', 'acp_having_temporarily_location') ->andWhere('acp_having_temporarily_location.startDate <= :acp_having_temporarily_location_date AND (acp_having_temporarily_location.endDate IS NULL OR acp_having_temporarily_location.endDate > :acp_having_temporarily_location_date)') - ->setParameter('acp_having_temporarily_location_date', $data['calc_date']); + ->setParameter('acp_having_temporarily_location_date', + $this->rollingDateConverter->convert($data['calc_date']) + ); switch ($data['having_temporarily']) { case true: @@ -77,10 +88,9 @@ class HasTemporaryLocationFilter implements FilterInterface } }, ]) - ->add('calc_date', ChillDateType::class, [ + ->add('calc_date', PickRollingDateType::class, [ 'label' => 'export.filter.course.having_temporarily.Calculation date', - 'input' => 'datetime_immutable', - 'data' => new DateTimeImmutable(), + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ReferrerFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ReferrerFilter.php index 7d1aabc22..5e1ad18b9 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ReferrerFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ReferrerFilter.php @@ -12,11 +12,12 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Form\Type\PickUserDynamicType; use Chill\MainBundle\Templating\Entity\UserRender; use Chill\PersonBundle\Export\Declarations; -use DateTimeImmutable; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -30,9 +31,14 @@ class ReferrerFilter implements FilterInterface private UserRender $userRender; - public function __construct(UserRender $userRender) - { + private RollingDateConverterInterface $rollingDateConverter; + + public function __construct( + UserRender $userRender, + RollingDateConverterInterface $rollingDateConverter + ) { $this->userRender = $userRender; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -57,7 +63,9 @@ class ReferrerFilter implements FilterInterface $qb->expr()->in(self::A . '.user', ':' . self::PU) ) ->setParameter(self::PU, $data['accepted_referrers']) - ->setParameter(self::P, $data['date_calc']); + ->setParameter(self::P, + $this->rollingDateConverter->convert($data['date_calc']) + ); } public function applyOn(): string @@ -71,9 +79,8 @@ class ReferrerFilter implements FilterInterface ->add('accepted_referrers', PickUserDynamicType::class, [ 'multiple' => true, ]) - ->add('date_calc', ChillDateType::class, [ - 'input' => 'datetime_immutable', - 'data' => new DateTimeImmutable('now'), + ->add('date_calc', PickRollingDateType::class, [ + 'data' => new RollingDate(RollingDate::T_TODAY), 'label' => 'export.filter.course.by_referrer.Computation date for referrer', 'required' => true, ]); diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/StepFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/StepFilter.php index 0c9b28e8c..240b093b5 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/StepFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/StepFilter.php @@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Export\Declarations; @@ -43,8 +44,10 @@ class StepFilter implements FilterInterface */ private $translator; - public function __construct(RollingDateConverterInterface $rollingDateConverter, TranslatorInterface $translator) - { + public function __construct( + RollingDateConverterInterface $rollingDateConverter, + TranslatorInterface $translator + ) { $this->rollingDateConverter = $rollingDateConverter; $this->translator = $translator; } @@ -94,6 +97,7 @@ class StepFilter implements FilterInterface ]) ->add('calc_date', PickRollingDateType::class, [ 'label' => 'export.acp.filter.by_step.date_calc', + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php index a18442c2a..fadc5d295 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php @@ -14,11 +14,12 @@ namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\UserJob; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Repository\UserJobRepositoryInterface; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Export\Declarations; -use DateTimeImmutable; use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\FormBuilderInterface; @@ -40,14 +41,18 @@ class UserJobFilter implements FilterInterface private UserJobRepositoryInterface $userJobRepository; + private RollingDateConverterInterface $rollingDateConverter; + public function __construct( Security $security, TranslatableStringHelper $translatableStringHelper, - UserJobRepositoryInterface $userJobRepository + UserJobRepositoryInterface $userJobRepository, + RollingDateConverterInterface $rollingDateConverter ) { $this->security = $security; $this->translatableStringHelper = $translatableStringHelper; $this->userJobRepository = $userJobRepository; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -68,7 +73,9 @@ class UserJobFilter implements FilterInterface ) ) ) - ->setParameter(self::P, $data['date_calc']) + ->setParameter(self::P, + $this->rollingDateConverter->convert($data['date_calc']) + ) ->join(self::A . '.user', self::AU) ->andWhere( $qb->expr()->in(self::AU . '.userJob', ':' . self::PJ) @@ -92,9 +99,8 @@ class UserJobFilter implements FilterInterface 'choice_label' => fn (UserJob $job) => $this->translatableStringHelper->localize($job->getLabel()), 'label' => 'Job', ]) - ->add('date_calc', ChillDateType::class, [ - 'input' => 'datetime_immutable', - 'data' => new DateTimeImmutable('now'), + ->add('date_calc', PickRollingDateType::class, [ + 'data' => new RollingDate(RollingDate::T_TODAY), 'label' => 'export.filter.course.by_user_scope.Computation date for referrer', 'required' => true, ]); diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserScopeFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserScopeFilter.php index 48a97f9f7..3fcf4f87e 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserScopeFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserScopeFilter.php @@ -14,11 +14,12 @@ namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Repository\ScopeRepositoryInterface; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Export\Declarations; -use DateTimeImmutable; use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Component\Form\FormBuilderInterface; @@ -40,14 +41,18 @@ class UserScopeFilter implements FilterInterface private TranslatableStringHelper $translatableStringHelper; + private RollingDateConverterInterface $rollingDateConverter; + public function __construct( ScopeRepositoryInterface $scopeRepository, Security $security, - TranslatableStringHelper $translatableStringHelper + TranslatableStringHelper $translatableStringHelper, + RollingDateConverterInterface $rollingDateConverter ) { $this->scopeRepository = $scopeRepository; $this->security = $security; $this->translatableStringHelper = $translatableStringHelper; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -68,7 +73,9 @@ class UserScopeFilter implements FilterInterface ) ) ) - ->setParameter(self::P, $data['date_calc']) + ->setParameter(self::P, + $this->rollingDateConverter->convert($data['date_calc']) + ) ->join(self::A . '.user', self::AU) ->andWhere( $qb->expr()->in(self::AU . '.mainScope', ':' . self::PS) @@ -91,9 +98,8 @@ class UserScopeFilter implements FilterInterface 'multiple' => true, 'expanded' => true, ]) - ->add('date_calc', ChillDateType::class, [ - 'input' => 'datetime_immutable', - 'data' => new DateTimeImmutable('now'), + ->add('date_calc', PickRollingDateType::class, [ + 'data' => new RollingDate(RollingDate::T_TODAY), 'label' => 'export.filter.course.by_user_scope.Computation date for referrer', 'required' => true, ]); diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByEndDateFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByEndDateFilter.php index f828da109..5021da1bc 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByEndDateFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByEndDateFilter.php @@ -12,15 +12,23 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\EvaluationFilters; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\PersonBundle\Export\Declarations; use DateTimeImmutable; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; class ByEndDateFilter implements FilterInterface { + private RollingDateConverterInterface $rollingDateConverter; + + public function __construct(RollingDateConverterInterface $rollingDateConverter) + { + $this->rollingDateConverter = $rollingDateConverter; + } + public function addRole(): ?string { return null; @@ -30,8 +38,12 @@ class ByEndDateFilter implements FilterInterface { $qb ->andWhere('workeval.endDate BETWEEN :work_eval_by_end_date_start_date and :work_eval_by_end_date_end_date') - ->setParameter('work_eval_by_end_date_start_date', $data['start_date'], Types::DATE_IMMUTABLE) - ->setParameter('work_eval_by_end_date_end_date', $data['end_date'], Types::DATE_IMMUTABLE); + ->setParameter('work_eval_by_end_date_start_date', + $this->rollingDateConverter->convert($data['start_date']) + ) + ->setParameter('work_eval_by_end_date_end_date', + $this->rollingDateConverter->convert($data['end_date']) + ); } public function applyOn(): string @@ -42,23 +54,22 @@ class ByEndDateFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder): void { $builder - ->add('start_date', ChillDateType::class, [ + ->add('start_date', PickRollingDateType::class, [ 'label' => 'start period date', - 'data' => new DateTimeImmutable('1 year ago'), + 'data' => new RollingDate(RollingDate::T_TODAY, new DateTimeImmutable('1 year ago')), 'input' => 'datetime_immutable', ]) - ->add('end_date', ChillDateType::class, [ + ->add('end_date', PickRollingDateType::class, [ 'label' => 'end period date', - 'data' => new DateTimeImmutable(), - 'input' => 'datetime_immutable', + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } public function describeAction($data, $format = 'string'): array { return ['Filtered by end date: between %start_date% and %end_date%', [ - '%start_date%' => $data['start_date']->format('d-m-Y'), - '%end_date%' => $data['end_date']->format('d-m-Y'), + '%start_date%' => $this->rollingDateConverter->convert($data['start_date'])->format('d-m-Y'), + '%end_date%' => $this->rollingDateConverter->convert($data['end_date'])->format('d-m-Y'), ]]; } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByStartDateFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByStartDateFilter.php index f12b5e805..c5c4c8899 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByStartDateFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByStartDateFilter.php @@ -12,15 +12,23 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\EvaluationFilters; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\PersonBundle\Export\Declarations; use DateTimeImmutable; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; class ByStartDateFilter implements FilterInterface { + private RollingDateConverterInterface $rollingDateConverter; + + public function __construct(RollingDateConverterInterface $rollingDateConverter) + { + $this->rollingDateConverter = $rollingDateConverter; + } + public function addRole(): ?string { return null; @@ -30,8 +38,12 @@ class ByStartDateFilter implements FilterInterface { $qb ->andWhere('workeval.startDate BETWEEN :work_eval_by_start_date_start_date and :work_eval_by_start_date_end_date') - ->setParameter('work_eval_by_start_date_start_date', $data['start_date'], Types::DATE_IMMUTABLE) - ->setParameter('work_eval_by_start_date_end_date', $data['end_date'], Types::DATE_IMMUTABLE); + ->setParameter('work_eval_by_start_date_start_date', + $this->rollingDateConverter->convert($data['start_date']) + ) + ->setParameter('work_eval_by_start_date_end_date', + $this->rollingDateConverter->convert($data['end_date']) + ); } public function applyOn(): string @@ -42,23 +54,22 @@ class ByStartDateFilter implements FilterInterface public function buildForm(FormBuilderInterface $builder): void { $builder - ->add('start_date', ChillDateType::class, [ + ->add('start_date', PickRollingDateType::class, [ 'label' => 'start period date', - 'data' => new DateTimeImmutable('1 year ago'), + 'data' => new RollingDate(RollingDate::T_TODAY, new DateTimeImmutable('1 year ago')), 'input' => 'datetime_immutable', ]) - ->add('end_date', ChillDateType::class, [ + ->add('end_date', PickRollingDateType::class, [ 'label' => 'end period date', - 'data' => new DateTimeImmutable(), - 'input' => 'datetime_immutable', + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } public function describeAction($data, $format = 'string'): array { return ['Filtered by start date: between %start_date% and %end_date%', [ - '%start_date%' => $data['start_date']->format('d-m-Y'), - '%end_date%' => $data['end_date']->format('d-m-Y'), + '%start_date%' => $this->rollingDateConverter->convert($data['start_date'])->format('d-m-Y'), + '%end_date%' => $this->rollingDateConverter->convert($data['end_date'])->format('d-m-Y'), ]]; } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/HouseholdFilters/CompositionFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/HouseholdFilters/CompositionFilter.php index 3ff8cb63e..e9b06d6af 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/HouseholdFilters/CompositionFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/HouseholdFilters/CompositionFilter.php @@ -12,12 +12,12 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\HouseholdFilters; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Entity\Household\HouseholdCompositionType; use Chill\PersonBundle\Export\Declarations; -use DateTime; -use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; @@ -28,10 +28,14 @@ class CompositionFilter implements FilterInterface { private TranslatableStringHelper $translatableStringHelper; + private RollingDateConverterInterface $rollingDateConverter; + public function __construct( - TranslatableStringHelper $translatableStringHelper + TranslatableStringHelper $translatableStringHelper, + RollingDateConverterInterface $rollingDateConverter ) { $this->translatableStringHelper = $translatableStringHelper; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -58,7 +62,9 @@ class CompositionFilter implements FilterInterface $qb->andWhere($whereClause); $qb->setParameter('compositions', $data['accepted_composition']); - $qb->setParameter('ondate_composition_type_filter', $data['on_date'], Types::DATE_MUTABLE); + $qb->setParameter('ondate_composition_type_filter', + $this->rollingDateConverter->convert($data['on_date']) + ); } public function applyOn(): string @@ -79,8 +85,8 @@ class CompositionFilter implements FilterInterface 'multiple' => true, 'expanded' => true, ]) - ->add('on_date', ChillDateType::class, [ - 'data' => new DateTime('now'), + ->add('on_date', PickRollingDateType::class, [ + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } @@ -96,7 +102,7 @@ class CompositionFilter implements FilterInterface return ['Filtered by composition: only %compositions% on %ondate%', [ '%compositions%' => implode(', ', $compositions), - '%ondate%' => $data['on_date']->format('d-m-Y'), + '%ondate%' => $this->rollingDateConverter->convert($data['on_date'])->format('d-m-Y'), ]]; } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/AgeFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/AgeFilter.php index 218ae483e..0bf175ce4 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/AgeFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/AgeFilter.php @@ -13,10 +13,11 @@ namespace Chill\PersonBundle\Export\Filter\PersonFilters; use Chill\MainBundle\Export\ExportElementValidatedInterface; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\PersonBundle\Export\Declarations; use DateInterval; -use DateTimeImmutable; use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\Extension\Core\Type\IntegerType; @@ -25,6 +26,13 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; class AgeFilter implements ExportElementValidatedInterface, FilterInterface { + private RollingDateConverterInterface $rollingDateConverter; + + public function __construct(RollingDateConverterInterface $rollingDateConverter) + { + $this->rollingDateConverter = $rollingDateConverter; + } + public function addRole(): ?string { return null; @@ -36,7 +44,7 @@ class AgeFilter implements ExportElementValidatedInterface, FilterInterface $min = null !== $data['min_age'] ? $data['min_age'] : 0; $max = null !== $data['max_age'] ? $data['max_age'] : 150; - $calc = $data['date_calc']; + $calc = $this->rollingDateConverter->convert($data['date_calc']); $minDate = $calc->sub(new DateInterval('P' . $max . 'Y')); $maxDate = $calc->sub(new DateInterval('P' . $min . 'Y')); @@ -78,10 +86,9 @@ class AgeFilter implements ExportElementValidatedInterface, FilterInterface 'label' => 'Maximum age', ]); - $builder->add('date_calc', ChillDateType::class, [ + $builder->add('date_calc', PickRollingDateType::class, [ 'label' => 'Calculate age in relation to this date', - 'data' => new DateTimeImmutable('now'), - 'input' => 'datetime_immutable', + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/BirthdateFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/BirthdateFilter.php index aaa88fb7b..24883b681 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/BirthdateFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/BirthdateFilter.php @@ -13,20 +13,30 @@ namespace Chill\PersonBundle\Export\Filter\PersonFilters; use Chill\MainBundle\Export\ExportElementValidatedInterface; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\PersonBundle\Export\Declarations; -use DateTime; use Doctrine\ORM\Query\Expr; +use Doctrine\ORM\QueryBuilder; +use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Validator\Context\ExecutionContextInterface; class BirthdateFilter implements ExportElementValidatedInterface, FilterInterface { + private RollingDateConverterInterface $rollingDateConverter; + + public function __construct(RollingDateConverterInterface $rollingDateConverter) + { + $this->rollingDateConverter = $rollingDateConverter; + } + public function addRole(): ?string { return null; } - public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data) + public function alterQuery(QueryBuilder $qb, $data) { $where = $qb->getDQLPart('where'); $clause = $qb->expr()->between( @@ -42,8 +52,12 @@ class BirthdateFilter implements ExportElementValidatedInterface, FilterInterfac } $qb->add('where', $where); - $qb->setParameter('date_from', $data['date_from']); - $qb->setParameter('date_to', $data['date_to']); + $qb->setParameter('date_from', + $this->rollingDateConverter->convert($data['date_from']) + ); + $qb->setParameter('date_to', + $this->rollingDateConverter->convert($data['date_to']) + ); } public function applyOn() @@ -51,16 +65,16 @@ class BirthdateFilter implements ExportElementValidatedInterface, FilterInterfac return Declarations::PERSON_TYPE; } - public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) + public function buildForm(FormBuilderInterface $builder) { - $builder->add('date_from', ChillDateType::class, [ + $builder->add('date_from', PickRollingDateType::class, [ 'label' => 'Born after this date', - 'data' => new DateTime(), + 'data' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), ]); - $builder->add('date_to', ChillDateType::class, [ + $builder->add('date_to', PickRollingDateType::class, [ 'label' => 'Born before this date', - 'data' => new DateTime(), + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } @@ -68,8 +82,8 @@ class BirthdateFilter implements ExportElementValidatedInterface, FilterInterfac { return ['Filtered by person\'s birthdate: ' . 'between %date_from% and %date_to%', [ - '%date_from%' => $data['date_from']->format('d-m-Y'), - '%date_to%' => $data['date_to']->format('d-m-Y'), + '%date_from%' => $this->rollingDateConverter->convert($data['date_from'])->format('d-m-Y'), + '%date_to%' => $this->rollingDateConverter->convert($data['date_to'])->format('d-m-Y'), ], ]; } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/DeadOrAliveFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/DeadOrAliveFilter.php index e317d4a04..384d6698a 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/DeadOrAliveFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/DeadOrAliveFilter.php @@ -12,9 +12,10 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\PersonFilters; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\PersonBundle\Export\Declarations; -use DateTime; use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; @@ -22,6 +23,14 @@ use Symfony\Component\Form\FormBuilderInterface; class DeadOrAliveFilter implements FilterInterface { + private RollingDateConverterInterface $rollingDateConverter; + + public function __construct( + RollingDateConverterInterface $rollingDateConverter + ) { + $this->rollingDateConverter = $rollingDateConverter; + } + public function addRole(): ?string { return null; @@ -32,7 +41,7 @@ class DeadOrAliveFilter implements FilterInterface $where = $qb->getDQLPart('where'); $personState = $data['person_state']; - $calc = $data['date_calc']; + $calc = $this->rollingDateConverter->convert($data['date_calc']); if ('alive' === $personState) { $clause = $qb->expr()->orX( @@ -91,9 +100,9 @@ class DeadOrAliveFilter implements FilterInterface 'expanded' => true, ]); - $builder->add('date_calc', ChillDateType::class, [ + $builder->add('date_calc', PickRollingDateType::class, [ 'label' => 'Filter in relation to this date', - 'data' => new DateTime('now'), + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } @@ -101,7 +110,7 @@ class DeadOrAliveFilter implements FilterInterface { return ['Filtered by a state of %deadOrAlive%: ' . 'at this date %date_calc%', [ - '%date_calc%' => $data['date_calc']->format('d-m-Y'), + '%date_calc%' => $this->rollingDateConverter->convert($data['date_calc'])->format('d-m-Y'), '%deadOrAlive%' => $data['person_state'], ], ]; } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/DeathdateFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/DeathdateFilter.php index 48749006d..568995461 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/DeathdateFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/DeathdateFilter.php @@ -13,9 +13,10 @@ namespace Chill\PersonBundle\Export\Filter\PersonFilters; use Chill\MainBundle\Export\ExportElementValidatedInterface; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\PersonBundle\Export\Declarations; -use DateTime; use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -23,6 +24,14 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface; class DeathdateFilter implements ExportElementValidatedInterface, FilterInterface { + private RollingDateConverterInterface $rollingDateConverter; + + public function __construct( + RollingDateConverterInterface $rollingDateConverter + ) { + $this->rollingDateConverter = $rollingDateConverter; + } + public function addRole(): ?string { return null; @@ -44,8 +53,12 @@ class DeathdateFilter implements ExportElementValidatedInterface, FilterInterfac } $qb->add('where', $where); - $qb->setParameter('date_from', $data['date_from']); - $qb->setParameter('date_to', $data['date_to']); + $qb->setParameter('date_from', + $this->rollingDateConverter->convert($data['date_from']) + ); + $qb->setParameter('date_to', + $this->rollingDateConverter->convert($data['date_to']) + ); } public function applyOn() @@ -55,14 +68,14 @@ class DeathdateFilter implements ExportElementValidatedInterface, FilterInterfac public function buildForm(FormBuilderInterface $builder) { - $builder->add('date_from', ChillDateType::class, [ + $builder->add('date_from', PickRollingDateType::class, [ 'label' => 'Death after this date', - 'data' => new DateTime(), + 'data' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), ]); - $builder->add('date_to', ChillDateType::class, [ + $builder->add('date_to', PickRollingDateType::class, [ 'label' => 'Deathdate before', - 'data' => new DateTime(), + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } @@ -70,8 +83,8 @@ class DeathdateFilter implements ExportElementValidatedInterface, FilterInterfac { return ['Filtered by person\'s deathdate: ' . 'between %date_from% and %date_to%', [ - '%date_from%' => $data['date_from']->format('d-m-Y'), - '%date_to%' => $data['date_to']->format('d-m-Y'), + '%date_from%' => $this->rollingDateConverter->convert($data['date_from'])->format('d-m-Y'), + '%date_to%' => $this->rollingDateConverter->convert($data['date_to'])->format('d-m-Y'), ], ]; } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GeographicalUnitFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GeographicalUnitFilter.php index 03d9ab568..e2bb0a09b 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GeographicalUnitFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GeographicalUnitFilter.php @@ -13,13 +13,14 @@ namespace Chill\PersonBundle\Export\Filter\PersonFilters; use Chill\MainBundle\Entity\GeographicalUnit; use Chill\MainBundle\Entity\GeographicalUnit\SimpleGeographicalUnitDTO; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Repository\GeographicalUnitLayerRepositoryInterface; use Chill\MainBundle\Repository\GeographicalUnitRepositoryInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress; use Chill\PersonBundle\Export\Declarations; -use DateTimeImmutable; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; @@ -32,14 +33,18 @@ class GeographicalUnitFilter implements \Chill\MainBundle\Export\FilterInterface private TranslatableStringHelperInterface $translatableStringHelper; + private RollingDateConverterInterface $rollingDateConverter; + public function __construct( GeographicalUnitRepositoryInterface $geographicalUnitRepository, GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository, - TranslatableStringHelperInterface $translatableStringHelper + TranslatableStringHelperInterface $translatableStringHelper, + RollingDateConverterInterface $rollingDateConverter ) { $this->geographicalUnitRepository = $geographicalUnitRepository; $this->geographicalUnitLayerRepository = $geographicalUnitLayerRepository; $this->translatableStringHelper = $translatableStringHelper; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -70,7 +75,9 @@ class GeographicalUnitFilter implements \Chill\MainBundle\Export\FilterInterface ->andWhere( $qb->expr()->exists($subQuery) ) - ->setParameter('person_filter_geog_date', $data['date_calc']) + ->setParameter('person_filter_geog_date', + $this->rollingDateConverter->convert($data['date_calc']) + ) ->setParameter('person_filter_geog_units', array_map(static fn (SimpleGeographicalUnitDTO $unitDTO) => $unitDTO->id, $data['units'])); } @@ -82,11 +89,10 @@ class GeographicalUnitFilter implements \Chill\MainBundle\Export\FilterInterface public function buildForm(FormBuilderInterface $builder) { $builder - ->add('date_calc', ChillDateType::class, [ + ->add('date_calc', PickRollingDateType::class, [ 'label' => 'Compute geographical location at date', 'required' => true, - 'data' => new DateTimeImmutable('today'), - 'input' => 'datetime_immutable', + 'data' => new RollingDate(RollingDate::T_TODAY), ]) ->add('units', ChoiceType::class, [ 'label' => 'Geographical unit', @@ -108,7 +114,7 @@ class GeographicalUnitFilter implements \Chill\MainBundle\Export\FilterInterface return [ 'exports.by_person.Filtered by person\'s geographical unit (based on address) computed at datecalc, only units', [ - 'datecalc' => $data['date_calc']->format('Y-m-d'), + 'datecalc' => $this->rollingDateConverter->convert($data['date_calc'])->format('Y-m-d'), 'units' => implode( ', ', array_map( diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php index 632ab8d3b..2aa6e92ad 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php @@ -12,12 +12,13 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\PersonFilters; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\PersonBundle\Entity\Person\ResidentialAddress; use Chill\PersonBundle\Export\Declarations; use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory; -use DateTime; use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; @@ -28,9 +29,14 @@ class ResidentialAddressAtThirdpartyFilter implements FilterInterface { private TranslatableStringHelper $translatableStringHelper; - public function __construct(TranslatableStringHelper $translatableStringHelper) - { + private RollingDateConverterInterface $rollingDateConverter; + + public function __construct( + RollingDateConverterInterface $rollingDateConverter, + TranslatableStringHelper $translatableStringHelper + ) { $this->translatableStringHelper = $translatableStringHelper; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -77,7 +83,9 @@ class ResidentialAddressAtThirdpartyFilter implements FilterInterface } $qb->setParameter('type', $data['thirdparty_cat']); - $qb->setParameter('date', $data['date_calc']); + $qb->setParameter('date', + $this->rollingDateConverter->convert($data['date_calc']) + ); $qb->add('where', $where); } @@ -98,9 +106,9 @@ class ResidentialAddressAtThirdpartyFilter implements FilterInterface 'expanded' => true, ]); - $builder->add('date_calc', ChillDateType::class, [ + $builder->add('date_calc', PickRollingDateType::class, [ 'label' => 'Date during which residential address was valid', - 'data' => new DateTime('now'), + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } @@ -108,7 +116,7 @@ class ResidentialAddressAtThirdpartyFilter implements FilterInterface { return ['Filtered by person\'s who have a residential address located at a thirdparty of type %thirdparty_type% and valid on %date_calc%', [ '%thirdparty_type%' => $this->translatableStringHelper->localize($data['thirdparty_cat'][0]->getName()), - '%date_calc%' => $data['date_calc']->format('d-m-Y'), + '%date_calc%' => $this->rollingDateConverter->convert($data['date_calc'])->format('d-m-Y'), ]]; } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php index 7408f7c2b..c92919ef3 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php @@ -12,10 +12,11 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\PersonFilters; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\PersonBundle\Entity\Person\ResidentialAddress; use Chill\PersonBundle\Export\Declarations; -use DateTime; use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr\Andx; use Doctrine\ORM\QueryBuilder; @@ -23,6 +24,14 @@ use function in_array; class ResidentialAddressAtUserFilter implements FilterInterface { + private RollingDateConverterInterface $rollingDateConverter; + + public function __construct( + RollingDateConverterInterface $rollingDateConverter + ) { + $this->rollingDateConverter = $rollingDateConverter; + } + public function addRole(): ?string { return null; @@ -57,7 +66,9 @@ class ResidentialAddressAtUserFilter implements FilterInterface $where = $qb->expr()->andX($clause); } - $qb->setParameter('date', $data['date_calc']); + $qb->setParameter('date', + $this->rollingDateConverter->convert($data['date_calc']) + ); $qb->add('where', $where); } @@ -68,9 +79,9 @@ class ResidentialAddressAtUserFilter implements FilterInterface public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) { - $builder->add('date_calc', ChillDateType::class, [ + $builder->add('date_calc', PickRollingDateType::class, [ 'label' => 'Date during which residential address was valid', - 'data' => new DateTime('now'), + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } diff --git a/src/Bundle/ChillReportBundle/Export/Filter/ReportDateFilter.php b/src/Bundle/ChillReportBundle/Export/Filter/ReportDateFilter.php index ec4ea7fc5..a7aa19ab0 100644 --- a/src/Bundle/ChillReportBundle/Export/Filter/ReportDateFilter.php +++ b/src/Bundle/ChillReportBundle/Export/Filter/ReportDateFilter.php @@ -12,12 +12,21 @@ declare(strict_types=1); namespace Chill\ReportBundle\Export\Filter; use Chill\MainBundle\Export\FilterInterface; -use Chill\MainBundle\Form\Type\ChillDateType; -use DateTime; +use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Doctrine\ORM\Query\Expr; class ReportDateFilter implements FilterInterface { + private RollingDateConverterInterface $rollingDateConverter; + + public function __construct( + RollingDateConverterInterface $rollingDateConverter + ) { + $this->rollingDateConverter = $rollingDateConverter; + } + public function addRole(): ?string { return null; @@ -39,8 +48,12 @@ class ReportDateFilter implements FilterInterface } $qb->add('where', $where); - $qb->setParameter('report_date_filter_date_from', $data['date_from']); - $qb->setParameter('report_date_filter_date_to', $data['date_to']); + $qb->setParameter('report_date_filter_date_from', + $this->rollingDateConverter->convert($data['date_from']) + ); + $qb->setParameter('report_date_filter_date_to', + $this->rollingDateConverter->convert($data['date_to']) + ); } public function applyOn() @@ -50,14 +63,14 @@ class ReportDateFilter implements FilterInterface public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) { - $builder->add('date_from', ChillDateType::class, [ + $builder->add('date_from', PickRollingDateType::class, [ 'label' => 'Report is after this date', - 'data' => new DateTime(), + 'data' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), ]); - $builder->add('date_to', ChillDateType::class, [ + $builder->add('date_to', PickRollingDateType::class, [ 'label' => 'Report is before this date', - 'data' => new DateTime(), + 'data' => new RollingDate(RollingDate::T_TODAY), ]); } @@ -65,8 +78,8 @@ class ReportDateFilter implements FilterInterface { return ['Filtered by report\'s date: ' . 'between %date_from% and %date_to%', [ - '%date_from%' => $data['date_from']->format('d-m-Y'), - '%date_to%' => $data['date_to']->format('d-m-Y'), + '%date_from%' => $this->rollingDateConverter->convert($data['date_from'])->format('d-m-Y'), + '%date_to%' => $this->rollingDateConverter->convert($data['date_to'])->format('d-m-Y'), ], ]; }