From 1f3dd00d815520dab82d4e2cb4db23fdd5e01599 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 14 Nov 2022 12:31:13 +0100 Subject: [PATCH 1/6] improve flex positionning for list exports cards --- .../Resources/public/chill/chillmain.scss | 14 +++++++---- .../Resources/views/Export/layout.html.twig | 24 +++++++++---------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss b/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss index 5c302bf83..7cd3f5479 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss +++ b/src/Bundle/ChillMainBundle/Resources/public/chill/chillmain.scss @@ -518,8 +518,14 @@ div.v-toast { z-index: 10000!important; } -div.grouped { - padding: 1em; - border: 1px solid black; - margin-bottom: 2em; +// export index page +div.exports-list { + div.flex-bloc .item-bloc { + flex-basis: 33%; + @include media-breakpoint-down(lg) { flex-basis: 50%; } + @include media-breakpoint-down(sm) { flex-basis: 100%; } + p:last-child { + margin-top: auto; + } + } } \ No newline at end of file diff --git a/src/Bundle/ChillMainBundle/Resources/views/Export/layout.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Export/layout.html.twig index 5ce433535..b86f617b4 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Export/layout.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Export/layout.html.twig @@ -25,25 +25,23 @@ {{ include('@ChillMain/Export/_navbar.html.twig', {'current' : 'common'}) }} -
+
{% for group, exports in grouped_exports %}{% if group != '_' %}

{{ group|trans }}

-
+
{% for export_alias, export in exports %} -
-
-
-

{{ export.title|trans }}

-

{{ export.description|trans }}

-

- - {{ 'Create an export'|trans }} - -

-
+
+
+

{{ export.title|trans }}

+

{{ export.description|trans }}

+

+ + {{ 'Create an export'|trans }} + +

{% endfor %} From 68bfb082fc9a482c268fb9100c23c5a2b15bae10 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 14 Nov 2022 15:38:14 +0100 Subject: [PATCH 2/6] 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'), ], ]; } From e767557216d9749ed7adf6d54ad6da99e279d135 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 14 Nov 2022 16:03:04 +0100 Subject: [PATCH 3/6] csfixer --- .../Export/Filter/ActivityDateFilter.php | 12 +++++++----- .../src/Export/Filter/ByDateFilter.php | 12 +++++++----- .../Export/Filter/BetweenDatesFilter.php | 6 ++++-- .../GeographicalUnitStatAggregator.php | 12 +++++++----- .../ReferrerAggregator.php | 9 +++++---- .../ReferrerScopeAggregator.php | 9 +++++---- .../ChildrenNumberAggregator.php | 7 ++++--- .../HouseholdAggregators/CompositionAggregator.php | 7 ++++--- .../ByHouseholdCompositionAggregator.php | 7 ++++--- .../PersonAggregators/GeographicalUnitAggregator.php | 9 +++++---- .../HouseholdPositionAggregator.php | 7 ++++--- .../AccompanyingCourseFilters/ActiveOnDateFilter.php | 3 ++- .../ActiveOneDayBetweenDatesFilter.php | 6 ++++-- .../GeographicalUnitStatFilter.php | 11 ++++++----- .../HasNoReferrerFilter.php | 3 ++- .../HasTemporaryLocationFilter.php | 3 ++- .../AccompanyingCourseFilters/ReferrerFilter.php | 9 +++++---- .../AccompanyingCourseFilters/UserJobFilter.php | 9 +++++---- .../AccompanyingCourseFilters/UserScopeFilter.php | 9 +++++---- .../Filter/EvaluationFilters/ByEndDateFilter.php | 6 ++++-- .../Filter/EvaluationFilters/ByStartDateFilter.php | 6 ++++-- .../Filter/HouseholdFilters/CompositionFilter.php | 7 ++++--- .../Export/Filter/PersonFilters/BirthdateFilter.php | 6 ++++-- .../Export/Filter/PersonFilters/DeathdateFilter.php | 6 ++++-- .../Filter/PersonFilters/GeographicalUnitFilter.php | 11 ++++++----- .../ResidentialAddressAtThirdpartyFilter.php | 7 ++++--- .../PersonFilters/ResidentialAddressAtUserFilter.php | 3 ++- .../Export/Filter/ReportDateFilter.php | 6 ++++-- 28 files changed, 123 insertions(+), 85 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ActivityDateFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ActivityDateFilter.php index edfa9b030..f2216c929 100644 --- a/src/Bundle/ChillActivityBundle/Export/Filter/ActivityDateFilter.php +++ b/src/Bundle/ChillActivityBundle/Export/Filter/ActivityDateFilter.php @@ -13,10 +13,10 @@ namespace Chill\ActivityBundle\Export\Filter; use Chill\ActivityBundle\Export\Declarations; use Chill\MainBundle\Export\FilterInterface; +use Chill\MainBundle\Form\Type\Export\FilterType; 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 Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -27,10 +27,10 @@ use Symfony\Contracts\Translation\TranslatorInterface; class ActivityDateFilter implements FilterInterface { - private RollingDateConverterInterface $rollingDateConverter; - protected TranslatorInterface $translator; + private RollingDateConverterInterface $rollingDateConverter; + public function __construct( TranslatorInterface $translator, RollingDateConverterInterface $rollingDateConverter @@ -60,10 +60,12 @@ class ActivityDateFilter implements FilterInterface } $qb->add('where', $where); - $qb->setParameter('date_from', + $qb->setParameter( + 'date_from', $this->rollingDateConverter->convert($data['date_from']) ); - $qb->setParameter('date_to', + $qb->setParameter( + 'date_to', $this->rollingDateConverter->convert($data['date_to']) ); } diff --git a/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByDateFilter.php b/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByDateFilter.php index fca4dece8..099c87fc0 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByDateFilter.php +++ b/src/Bundle/ChillAsideActivityBundle/src/Export/Filter/ByDateFilter.php @@ -13,10 +13,10 @@ namespace Chill\AsideActivityBundle\Export\Filter; use Chill\AsideActivityBundle\Export\Declarations; use Chill\MainBundle\Export\FilterInterface; +use Chill\MainBundle\Form\Type\Export\FilterType; 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 Doctrine\ORM\Query\Expr\Andx; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -27,10 +27,10 @@ use Symfony\Contracts\Translation\TranslatorInterface; class ByDateFilter implements FilterInterface { - private RollingDateConverterInterface $rollingDateConverter; - protected TranslatorInterface $translator; + private RollingDateConverterInterface $rollingDateConverter; + public function __construct( RollingDateConverterInterface $rollingDateConverter, TranslatorInterface $translator @@ -60,10 +60,12 @@ class ByDateFilter implements FilterInterface } $qb->add('where', $where); - $qb->setParameter('date_from', + $qb->setParameter( + 'date_from', $this->rollingDateConverter->convert($data['date_from']) ); - $qb->setParameter('date_to', + $qb->setParameter( + 'date_to', $this->rollingDateConverter->convert($data['date_to']) ); } diff --git a/src/Bundle/ChillCalendarBundle/Export/Filter/BetweenDatesFilter.php b/src/Bundle/ChillCalendarBundle/Export/Filter/BetweenDatesFilter.php index 01bfad033..9e0358609 100644 --- a/src/Bundle/ChillCalendarBundle/Export/Filter/BetweenDatesFilter.php +++ b/src/Bundle/ChillCalendarBundle/Export/Filter/BetweenDatesFilter.php @@ -50,11 +50,13 @@ class BetweenDatesFilter implements FilterInterface } $qb->add('where', $where); - $qb->setParameter('dateFrom', + $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', + $qb->setParameter( + 'dateTo', $this->rollingDateConverter->convert($data['date_to'])->modify('+1 day') ); } diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/GeographicalUnitStatAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/GeographicalUnitStatAggregator.php index 59a39ab12..22a2cb719 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/GeographicalUnitStatAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/GeographicalUnitStatAggregator.php @@ -16,9 +16,9 @@ use Chill\MainBundle\Entity\GeographicalUnit; use Chill\MainBundle\Entity\GeographicalUnitLayer; use Chill\MainBundle\Export\AggregatorInterface; use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Repository\GeographicalUnitLayerRepositoryInterface; 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; @@ -33,10 +33,10 @@ final class GeographicalUnitStatAggregator implements AggregatorInterface { private GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository; - private TranslatableStringHelperInterface $translatableStringHelper; - private RollingDateConverterInterface $rollingDateConverter; + private TranslatableStringHelperInterface $translatableStringHelper; + public function __construct( GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository, TranslatableStringHelperInterface $translatableStringHelper, @@ -67,7 +67,8 @@ final class GeographicalUnitStatAggregator implements AggregatorInterface ) ); - $qb->setParameter('acp_geog_aggregator_date', + $qb->setParameter( + 'acp_geog_aggregator_date', $this->rollingDateConverter->convert($data['date_calc']) ); } @@ -88,7 +89,8 @@ final class GeographicalUnitStatAggregator implements AggregatorInterface ) ); - $qb->setParameter('acp_geog_aggregator_date', + $qb->setParameter( + 'acp_geog_aggregator_date', $this->rollingDateConverter->convert($data['date_calc']) ); } diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerAggregator.php index 84da976c6..01bc3a459 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerAggregator.php @@ -13,9 +13,9 @@ namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators; use Chill\MainBundle\Export\AggregatorInterface; use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Repository\UserRepository; 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 Doctrine\ORM\QueryBuilder; @@ -27,12 +27,12 @@ final class ReferrerAggregator implements AggregatorInterface private const P = 'acp_ref_agg_date'; + private RollingDateConverterInterface $rollingDateConverter; + private UserRender $userRender; private UserRepository $userRepository; - private RollingDateConverterInterface $rollingDateConverter; - public function __construct( UserRepository $userRepository, UserRender $userRender, @@ -66,7 +66,8 @@ final class ReferrerAggregator implements AggregatorInterface ) ) ) - ->setParameter(self::P, + ->setParameter( + self::P, $this->rollingDateConverter->convert($data['date_calc']) ); } diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregator.php index 16ff76e3d..62f8cdef2 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregator.php @@ -13,9 +13,9 @@ namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators; use Chill\MainBundle\Export\AggregatorInterface; use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Repository\ScopeRepositoryInterface; 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 Doctrine\ORM\QueryBuilder; @@ -26,12 +26,12 @@ class ReferrerScopeAggregator implements AggregatorInterface { private const SCOPE_KEY = 'acp_agg_refscope_user_history_ref_scope_name'; + private RollingDateConverterInterface $rollingDateConverter; + private ScopeRepositoryInterface $scopeRepository; private TranslatableStringHelperInterface $translatableStringHelper; - private RollingDateConverterInterface $rollingDateConverter; - public function __construct( ScopeRepositoryInterface $scopeRepository, TranslatableStringHelperInterface $translatableStringHelper, @@ -69,7 +69,8 @@ class ReferrerScopeAggregator implements AggregatorInterface ) ) ) - ->setParameter($dateCalc, + ->setParameter( + $dateCalc, $this->rollingDateConverter->convert($data['date_calc']) ); diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php index aa2e9b4b6..0c9bc623f 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/ChildrenNumberAggregator.php @@ -24,10 +24,10 @@ use function in_array; class ChildrenNumberAggregator implements AggregatorInterface { - private TranslatorInterface $translator; - private RollingDateConverterInterface $rollingDateConverter; + private TranslatorInterface $translator; + public function __construct( TranslatorInterface $translator, RollingDateConverterInterface $rollingDateConverter @@ -59,7 +59,8 @@ class ChildrenNumberAggregator implements AggregatorInterface ->addSelect('composition_children.numberOfChildren AS childrennumber_aggregator') ->addGroupBy('childrennumber_aggregator'); - $qb->setParameter('ondate_composition_children', + $qb->setParameter( + 'ondate_composition_children', $this->rollingDateConverter->convert($data['on_date']) ); } diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php index 1917a51b3..19884dd10 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/HouseholdAggregators/CompositionAggregator.php @@ -25,12 +25,12 @@ use function in_array; class CompositionAggregator implements AggregatorInterface { + private RollingDateConverterInterface $rollingDateConverter; + private TranslatableStringHelper $translatableStringHelper; private HouseholdCompositionTypeRepository $typeRepository; - private RollingDateConverterInterface $rollingDateConverter; - public function __construct( HouseholdCompositionTypeRepository $typeRepository, TranslatableStringHelper $translatableStringHelper, @@ -64,7 +64,8 @@ class CompositionAggregator implements AggregatorInterface ->addSelect('IDENTITY(composition_type.householdCompositionType) AS composition_aggregator') ->addGroupBy('composition_aggregator'); - $qb->setParameter('ondate_composition_type', + $qb->setParameter( + 'ondate_composition_type', $this->rollingDateConverter->convert($data['on_date']) ); } diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/ByHouseholdCompositionAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/ByHouseholdCompositionAggregator.php index 576f52626..03e5f17ce 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/ByHouseholdCompositionAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/ByHouseholdCompositionAggregator.php @@ -29,10 +29,10 @@ class ByHouseholdCompositionAggregator implements AggregatorInterface private HouseholdCompositionTypeRepositoryInterface $householdCompositionTypeRepository; - private TranslatableStringHelperInterface $translatableStringHelper; - private RollingDateConverterInterface $rollingDateConverter; + private TranslatableStringHelperInterface $translatableStringHelper; + public function __construct( RollingDateConverterInterface $rollingDateConverter, HouseholdCompositionTypeRepositoryInterface $householdCompositionTypeRepository, @@ -78,7 +78,8 @@ class ByHouseholdCompositionAggregator implements AggregatorInterface ) ) ->addSelect("IDENTITY({$p}_compo.householdCompositionType) AS {$p}_select") - ->setParameter("{$p}_date", + ->setParameter( + "{$p}_date", $this->rollingDateConverter->convert($data['date_calc']) ) ->addGroupBy("{$p}_select"); diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/GeographicalUnitAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/GeographicalUnitAggregator.php index dd6f10035..6c92be3fd 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/GeographicalUnitAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/GeographicalUnitAggregator.php @@ -15,9 +15,9 @@ use Chill\MainBundle\Entity\GeographicalUnit; use Chill\MainBundle\Entity\GeographicalUnitLayer; use Chill\MainBundle\Export\AggregatorInterface; use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Repository\GeographicalUnitLayerRepositoryInterface; 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 Doctrine\ORM\Query\Expr\Join; @@ -30,10 +30,10 @@ class GeographicalUnitAggregator implements AggregatorInterface { private GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository; - private TranslatableStringHelperInterface $translatableStringHelper; - private RollingDateConverterInterface $rollingDateConverter; + private TranslatableStringHelperInterface $translatableStringHelper; + public function __construct( GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository, TranslatableStringHelperInterface $translatableStringHelper, @@ -73,7 +73,8 @@ class GeographicalUnitAggregator implements AggregatorInterface $qb->expr()->in('person_geog_agg_geog_unit.layer', ':person_geog_agg_layers') ) ) - ->setParameter('person_geog_agg_date', + ->setParameter( + 'person_geog_agg_date', $this->rollingDateConverter->convert($data['date_calc']) ) ->setParameter('person_geog_agg_layers', $data['level']) diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/HouseholdPositionAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/HouseholdPositionAggregator.php index 0d986bdea..ea516dbb0 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/HouseholdPositionAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/HouseholdPositionAggregator.php @@ -31,12 +31,12 @@ final class HouseholdPositionAggregator implements AggregatorInterface, ExportEl { private PositionRepository $positionRepository; + private RollingDateConverterInterface $rollingDateConverter; + private TranslatableStringHelper $translatableStringHelper; private TranslatorInterface $translator; - private RollingDateConverterInterface $rollingDateConverter; - public function __construct( TranslatorInterface $translator, TranslatableStringHelper $translatableStringHelper, @@ -72,7 +72,8 @@ final class HouseholdPositionAggregator implements AggregatorInterface, ExportEl ) )); - $qb->setParameter('date', + $qb->setParameter( + 'date', $this->rollingDateConverter->convert($data['date_position']) ); diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ActiveOnDateFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ActiveOnDateFilter.php index 55fe56d59..3fa8d711f 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ActiveOnDateFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ActiveOnDateFilter.php @@ -53,7 +53,8 @@ class ActiveOnDateFilter implements FilterInterface } $qb->add('where', $where); - $qb->setParameter('ondate', + $qb->setParameter( + 'ondate', $this->rollingDateConverter->convert($data['on_date']) ); } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ActiveOneDayBetweenDatesFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ActiveOneDayBetweenDatesFilter.php index 4d1a9ad23..f713e8a97 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ActiveOneDayBetweenDatesFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ActiveOneDayBetweenDatesFilter.php @@ -38,10 +38,12 @@ class ActiveOneDayBetweenDatesFilter implements FilterInterface $clause = "OVERLAPSI (acp.openingDate, acp.closingDate), (:datefrom, :dateto) = 'TRUE'"; $qb->andWhere($clause); - $qb->setParameter('datefrom', + $qb->setParameter( + 'datefrom', $this->rollingDateConverter->convert($data['date_from']) ); - $qb->setParameter('dateto', + $qb->setParameter( + 'dateto', $this->rollingDateConverter->convert($data['date_to']) ); } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php index 55e710f8e..0c445ec3b 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php @@ -16,10 +16,10 @@ use Chill\MainBundle\Entity\GeographicalUnit; use Chill\MainBundle\Entity\GeographicalUnit\SimpleGeographicalUnitDTO; 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\MainBundle\Repository\GeographicalUnitLayerRepositoryInterface; use Chill\MainBundle\Repository\GeographicalUnitRepositoryInterface; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress; @@ -40,10 +40,10 @@ class GeographicalUnitStatFilter implements FilterInterface private GeographicalUnitRepositoryInterface $geographicalUnitRepository; - private TranslatableStringHelperInterface $translatableStringHelper; - private RollingDateConverterInterface $rollingDateConverter; + private TranslatableStringHelperInterface $translatableStringHelper; + public function __construct( EntityManagerInterface $em, GeographicalUnitRepositoryInterface $geographicalUnitRepository, @@ -88,7 +88,8 @@ class GeographicalUnitStatFilter implements FilterInterface $qb ->andWhere($qb->expr()->exists($subQueryDql)) - ->setParameter('acp_geog_filter_date', + ->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'])); diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasNoReferrerFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasNoReferrerFilter.php index ff30b6312..4c682a56a 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasNoReferrerFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasNoReferrerFilter.php @@ -49,7 +49,8 @@ class HasNoReferrerFilter implements FilterInterface AND uh.accompanyingPeriod = acp ) ') - ->setParameter('has_no_referrer_filter_date', + ->setParameter( + 'has_no_referrer_filter_date', $this->rollingDateConverter->convert($data['calc_date']) ); } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasTemporaryLocationFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasTemporaryLocationFilter.php index 3dfbea9c2..7aadde734 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasTemporaryLocationFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasTemporaryLocationFilter.php @@ -42,7 +42,8 @@ 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', + ->setParameter( + 'acp_having_temporarily_location_date', $this->rollingDateConverter->convert($data['calc_date']) ); diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ReferrerFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ReferrerFilter.php index 5e1ad18b9..b37d90d84 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ReferrerFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/ReferrerFilter.php @@ -13,9 +13,9 @@ namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Form\Type\PickUserDynamicType; 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 Doctrine\ORM\QueryBuilder; @@ -29,10 +29,10 @@ class ReferrerFilter implements FilterInterface private const PU = 'acp_referrer_filter_users'; - private UserRender $userRender; - private RollingDateConverterInterface $rollingDateConverter; + private UserRender $userRender; + public function __construct( UserRender $userRender, RollingDateConverterInterface $rollingDateConverter @@ -63,7 +63,8 @@ class ReferrerFilter implements FilterInterface $qb->expr()->in(self::A . '.user', ':' . self::PU) ) ->setParameter(self::PU, $data['accepted_referrers']) - ->setParameter(self::P, + ->setParameter( + self::P, $this->rollingDateConverter->convert($data['date_calc']) ); } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php index fadc5d295..b97f97dda 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserJobFilter.php @@ -15,9 +15,9 @@ use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\UserJob; use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Repository\UserJobRepositoryInterface; 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 Doctrine\ORM\QueryBuilder; @@ -35,14 +35,14 @@ class UserJobFilter implements FilterInterface private const PJ = 'acp_ujob_filter_job'; + private RollingDateConverterInterface $rollingDateConverter; + private Security $security; private TranslatableStringHelper $translatableStringHelper; private UserJobRepositoryInterface $userJobRepository; - private RollingDateConverterInterface $rollingDateConverter; - public function __construct( Security $security, TranslatableStringHelper $translatableStringHelper, @@ -73,7 +73,8 @@ class UserJobFilter implements FilterInterface ) ) ) - ->setParameter(self::P, + ->setParameter( + self::P, $this->rollingDateConverter->convert($data['date_calc']) ) ->join(self::A . '.user', self::AU) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserScopeFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserScopeFilter.php index 3fcf4f87e..bbffa4bca 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserScopeFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/UserScopeFilter.php @@ -15,9 +15,9 @@ use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Form\Type\PickRollingDateType; +use Chill\MainBundle\Repository\ScopeRepositoryInterface; 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 Doctrine\ORM\QueryBuilder; @@ -35,14 +35,14 @@ class UserScopeFilter implements FilterInterface private const PS = 'acp_uscope_filter_scopes'; + private RollingDateConverterInterface $rollingDateConverter; + private ScopeRepositoryInterface $scopeRepository; private Security $security; private TranslatableStringHelper $translatableStringHelper; - private RollingDateConverterInterface $rollingDateConverter; - public function __construct( ScopeRepositoryInterface $scopeRepository, Security $security, @@ -73,7 +73,8 @@ class UserScopeFilter implements FilterInterface ) ) ) - ->setParameter(self::P, + ->setParameter( + self::P, $this->rollingDateConverter->convert($data['date_calc']) ) ->join(self::A . '.user', self::AU) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByEndDateFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByEndDateFilter.php index 5021da1bc..1f14b04ac 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByEndDateFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByEndDateFilter.php @@ -38,10 +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', + ->setParameter( + 'work_eval_by_end_date_start_date', $this->rollingDateConverter->convert($data['start_date']) ) - ->setParameter('work_eval_by_end_date_end_date', + ->setParameter( + 'work_eval_by_end_date_end_date', $this->rollingDateConverter->convert($data['end_date']) ); } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByStartDateFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByStartDateFilter.php index c5c4c8899..000f3447e 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByStartDateFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByStartDateFilter.php @@ -38,10 +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', + ->setParameter( + 'work_eval_by_start_date_start_date', $this->rollingDateConverter->convert($data['start_date']) ) - ->setParameter('work_eval_by_start_date_end_date', + ->setParameter( + 'work_eval_by_start_date_end_date', $this->rollingDateConverter->convert($data['end_date']) ); } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/HouseholdFilters/CompositionFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/HouseholdFilters/CompositionFilter.php index e9b06d6af..922702418 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/HouseholdFilters/CompositionFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/HouseholdFilters/CompositionFilter.php @@ -26,10 +26,10 @@ use function in_array; class CompositionFilter implements FilterInterface { - private TranslatableStringHelper $translatableStringHelper; - private RollingDateConverterInterface $rollingDateConverter; + private TranslatableStringHelper $translatableStringHelper; + public function __construct( TranslatableStringHelper $translatableStringHelper, RollingDateConverterInterface $rollingDateConverter @@ -62,7 +62,8 @@ class CompositionFilter implements FilterInterface $qb->andWhere($whereClause); $qb->setParameter('compositions', $data['accepted_composition']); - $qb->setParameter('ondate_composition_type_filter', + $qb->setParameter( + 'ondate_composition_type_filter', $this->rollingDateConverter->convert($data['on_date']) ); } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/BirthdateFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/BirthdateFilter.php index 24883b681..7ae22ddd8 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/BirthdateFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/BirthdateFilter.php @@ -52,10 +52,12 @@ class BirthdateFilter implements ExportElementValidatedInterface, FilterInterfac } $qb->add('where', $where); - $qb->setParameter('date_from', + $qb->setParameter( + 'date_from', $this->rollingDateConverter->convert($data['date_from']) ); - $qb->setParameter('date_to', + $qb->setParameter( + 'date_to', $this->rollingDateConverter->convert($data['date_to']) ); } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/DeathdateFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/DeathdateFilter.php index 568995461..0ac4b3173 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/DeathdateFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/DeathdateFilter.php @@ -53,10 +53,12 @@ class DeathdateFilter implements ExportElementValidatedInterface, FilterInterfac } $qb->add('where', $where); - $qb->setParameter('date_from', + $qb->setParameter( + 'date_from', $this->rollingDateConverter->convert($data['date_from']) ); - $qb->setParameter('date_to', + $qb->setParameter( + 'date_to', $this->rollingDateConverter->convert($data['date_to']) ); } diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GeographicalUnitFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GeographicalUnitFilter.php index e2bb0a09b..d641a0140 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GeographicalUnitFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GeographicalUnitFilter.php @@ -14,10 +14,10 @@ namespace Chill\PersonBundle\Export\Filter\PersonFilters; use Chill\MainBundle\Entity\GeographicalUnit; use Chill\MainBundle\Entity\GeographicalUnit\SimpleGeographicalUnitDTO; 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\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress; use Chill\PersonBundle\Export\Declarations; @@ -31,10 +31,10 @@ class GeographicalUnitFilter implements \Chill\MainBundle\Export\FilterInterface private GeographicalUnitRepositoryInterface $geographicalUnitRepository; - private TranslatableStringHelperInterface $translatableStringHelper; - private RollingDateConverterInterface $rollingDateConverter; + private TranslatableStringHelperInterface $translatableStringHelper; + public function __construct( GeographicalUnitRepositoryInterface $geographicalUnitRepository, GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository, @@ -75,7 +75,8 @@ class GeographicalUnitFilter implements \Chill\MainBundle\Export\FilterInterface ->andWhere( $qb->expr()->exists($subQuery) ) - ->setParameter('person_filter_geog_date', + ->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'])); diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php index 2aa6e92ad..90003c6bf 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtThirdpartyFilter.php @@ -27,10 +27,10 @@ use function in_array; class ResidentialAddressAtThirdpartyFilter implements FilterInterface { - private TranslatableStringHelper $translatableStringHelper; - private RollingDateConverterInterface $rollingDateConverter; + private TranslatableStringHelper $translatableStringHelper; + public function __construct( RollingDateConverterInterface $rollingDateConverter, TranslatableStringHelper $translatableStringHelper @@ -83,7 +83,8 @@ class ResidentialAddressAtThirdpartyFilter implements FilterInterface } $qb->setParameter('type', $data['thirdparty_cat']); - $qb->setParameter('date', + $qb->setParameter( + 'date', $this->rollingDateConverter->convert($data['date_calc']) ); $qb->add('where', $where); diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php index c92919ef3..bd55c5b80 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/ResidentialAddressAtUserFilter.php @@ -66,7 +66,8 @@ class ResidentialAddressAtUserFilter implements FilterInterface $where = $qb->expr()->andX($clause); } - $qb->setParameter('date', + $qb->setParameter( + 'date', $this->rollingDateConverter->convert($data['date_calc']) ); $qb->add('where', $where); diff --git a/src/Bundle/ChillReportBundle/Export/Filter/ReportDateFilter.php b/src/Bundle/ChillReportBundle/Export/Filter/ReportDateFilter.php index a7aa19ab0..79bad4f52 100644 --- a/src/Bundle/ChillReportBundle/Export/Filter/ReportDateFilter.php +++ b/src/Bundle/ChillReportBundle/Export/Filter/ReportDateFilter.php @@ -48,10 +48,12 @@ class ReportDateFilter implements FilterInterface } $qb->add('where', $where); - $qb->setParameter('report_date_filter_date_from', + $qb->setParameter( + 'report_date_filter_date_from', $this->rollingDateConverter->convert($data['date_from']) ); - $qb->setParameter('report_date_filter_date_to', + $qb->setParameter( + 'report_date_filter_date_to', $this->rollingDateConverter->convert($data['date_to']) ); } From 2db778c4a4a5e03a106b132a452e4b14eb1b86c3 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Mon, 14 Nov 2022 16:16:38 +0100 Subject: [PATCH 4/6] fix chill-bundles#25 RollingDate bad expression --- .../Export/Filter/EvaluationFilters/ByEndDateFilter.php | 2 +- .../Export/Filter/EvaluationFilters/ByStartDateFilter.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByEndDateFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByEndDateFilter.php index 1f14b04ac..2dd9192bd 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByEndDateFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByEndDateFilter.php @@ -58,7 +58,7 @@ class ByEndDateFilter implements FilterInterface $builder ->add('start_date', PickRollingDateType::class, [ 'label' => 'start period date', - 'data' => new RollingDate(RollingDate::T_TODAY, new DateTimeImmutable('1 year ago')), + 'data' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), 'input' => 'datetime_immutable', ]) ->add('end_date', PickRollingDateType::class, [ diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByStartDateFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByStartDateFilter.php index 000f3447e..95314708f 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByStartDateFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/EvaluationFilters/ByStartDateFilter.php @@ -58,7 +58,7 @@ class ByStartDateFilter implements FilterInterface $builder ->add('start_date', PickRollingDateType::class, [ 'label' => 'start period date', - 'data' => new RollingDate(RollingDate::T_TODAY, new DateTimeImmutable('1 year ago')), + 'data' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START), 'input' => 'datetime_immutable', ]) ->add('end_date', PickRollingDateType::class, [ From 434ef075da9d3ccf8cf1903532bdc684b6ff3da1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 14 Nov 2022 17:06:26 +0100 Subject: [PATCH 5/6] Feature: Add geographical unit name and ref ids in list, associated to address --- .../Export/Helper/ExportAddressHelper.php | 165 +++++++++++++++++- 1 file changed, 157 insertions(+), 8 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Export/Helper/ExportAddressHelper.php b/src/Bundle/ChillMainBundle/Export/Helper/ExportAddressHelper.php index 701f9ed07..9077b501a 100644 --- a/src/Bundle/ChillMainBundle/Export/Helper/ExportAddressHelper.php +++ b/src/Bundle/ChillMainBundle/Export/Helper/ExportAddressHelper.php @@ -11,13 +11,16 @@ declare(strict_types=1); namespace Chill\MainBundle\Export\Helper; +use Chill\MainBundle\Entity\GeographicalUnit; +use Chill\MainBundle\Entity\GeographicalUnitLayer; use Chill\MainBundle\Repository\AddressRepository; +use Chill\MainBundle\Repository\GeographicalUnitLayerRepositoryInterface; use Chill\MainBundle\Templating\Entity\AddressRender; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Doctrine\ORM\QueryBuilder; use LogicException; -use Symfony\Component\PropertyAccess\PropertyAccess; -use Symfony\Component\PropertyAccess\PropertyAccessor; +use function array_key_exists; +use function count; use function in_array; use function strlen; @@ -26,9 +29,12 @@ use function strlen; */ class ExportAddressHelper { + /** + * Compute all the F_* constants. + */ public const F_ALL = self::F_ATTRIBUTES | self::F_BUILDING | self::F_COUNTRY | - self::F_GEOM | self::F_POSTAL_CODE | self::F_STREET; + self::F_GEOM | self::F_POSTAL_CODE | self::F_STREET | self::F_GEOGRAPHICAL_UNITS; public const F_AS_STRING = 0b00010000; @@ -38,6 +44,8 @@ class ExportAddressHelper public const F_COUNTRY = 0b00000001; + public const F_GEOGRAPHICAL_UNITS = 0b1000000000; + public const F_GEOM = 0b00100000; public const F_POSTAL_CODE = 0b00000010; @@ -52,6 +60,7 @@ class ExportAddressHelper 'string' => self::F_AS_STRING, 'geom' => self::F_GEOM, 'attributes' => self::F_ATTRIBUTES, + 'geographical_units' => self::F_GEOGRAPHICAL_UNITS, ]; private const COLUMN_MAPPING = [ @@ -62,23 +71,35 @@ class ExportAddressHelper 'string' => ['_as_string'], 'attributes' => ['isNoAddress', 'confidential', 'id'], 'geom' => ['_lat', '_lon'], + 'geographical_units' => ['_unit_names', '_unit_refs'], ]; private AddressRender $addressRender; private AddressRepository $addressRepository; - private PropertyAccessor $propertyAccess; + private GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository; private TranslatableStringHelperInterface $translatableStringHelper; + /** + * @var array>|null + */ + private ?array $unitNamesKeysCache = []; + + /** + * @var array>|null + */ + private ?array $unitRefsKeysCache = []; + public function __construct( + AddressRender $addressRender, AddressRepository $addressRepository, - TranslatableStringHelperInterface $translatableStringHelper, - AddressRender $addressRender + GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository, + TranslatableStringHelperInterface $translatableStringHelper ) { $this->addressRepository = $addressRepository; - $this->propertyAccess = PropertyAccess::createPropertyAccessor(); + $this->geographicalUnitLayerRepository = $geographicalUnitLayerRepository; $this->translatableStringHelper = $translatableStringHelper; $this->addressRender = $addressRender; } @@ -155,8 +176,60 @@ class ExportAddressHelper break; + case '_unit_names': + foreach ($this->generateKeysForUnitsNames($prefix) as $alias => $layer) { + $queryBuilder + ->addSelect( + sprintf( + '(SELECT AGGREGATE(u_n_%s_%s.unitName) FROM %s u_n_%s_%s WHERE u_n_%s_%s MEMBER OF %s.geographicalUnits AND u_n_%s_%s.layer = :layer_%s_%s) AS %s', + $prefix, + $layer->getId(), + GeographicalUnit::class, + $prefix, + $layer->getId(), + $prefix, + $layer->getId(), + $entityName, + $prefix, + $layer->getId(), + $prefix, + $layer->getId(), + $alias + ) + ) + ->setParameter(sprintf('layer_%s_%s', $prefix, $layer->getId()), $layer); + } + + break; + + case '_unit_refs': + foreach ($this->generateKeysForUnitsRefs($prefix) as $alias => $layer) { + $queryBuilder + ->addSelect( + sprintf( + '(SELECT AGGREGATE(u_r_%s_%s.unitRefId) FROM %s u_r_%s_%s WHERE u_r_%s_%s MEMBER OF %s.geographicalUnits AND u_r_%s_%s.layer = :layer_%s_%s) AS %s', + $prefix, + $layer->getId(), + GeographicalUnit::class, + $prefix, + $layer->getId(), + $prefix, + $layer->getId(), + $entityName, + $prefix, + $layer->getId(), + $prefix, + $layer->getId(), + $alias + ) + ) + ->setParameter(sprintf('layer_%s_%s', $prefix, $layer->getId()), $layer); + } + + break; + default: - throw new LogicException('This key is not supported: ' . $key); + throw new LogicException(sprintf('This key is not supported: %s, field %s', $key, $field)); } } } @@ -174,6 +247,13 @@ class ExportAddressHelper foreach (self::ALL as $key => $bitmask) { if (($params & $bitmask) === $bitmask) { + if ('geographical_units' === $key) { + // geographical unit generate keys dynamically, depending on layers + $prefixes = array_merge($prefixes, array_keys($this->generateKeysForUnitsNames($prefix)), array_keys($this->generateKeysForUnitsRefs($prefix))); + + continue; + } + $prefixes = array_merge( $prefixes, array_map( @@ -271,7 +351,76 @@ class ExportAddressHelper }; default: + $layerNamesKeys = array_merge($this->generateKeysForUnitsNames($prefix), $this->generateKeysForUnitsRefs($prefix)); + + if (array_key_exists($key, $layerNamesKeys)) { + return function ($value) use ($key, $layerNamesKeys) { + if ('_header' === $value) { + $header = $this->translatableStringHelper->localize($layerNamesKeys[$key]->getName()); + + if (str_contains($key, 'unit_ref')) { + $header .= ' (id)'; + } + + return $header; + } + + if (null === $value) { + return ''; + } + + $decodedValues = json_decode($value, true); + + switch (count($decodedValues)) { + case 0: + return ''; + + case 1: + return $decodedValues[0]; + + default: + return implode('|', $decodedValues); + } + }; + } + throw new LogicException('this key is not supported: ' . $sanitizedKey); } } + + /** + * @return array + */ + private function generateKeysForUnitsNames(string $prefix): array + { + if (array_key_exists($prefix, $this->unitNamesKeysCache)) { + return $this->unitNamesKeysCache[$prefix]; + } + + $keys = []; + + foreach ($this->geographicalUnitLayerRepository->findAllHavingUnits() as $layer) { + $keys[$prefix . 'unit_names_' . $layer->getId()] = $layer; + } + + return $this->unitNamesKeysCache[$prefix] = $keys; + } + + /** + * @return array + */ + private function generateKeysForUnitsRefs(string $prefix): array + { + if (array_key_exists($prefix, $this->unitRefsKeysCache)) { + return $this->unitRefsKeysCache[$prefix]; + } + + $keys = []; + + foreach ($this->geographicalUnitLayerRepository->findAllHavingUnits() as $layer) { + $keys[$prefix . 'unit_refs_' . $layer->getId()] = $layer; + } + + return $this->unitRefsKeysCache[$prefix] = $keys; + } } From 0e661784b00ee027ed58f3944f665df194a3b3ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 15 Nov 2022 18:17:58 +0100 Subject: [PATCH 6/6] DX: fix construct of ReferrerScopeAggregator in test --- .../ReferrerScopeAggregatorTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregatorTest.php b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregatorTest.php index 07ddf1376..09d5f99df 100644 --- a/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregatorTest.php +++ b/src/Bundle/ChillPersonBundle/Tests/Export/Aggregator/AccompanyingCourseAggregators/ReferrerScopeAggregatorTest.php @@ -13,6 +13,8 @@ namespace Export\Aggregator\AccompanyingCourseAggregators; use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Repository\ScopeRepositoryInterface; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Test\Export\AbstractAggregatorTest; use Chill\PersonBundle\Entity\AccompanyingPeriod; @@ -40,9 +42,13 @@ final class ReferrerScopeAggregatorTest extends AbstractAggregatorTest (new Scope())->setName(['fr' => 'scope']) ); + $dateConverter = $this->prophesize(RollingDateConverterInterface::class); + $dateConverter->convert(Argument::type(RollingDate::class))->willReturn(new DateTimeImmutable()); + return new ReferrerScopeAggregator( $scopeRepository->reveal(), - $translatableStringHelper->reveal() + $translatableStringHelper->reveal(), + $dateConverter->reveal() ); }