diff --git a/src/Bundle/ChillActivityBundle/Export/Filter/ActivityDateFilter.php b/src/Bundle/ChillActivityBundle/Export/Filter/ActivityDateFilter.php index 1f3a52cc5..f2216c929 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\Export\FilterType; -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; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -28,9 +29,14 @@ class ActivityDateFilter implements FilterInterface { protected TranslatorInterface $translator; - public function __construct(TranslatorInterface $translator) - { + private RollingDateConverterInterface $rollingDateConverter; + + public function __construct( + TranslatorInterface $translator, + RollingDateConverterInterface $rollingDateConverter + ) { $this->translator = $translator; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -54,8 +60,14 @@ 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 +78,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 +133,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..099c87fc0 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\Export\FilterType; -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\Andx; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -28,9 +29,14 @@ class ByDateFilter implements FilterInterface { protected TranslatorInterface $translator; - public function __construct(TranslatorInterface $translator) - { + private RollingDateConverterInterface $rollingDateConverter; + + public function __construct( + RollingDateConverterInterface $rollingDateConverter, + TranslatorInterface $translator + ) { $this->translator = $translator; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -54,8 +60,14 @@ 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 +78,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 +131,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 63004df21..8194e8c7c 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,15 @@ 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 +69,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 calendars between %dateFrom% and %dateTo%', [ - '%dateFrom%' => $data['date_from']->format('d-m-Y'), - '%dateTo%' => $data['date_to']->format('d-m-Y'), + return ['Filtered by appointments between %dateFrom% and %dateTo%', [ + '%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/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; + } } 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 %} diff --git a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/GeographicalUnitStatAggregator.php b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/GeographicalUnitStatAggregator.php index deb564001..e0606a959 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/GeographicalUnitStatAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/AccompanyingCourseAggregators/GeographicalUnitStatAggregator.php @@ -14,12 +14,13 @@ namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators; use Chill\MainBundle\Entity\Address; 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\Repository\GeographicalUnitLayerRepositoryInterface; +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; -use DateTimeImmutable; use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\QueryBuilder; use Symfony\Bridge\Doctrine\Form\Type\EntityType; @@ -30,14 +31,18 @@ final class GeographicalUnitStatAggregator implements AggregatorInterface { private GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository; + private RollingDateConverterInterface $rollingDateConverter; + private TranslatableStringHelperInterface $translatableStringHelper; public function __construct( GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository, - TranslatableStringHelperInterface $translatableStringHelper + TranslatableStringHelperInterface $translatableStringHelper, + RollingDateConverterInterface $rollingDateConverter ) { $this->geographicalUnitLayerRepository = $geographicalUnitLayerRepository; $this->translatableStringHelper = $translatableStringHelper; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -59,8 +64,6 @@ final class GeographicalUnitStatAggregator implements AggregatorInterface ) ); - $qb->setParameter('acp_geog_aggregator_date', $data['date_calc']); - // link between location history and person $qb->leftJoin( PersonHouseholdAddress::class, @@ -76,7 +79,10 @@ 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 $qb->leftJoin( @@ -112,11 +118,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..01bc3a459 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\Repository\UserRepository; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Templating\Entity\UserRender; use Chill\PersonBundle\Export\Declarations; -use DateTimeImmutable; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -26,16 +27,20 @@ final class ReferrerAggregator implements AggregatorInterface private const P = 'acp_ref_agg_date'; + private RollingDateConverterInterface $rollingDateConverter; + private UserRender $userRender; private UserRepository $userRepository; 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,10 @@ 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 +80,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..62f8cdef2 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\Repository\ScopeRepositoryInterface; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Export\Declarations; -use DateTimeImmutable; use Doctrine\ORM\QueryBuilder; use LogicException; use Symfony\Component\Form\FormBuilderInterface; @@ -25,16 +26,20 @@ 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; 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,10 @@ class ReferrerScopeAggregator implements AggregatorInterface ) ) ) - ->setParameter($dateCalc, $data['date_calc']); + ->setParameter( + $dateCalc, + $this->rollingDateConverter->convert($data['date_calc']) + ); // add groups $qb @@ -79,9 +87,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..0c9bc623f 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; @@ -24,12 +24,16 @@ use function in_array; class ChildrenNumberAggregator implements AggregatorInterface { + private RollingDateConverterInterface $rollingDateConverter; + private TranslatorInterface $translator; public function __construct( - TranslatorInterface $translator + TranslatorInterface $translator, + RollingDateConverterInterface $rollingDateConverter ) { $this->translator = $translator; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -55,7 +59,10 @@ 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 +72,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..19884dd10 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; @@ -25,16 +25,20 @@ use function in_array; class CompositionAggregator implements AggregatorInterface { + private RollingDateConverterInterface $rollingDateConverter; + private TranslatableStringHelper $translatableStringHelper; private HouseholdCompositionTypeRepository $typeRepository; 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,10 @@ 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 +77,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..03e5f17ce 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; @@ -28,12 +29,18 @@ class ByHouseholdCompositionAggregator implements AggregatorInterface private HouseholdCompositionTypeRepositoryInterface $householdCompositionTypeRepository; + private RollingDateConverterInterface $rollingDateConverter; + private TranslatableStringHelperInterface $translatableStringHelper; - public function __construct(HouseholdCompositionTypeRepositoryInterface $householdCompositionTypeRepository, TranslatableStringHelperInterface $translatableStringHelper) - { + 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,10 @@ 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 +92,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 87fe6abb2..6193f3c61 100644 --- a/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/GeographicalUnitAggregator.php +++ b/src/Bundle/ChillPersonBundle/Export/Aggregator/PersonAggregators/GeographicalUnitAggregator.php @@ -13,11 +13,12 @@ namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators; 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\Repository\GeographicalUnitLayerRepositoryInterface; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Export\Declarations; -use DateTimeImmutable; use Doctrine\ORM\QueryBuilder; use LogicException; use Symfony\Bridge\Doctrine\Form\Type\EntityType; @@ -27,14 +28,18 @@ class GeographicalUnitAggregator implements AggregatorInterface { private GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository; + private RollingDateConverterInterface $rollingDateConverter; + private TranslatableStringHelperInterface $translatableStringHelper; public function __construct( GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository, - TranslatableStringHelperInterface $translatableStringHelper + TranslatableStringHelperInterface $translatableStringHelper, + RollingDateConverterInterface $rollingDateConverter ) { $this->geographicalUnitLayerRepository = $geographicalUnitLayerRepository; $this->translatableStringHelper = $translatableStringHelper; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -66,7 +71,10 @@ 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') @@ -82,11 +90,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..ea516dbb0 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; @@ -30,6 +31,8 @@ final class HouseholdPositionAggregator implements AggregatorInterface, ExportEl { private PositionRepository $positionRepository; + private RollingDateConverterInterface $rollingDateConverter; + private TranslatableStringHelper $translatableStringHelper; private TranslatorInterface $translator; @@ -37,11 +40,13 @@ final class HouseholdPositionAggregator implements AggregatorInterface, ExportEl 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,10 @@ 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 +88,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..3fa8d711f 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,10 @@ 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 +67,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..f713e8a97 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,14 @@ 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 +56,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 67355aeca..d7625711c 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/GeographicalUnitStatFilter.php @@ -14,14 +14,15 @@ namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; use Chill\MainBundle\Entity\Address; 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\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; use Chill\PersonBundle\Export\Declarations; -use DateTimeImmutable; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; @@ -35,16 +36,20 @@ class GeographicalUnitStatFilter implements FilterInterface private GeographicalUnitRepositoryInterface $geographicalUnitRepository; + private RollingDateConverterInterface $rollingDateConverter; + private TranslatableStringHelperInterface $translatableStringHelper; 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 @@ -77,7 +82,10 @@ 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'])); } @@ -89,11 +97,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', @@ -113,8 +120,8 @@ 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'), - '%units%' => implode( + '%date%' => $this->rollingDateConverter->convert($data['date_calc'])->format('d-m-Y'), + '%units' => implode( ', ', array_map( function (SimpleGeographicalUnitDTO $item) { diff --git a/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasNoReferrerFilter.php b/src/Bundle/ChillPersonBundle/Export/Filter/AccompanyingCourseFilters/HasNoReferrerFilter.php index 303c789af..4c682a56a 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,10 @@ 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 +63,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..7aadde734 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,10 @@ 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 +89,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..b37d90d84 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\Form\Type\PickUserDynamicType; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Templating\Entity\UserRender; use Chill\PersonBundle\Export\Declarations; -use DateTimeImmutable; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\FormBuilderInterface; @@ -28,11 +29,16 @@ class ReferrerFilter implements FilterInterface private const PU = 'acp_referrer_filter_users'; + private RollingDateConverterInterface $rollingDateConverter; + private UserRender $userRender; - public function __construct(UserRender $userRender) - { + public function __construct( + UserRender $userRender, + RollingDateConverterInterface $rollingDateConverter + ) { $this->userRender = $userRender; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -57,7 +63,10 @@ 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 +80,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..b97f97dda 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\Repository\UserJobRepositoryInterface; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; 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; @@ -34,6 +35,8 @@ class UserJobFilter implements FilterInterface private const PJ = 'acp_ujob_filter_job'; + private RollingDateConverterInterface $rollingDateConverter; + private Security $security; private TranslatableStringHelper $translatableStringHelper; @@ -43,11 +46,13 @@ class UserJobFilter implements FilterInterface 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,10 @@ 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 +100,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..bbffa4bca 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\Repository\ScopeRepositoryInterface; +use Chill\MainBundle\Service\RollingDate\RollingDate; +use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; 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; @@ -34,6 +35,8 @@ class UserScopeFilter implements FilterInterface private const PS = 'acp_uscope_filter_scopes'; + private RollingDateConverterInterface $rollingDateConverter; + private ScopeRepositoryInterface $scopeRepository; private Security $security; @@ -43,11 +46,13 @@ class UserScopeFilter implements FilterInterface 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,10 @@ 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 +99,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..2dd9192bd 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,14 @@ 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 +56,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_YEAR_PREVIOUS_START), '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..95314708f 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,14 @@ 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 +56,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_YEAR_PREVIOUS_START), '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..922702418 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; @@ -26,12 +26,16 @@ use function in_array; class CompositionFilter implements FilterInterface { + private RollingDateConverterInterface $rollingDateConverter; + private TranslatableStringHelper $translatableStringHelper; public function __construct( - TranslatableStringHelper $translatableStringHelper + TranslatableStringHelper $translatableStringHelper, + RollingDateConverterInterface $rollingDateConverter ) { $this->translatableStringHelper = $translatableStringHelper; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -58,7 +62,10 @@ 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 +86,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 +103,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..7ae22ddd8 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,14 @@ 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 +67,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 +84,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..0ac4b3173 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,14 @@ 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 +70,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 +85,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 3d539a442..773325580 100644 --- a/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GeographicalUnitFilter.php +++ b/src/Bundle/ChillPersonBundle/Export/Filter/PersonFilters/GeographicalUnitFilter.php @@ -12,13 +12,14 @@ declare(strict_types=1); namespace Chill\PersonBundle\Export\Filter\PersonFilters; use Chill\MainBundle\Entity\GeographicalUnit\SimpleGeographicalUnitDTO; -use Chill\MainBundle\Form\Type\ChillDateType; +use Chill\MainBundle\Form\Type\PickRollingDateType; 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; -use DateTimeImmutable; use Doctrine\ORM\QueryBuilder; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\FormBuilderInterface; @@ -29,16 +30,20 @@ class GeographicalUnitFilter implements \Chill\MainBundle\Export\FilterInterface private GeographicalUnitRepositoryInterface $geographicalUnitRepository; + private RollingDateConverterInterface $rollingDateConverter; + private TranslatableStringHelperInterface $translatableStringHelper; 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 @@ -68,7 +73,10 @@ 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'])); } @@ -80,11 +88,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', @@ -106,7 +113,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..90003c6bf 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; @@ -26,11 +27,16 @@ use function in_array; class ResidentialAddressAtThirdpartyFilter implements FilterInterface { + private RollingDateConverterInterface $rollingDateConverter; + private TranslatableStringHelper $translatableStringHelper; - public function __construct(TranslatableStringHelper $translatableStringHelper) - { + public function __construct( + RollingDateConverterInterface $rollingDateConverter, + TranslatableStringHelper $translatableStringHelper + ) { $this->translatableStringHelper = $translatableStringHelper; + $this->rollingDateConverter = $rollingDateConverter; } public function addRole(): ?string @@ -77,7 +83,10 @@ 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 +107,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 +117,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..bd55c5b80 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,10 @@ 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 +80,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/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() ); } diff --git a/src/Bundle/ChillReportBundle/Export/Filter/ReportDateFilter.php b/src/Bundle/ChillReportBundle/Export/Filter/ReportDateFilter.php index ec4ea7fc5..79bad4f52 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,14 @@ 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 +65,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 +80,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'), ], ]; }