Merge branch '111_exports_suite' into testing

This commit is contained in:
Julien Fastré 2022-11-16 14:32:54 +01:00
commit dafd715efd
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
35 changed files with 733 additions and 280 deletions

View File

@ -13,9 +13,10 @@ namespace Chill\ActivityBundle\Export\Filter;
use Chill\ActivityBundle\Export\Declarations; use Chill\ActivityBundle\Export\Declarations;
use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Form\Type\Export\FilterType; 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\Query\Expr;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -28,9 +29,14 @@ class ActivityDateFilter implements FilterInterface
{ {
protected TranslatorInterface $translator; protected TranslatorInterface $translator;
public function __construct(TranslatorInterface $translator) private RollingDateConverterInterface $rollingDateConverter;
{
public function __construct(
TranslatorInterface $translator,
RollingDateConverterInterface $rollingDateConverter
) {
$this->translator = $translator; $this->translator = $translator;
$this->rollingDateConverter = $rollingDateConverter;
} }
public function addRole(): ?string public function addRole(): ?string
@ -54,8 +60,14 @@ class ActivityDateFilter implements FilterInterface
} }
$qb->add('where', $where); $qb->add('where', $where);
$qb->setParameter('date_from', $data['date_from']); $qb->setParameter(
$qb->setParameter('date_to', $data['date_to']); 'date_from',
$this->rollingDateConverter->convert($data['date_from'])
);
$qb->setParameter(
'date_to',
$this->rollingDateConverter->convert($data['date_to'])
);
} }
public function applyOn(): string public function applyOn(): string
@ -66,13 +78,13 @@ class ActivityDateFilter implements FilterInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
$builder $builder
->add('date_from', ChillDateType::class, [ ->add('date_from', PickRollingDateType::class, [
'label' => 'Activities after this date', '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', 'label' => 'Activities before this date',
'data' => new DateTime(), 'data' => new RollingDate(RollingDate::T_TODAY),
]); ]);
$builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
@ -121,8 +133,8 @@ class ActivityDateFilter implements FilterInterface
return [ return [
'Filtered by date of activity: only between %date_from% and %date_to%', 'Filtered by date of activity: only between %date_from% and %date_to%',
[ [
'%date_from%' => $data['date_from']->format('d-m-Y'), '%date_from%' => $this->rollingDateConverter->convert($data['date_from'])->format('d-m-Y'),
'%date_to%' => $data['date_to']->format('d-m-Y'), '%date_to%' => $this->rollingDateConverter->convert($data['date_to'])->format('d-m-Y'),
], ],
]; ];
} }

View File

@ -13,9 +13,10 @@ namespace Chill\AsideActivityBundle\Export\Filter;
use Chill\AsideActivityBundle\Export\Declarations; use Chill\AsideActivityBundle\Export\Declarations;
use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Form\Type\Export\FilterType; 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\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -28,9 +29,14 @@ class ByDateFilter implements FilterInterface
{ {
protected TranslatorInterface $translator; protected TranslatorInterface $translator;
public function __construct(TranslatorInterface $translator) private RollingDateConverterInterface $rollingDateConverter;
{
public function __construct(
RollingDateConverterInterface $rollingDateConverter,
TranslatorInterface $translator
) {
$this->translator = $translator; $this->translator = $translator;
$this->rollingDateConverter = $rollingDateConverter;
} }
public function addRole(): ?string public function addRole(): ?string
@ -54,8 +60,14 @@ class ByDateFilter implements FilterInterface
} }
$qb->add('where', $where); $qb->add('where', $where);
$qb->setParameter('date_from', $data['date_from']); $qb->setParameter(
$qb->setParameter('date_to', $data['date_to']); 'date_from',
$this->rollingDateConverter->convert($data['date_from'])
);
$qb->setParameter(
'date_to',
$this->rollingDateConverter->convert($data['date_to'])
);
} }
public function applyOn(): string public function applyOn(): string
@ -66,13 +78,13 @@ class ByDateFilter implements FilterInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
$builder $builder
->add('date_from', ChillDateType::class, [ ->add('date_from', PickRollingDateType::class, [
'label' => 'export.filter.Aside activities after this date', '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', '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) { $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
@ -119,8 +131,8 @@ class ByDateFilter implements FilterInterface
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {
return ['export.filter.Filtered by aside activities between %dateFrom% and %dateTo%', [ return ['export.filter.Filtered by aside activities between %dateFrom% and %dateTo%', [
'%dateFrom%' => $data['date_from']->format('d-m-Y'), '%dateFrom%' => $this->rollingDateConverter->convert($data['date_from'])->format('d-m-Y'),
'%dateTo%' => $data['date_to']->format('d-m-Y'), '%dateTo%' => $this->rollingDateConverter->convert($data['date_to'])->format('d-m-Y'),
]]; ]];
} }

View File

@ -13,15 +13,22 @@ namespace Chill\CalendarBundle\Export\Filter;
use Chill\CalendarBundle\Export\Declarations; use Chill\CalendarBundle\Export\Declarations;
use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Form\Type\PickRollingDateType;
use DateTime; use Chill\MainBundle\Service\RollingDate\RollingDate;
use Doctrine\DBAL\Types\Types; use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Doctrine\ORM\Query\Expr\Andx; use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class BetweenDatesFilter implements FilterInterface class BetweenDatesFilter implements FilterInterface
{ {
private RollingDateConverterInterface $rollingDateConverter;
public function __construct(RollingDateConverterInterface $rollingDateConverter)
{
$this->rollingDateConverter = $rollingDateConverter;
}
public function addRole(): ?string public function addRole(): ?string
{ {
return null; return null;
@ -43,9 +50,15 @@ class BetweenDatesFilter implements FilterInterface
} }
$qb->add('where', $where); $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. // 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 public function applyOn(): string
@ -56,19 +69,19 @@ class BetweenDatesFilter implements FilterInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
$builder $builder
->add('date_from', ChillDateType::class, [ ->add('date_from', PickRollingDateType::class, [
'data' => new DateTime(), 'data' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START),
]) ])
->add('date_to', ChillDateType::class, [ ->add('date_to', PickRollingDateType::class, [
'data' => new DateTime(), 'data' => new RollingDate(RollingDate::T_TODAY),
]); ]);
} }
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {
return ['Filtered by calendars between %dateFrom% and %dateTo%', [ return ['Filtered by appointments between %dateFrom% and %dateTo%', [
'%dateFrom%' => $data['date_from']->format('d-m-Y'), '%dateFrom%' => $this->rollingDateConverter->convert($data['date_from'])->format('d-m-Y'),
'%dateTo%' => $data['date_to']->format('d-m-Y'), '%dateTo%' => $this->rollingDateConverter->convert($data['date_to'])->format('d-m-Y'),
]]; ]];
} }

View File

@ -11,13 +11,16 @@ declare(strict_types=1);
namespace Chill\MainBundle\Export\Helper; namespace Chill\MainBundle\Export\Helper;
use Chill\MainBundle\Entity\GeographicalUnit;
use Chill\MainBundle\Entity\GeographicalUnitLayer;
use Chill\MainBundle\Repository\AddressRepository; use Chill\MainBundle\Repository\AddressRepository;
use Chill\MainBundle\Repository\GeographicalUnitLayerRepositoryInterface;
use Chill\MainBundle\Templating\Entity\AddressRender; use Chill\MainBundle\Templating\Entity\AddressRender;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use LogicException; use LogicException;
use Symfony\Component\PropertyAccess\PropertyAccess; use function array_key_exists;
use Symfony\Component\PropertyAccess\PropertyAccessor; use function count;
use function in_array; use function in_array;
use function strlen; use function strlen;
@ -26,9 +29,12 @@ use function strlen;
*/ */
class ExportAddressHelper class ExportAddressHelper
{ {
/**
* Compute all the F_* constants.
*/
public const F_ALL = public const F_ALL =
self::F_ATTRIBUTES | self::F_BUILDING | self::F_COUNTRY | 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; public const F_AS_STRING = 0b00010000;
@ -38,6 +44,8 @@ class ExportAddressHelper
public const F_COUNTRY = 0b00000001; public const F_COUNTRY = 0b00000001;
public const F_GEOGRAPHICAL_UNITS = 0b1000000000;
public const F_GEOM = 0b00100000; public const F_GEOM = 0b00100000;
public const F_POSTAL_CODE = 0b00000010; public const F_POSTAL_CODE = 0b00000010;
@ -52,6 +60,7 @@ class ExportAddressHelper
'string' => self::F_AS_STRING, 'string' => self::F_AS_STRING,
'geom' => self::F_GEOM, 'geom' => self::F_GEOM,
'attributes' => self::F_ATTRIBUTES, 'attributes' => self::F_ATTRIBUTES,
'geographical_units' => self::F_GEOGRAPHICAL_UNITS,
]; ];
private const COLUMN_MAPPING = [ private const COLUMN_MAPPING = [
@ -62,23 +71,35 @@ class ExportAddressHelper
'string' => ['_as_string'], 'string' => ['_as_string'],
'attributes' => ['isNoAddress', 'confidential', 'id'], 'attributes' => ['isNoAddress', 'confidential', 'id'],
'geom' => ['_lat', '_lon'], 'geom' => ['_lat', '_lon'],
'geographical_units' => ['_unit_names', '_unit_refs'],
]; ];
private AddressRender $addressRender; private AddressRender $addressRender;
private AddressRepository $addressRepository; private AddressRepository $addressRepository;
private PropertyAccessor $propertyAccess; private GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository;
private TranslatableStringHelperInterface $translatableStringHelper; private TranslatableStringHelperInterface $translatableStringHelper;
/**
* @var array<string, string, GeographicalUnitLayer>>|null
*/
private ?array $unitNamesKeysCache = [];
/**
* @var array<string, array<string, GeographicalUnitLayer>>|null
*/
private ?array $unitRefsKeysCache = [];
public function __construct( public function __construct(
AddressRender $addressRender,
AddressRepository $addressRepository, AddressRepository $addressRepository,
TranslatableStringHelperInterface $translatableStringHelper, GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository,
AddressRender $addressRender TranslatableStringHelperInterface $translatableStringHelper
) { ) {
$this->addressRepository = $addressRepository; $this->addressRepository = $addressRepository;
$this->propertyAccess = PropertyAccess::createPropertyAccessor(); $this->geographicalUnitLayerRepository = $geographicalUnitLayerRepository;
$this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
$this->addressRender = $addressRender; $this->addressRender = $addressRender;
} }
@ -155,8 +176,60 @@ class ExportAddressHelper
break; 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: 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) { foreach (self::ALL as $key => $bitmask) {
if (($params & $bitmask) === $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_merge(
$prefixes, $prefixes,
array_map( array_map(
@ -271,7 +351,76 @@ class ExportAddressHelper
}; };
default: 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); throw new LogicException('this key is not supported: ' . $sanitizedKey);
} }
} }
/**
* @return array<string, GeographicalUnitLayer>
*/
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<string, GeographicalUnitLayer>
*/
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;
}
} }

View File

@ -518,8 +518,14 @@ div.v-toast {
z-index: 10000!important; z-index: 10000!important;
} }
div.grouped { // export index page
padding: 1em; div.exports-list {
border: 1px solid black; div.flex-bloc .item-bloc {
margin-bottom: 2em; 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;
}
}
} }

View File

@ -25,25 +25,23 @@
{{ include('@ChillMain/Export/_navbar.html.twig', {'current' : 'common'}) }} {{ include('@ChillMain/Export/_navbar.html.twig', {'current' : 'common'}) }}
<div class="col-md-10"> <div class="col-md-10 exports-list">
<div class="container mt-4"> <div class="container mt-4">
{% for group, exports in grouped_exports %}{% if group != '_' %} {% for group, exports in grouped_exports %}{% if group != '_' %}
<h2 class="display-6">{{ group|trans }}</h2> <h2 class="display-6">{{ group|trans }}</h2>
<div class="row grouped"> <div class="row flex-bloc">
{% for export_alias, export in exports %} {% for export_alias, export in exports %}
<div class="col-6 col-md-4 mb-3"> <div class="item-bloc">
<div class="card"> <div class="item-row card-body">
<div class="card-body"> <h2 class="card-title">{{ export.title|trans }}</h2>
<h2 class="card-title">{{ export.title|trans }}</h2> <p class="card-text my-3">{{ export.description|trans }}</p>
<p class="card-text">{{ export.description|trans }}</p> <p>
<p> <a class="btn btn-action" href="{{ path('chill_main_export_new', { 'alias': export_alias } ) }}">
<a class="btn btn-action" href="{{ path('chill_main_export_new', { 'alias': export_alias } ) }}"> {{ 'Create an export'|trans }}
{{ 'Create an export'|trans }} </a>
</a> </p>
</p>
</div>
</div> </div>
</div> </div>
{% endfor %} {% endfor %}

View File

@ -14,12 +14,13 @@ namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Entity\Address; use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\GeographicalUnitLayer; use Chill\MainBundle\Entity\GeographicalUnitLayer;
use Chill\MainBundle\Export\AggregatorInterface; 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\Repository\GeographicalUnitLayerRepositoryInterface;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress; use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use DateTimeImmutable;
use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
@ -30,14 +31,18 @@ final class GeographicalUnitStatAggregator implements AggregatorInterface
{ {
private GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository; private GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository;
private RollingDateConverterInterface $rollingDateConverter;
private TranslatableStringHelperInterface $translatableStringHelper; private TranslatableStringHelperInterface $translatableStringHelper;
public function __construct( public function __construct(
GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository, GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository,
TranslatableStringHelperInterface $translatableStringHelper TranslatableStringHelperInterface $translatableStringHelper,
RollingDateConverterInterface $rollingDateConverter
) { ) {
$this->geographicalUnitLayerRepository = $geographicalUnitLayerRepository; $this->geographicalUnitLayerRepository = $geographicalUnitLayerRepository;
$this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
$this->rollingDateConverter = $rollingDateConverter;
} }
public function addRole(): ?string 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 // link between location history and person
$qb->leftJoin( $qb->leftJoin(
PersonHouseholdAddress::class, 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 // we finally find an address
$qb->leftJoin( $qb->leftJoin(
@ -112,11 +118,10 @@ final class GeographicalUnitStatAggregator implements AggregatorInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
$builder $builder
->add('date_calc', ChillDateType::class, [ ->add('date_calc', PickRollingDateType::class, [
'label' => 'Compute geographical location at date', 'label' => 'Compute geographical location at date',
'required' => true, 'required' => true,
'data' => new DateTimeImmutable('today'), 'data' => new RollingDate(RollingDate::T_TODAY),
'input' => 'datetime_immutable',
]) ])
->add('level', EntityType::class, [ ->add('level', EntityType::class, [
'label' => 'Geographical layer', 'label' => 'Geographical layer',

View File

@ -12,11 +12,12 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators; namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Export\AggregatorInterface; 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\Repository\UserRepository;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Templating\Entity\UserRender; use Chill\MainBundle\Templating\Entity\UserRender;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use DateTimeImmutable;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -26,16 +27,20 @@ final class ReferrerAggregator implements AggregatorInterface
private const P = 'acp_ref_agg_date'; private const P = 'acp_ref_agg_date';
private RollingDateConverterInterface $rollingDateConverter;
private UserRender $userRender; private UserRender $userRender;
private UserRepository $userRepository; private UserRepository $userRepository;
public function __construct( public function __construct(
UserRepository $userRepository, UserRepository $userRepository,
UserRender $userRender UserRender $userRender,
RollingDateConverterInterface $rollingDateConverter
) { ) {
$this->userRepository = $userRepository; $this->userRepository = $userRepository;
$this->userRender = $userRender; $this->userRender = $userRender;
$this->rollingDateConverter = $rollingDateConverter;
} }
public function addRole(): ?string 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 public function applyOn(): string
@ -72,9 +80,8 @@ final class ReferrerAggregator implements AggregatorInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
$builder $builder
->add('date_calc', ChillDateType::class, [ ->add('date_calc', PickRollingDateType::class, [
'input' => 'datetime_immutable', 'data' => new RollingDate(RollingDate::T_TODAY),
'data' => new DateTimeImmutable('now'),
'label' => 'export.aggregator.course.by_referrer.Computation date for referrer', 'label' => 'export.aggregator.course.by_referrer.Computation date for referrer',
'required' => true, 'required' => true,
]); ]);

View File

@ -12,11 +12,12 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators; namespace Chill\PersonBundle\Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Export\AggregatorInterface; 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\Repository\ScopeRepositoryInterface;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use DateTimeImmutable;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use LogicException; use LogicException;
use Symfony\Component\Form\FormBuilderInterface; 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 const SCOPE_KEY = 'acp_agg_refscope_user_history_ref_scope_name';
private RollingDateConverterInterface $rollingDateConverter;
private ScopeRepositoryInterface $scopeRepository; private ScopeRepositoryInterface $scopeRepository;
private TranslatableStringHelperInterface $translatableStringHelper; private TranslatableStringHelperInterface $translatableStringHelper;
public function __construct( public function __construct(
ScopeRepositoryInterface $scopeRepository, ScopeRepositoryInterface $scopeRepository,
TranslatableStringHelperInterface $translatableStringHelper TranslatableStringHelperInterface $translatableStringHelper,
RollingDateConverterInterface $rollingDateConverter
) { ) {
$this->scopeRepository = $scopeRepository; $this->scopeRepository = $scopeRepository;
$this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
$this->rollingDateConverter = $rollingDateConverter;
} }
public function addRole(): ?string 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 // add groups
$qb $qb
@ -79,9 +87,8 @@ class ReferrerScopeAggregator implements AggregatorInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
$builder->add('date_calc', ChillDateType::class, [ $builder->add('date_calc', PickRollingDateType::class, [
'input' => 'datetime_immutable', 'data' => new RollingDate(RollingDate::T_TODAY),
'data' => new DateTimeImmutable('now'),
'label' => 'export.aggregator.course.by_user_scope.Computation date for referrer', 'label' => 'export.aggregator.course.by_user_scope.Computation date for referrer',
'required' => true, 'required' => true,
]); ]);

View File

@ -12,10 +12,10 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\HouseholdAggregators; namespace Chill\PersonBundle\Export\Aggregator\HouseholdAggregators;
use Chill\MainBundle\Export\AggregatorInterface; 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 Chill\PersonBundle\Export\Declarations;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -24,12 +24,16 @@ use function in_array;
class ChildrenNumberAggregator implements AggregatorInterface class ChildrenNumberAggregator implements AggregatorInterface
{ {
private RollingDateConverterInterface $rollingDateConverter;
private TranslatorInterface $translator; private TranslatorInterface $translator;
public function __construct( public function __construct(
TranslatorInterface $translator TranslatorInterface $translator,
RollingDateConverterInterface $rollingDateConverter
) { ) {
$this->translator = $translator; $this->translator = $translator;
$this->rollingDateConverter = $rollingDateConverter;
} }
public function addRole(): ?string public function addRole(): ?string
@ -55,7 +59,10 @@ class ChildrenNumberAggregator implements AggregatorInterface
->addSelect('composition_children.numberOfChildren AS childrennumber_aggregator') ->addSelect('composition_children.numberOfChildren AS childrennumber_aggregator')
->addGroupBy('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 public function applyOn(): string
@ -65,8 +72,8 @@ class ChildrenNumberAggregator implements AggregatorInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
$builder->add('on_date', ChillDateType::class, [ $builder->add('on_date', PickRollingDateType::class, [
'data' => new DateTime('now'), 'data' => new RollingDate(RollingDate::T_TODAY),
]); ]);
} }

View File

@ -12,12 +12,12 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\HouseholdAggregators; namespace Chill\PersonBundle\Export\Aggregator\HouseholdAggregators;
use Chill\MainBundle\Export\AggregatorInterface; 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\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\Household\HouseholdCompositionTypeRepository; use Chill\PersonBundle\Repository\Household\HouseholdCompositionTypeRepository;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -25,16 +25,20 @@ use function in_array;
class CompositionAggregator implements AggregatorInterface class CompositionAggregator implements AggregatorInterface
{ {
private RollingDateConverterInterface $rollingDateConverter;
private TranslatableStringHelper $translatableStringHelper; private TranslatableStringHelper $translatableStringHelper;
private HouseholdCompositionTypeRepository $typeRepository; private HouseholdCompositionTypeRepository $typeRepository;
public function __construct( public function __construct(
HouseholdCompositionTypeRepository $typeRepository, HouseholdCompositionTypeRepository $typeRepository,
TranslatableStringHelper $translatableStringHelper TranslatableStringHelper $translatableStringHelper,
RollingDateConverterInterface $rollingDateConverter
) { ) {
$this->typeRepository = $typeRepository; $this->typeRepository = $typeRepository;
$this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
$this->rollingDateConverter = $rollingDateConverter;
} }
public function addRole(): ?string public function addRole(): ?string
@ -60,7 +64,10 @@ class CompositionAggregator implements AggregatorInterface
->addSelect('IDENTITY(composition_type.householdCompositionType) AS composition_aggregator') ->addSelect('IDENTITY(composition_type.householdCompositionType) AS composition_aggregator')
->addGroupBy('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 public function applyOn(): string
@ -70,8 +77,8 @@ class CompositionAggregator implements AggregatorInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
$builder->add('on_date', ChillDateType::class, [ $builder->add('on_date', PickRollingDateType::class, [
'data' => new DateTime('now'), 'data' => new RollingDate(RollingDate::T_TODAY),
]); ]);
} }

View File

@ -12,12 +12,13 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators; namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators;
use Chill\MainBundle\Export\AggregatorInterface; 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\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\Household\HouseholdComposition; use Chill\PersonBundle\Entity\Household\HouseholdComposition;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\Household\HouseholdCompositionTypeRepositoryInterface; use Chill\PersonBundle\Repository\Household\HouseholdCompositionTypeRepositoryInterface;
use DateTimeImmutable;
use Doctrine\ORM\Query\Expr\Join; use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -28,12 +29,18 @@ class ByHouseholdCompositionAggregator implements AggregatorInterface
private HouseholdCompositionTypeRepositoryInterface $householdCompositionTypeRepository; private HouseholdCompositionTypeRepositoryInterface $householdCompositionTypeRepository;
private RollingDateConverterInterface $rollingDateConverter;
private TranslatableStringHelperInterface $translatableStringHelper; private TranslatableStringHelperInterface $translatableStringHelper;
public function __construct(HouseholdCompositionTypeRepositoryInterface $householdCompositionTypeRepository, TranslatableStringHelperInterface $translatableStringHelper) public function __construct(
{ RollingDateConverterInterface $rollingDateConverter,
HouseholdCompositionTypeRepositoryInterface $householdCompositionTypeRepository,
TranslatableStringHelperInterface $translatableStringHelper
) {
$this->householdCompositionTypeRepository = $householdCompositionTypeRepository; $this->householdCompositionTypeRepository = $householdCompositionTypeRepository;
$this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
$this->rollingDateConverter = $rollingDateConverter;
} }
public function addRole(): ?string public function addRole(): ?string
@ -71,7 +78,10 @@ class ByHouseholdCompositionAggregator implements AggregatorInterface
) )
) )
->addSelect("IDENTITY({$p}_compo.householdCompositionType) AS {$p}_select") ->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"); ->addGroupBy("{$p}_select");
} }
@ -82,10 +92,9 @@ class ByHouseholdCompositionAggregator implements AggregatorInterface
public function buildForm(FormBuilderInterface $builder) 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', 'label' => 'export.aggregator.person.by_household_composition.Calc date',
'input_format' => 'datetime_immutable', 'data' => new RollingDate(RollingDate::T_TODAY),
'data' => new DateTimeImmutable('now'),
]); ]);
} }

View File

@ -13,11 +13,12 @@ namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators;
use Chill\MainBundle\Entity\GeographicalUnitLayer; use Chill\MainBundle\Entity\GeographicalUnitLayer;
use Chill\MainBundle\Export\AggregatorInterface; 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\Repository\GeographicalUnitLayerRepositoryInterface;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use DateTimeImmutable;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use LogicException; use LogicException;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
@ -27,14 +28,18 @@ class GeographicalUnitAggregator implements AggregatorInterface
{ {
private GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository; private GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository;
private RollingDateConverterInterface $rollingDateConverter;
private TranslatableStringHelperInterface $translatableStringHelper; private TranslatableStringHelperInterface $translatableStringHelper;
public function __construct( public function __construct(
GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository, GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository,
TranslatableStringHelperInterface $translatableStringHelper TranslatableStringHelperInterface $translatableStringHelper,
RollingDateConverterInterface $rollingDateConverter
) { ) {
$this->geographicalUnitLayerRepository = $geographicalUnitLayerRepository; $this->geographicalUnitLayerRepository = $geographicalUnitLayerRepository;
$this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
$this->rollingDateConverter = $rollingDateConverter;
} }
public function addRole(): ?string 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') $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']) ->setParameter('person_geog_agg_layers', $data['level'])
->addSelect('person_geog_agg_geog_unit.unitName AS geog_unit_name') ->addSelect('person_geog_agg_geog_unit.unitName AS geog_unit_name')
->addSelect('person_geog_agg_geog_unit.unitRefId AS geog_unit_key') ->addSelect('person_geog_agg_geog_unit.unitRefId AS geog_unit_key')
@ -82,11 +90,10 @@ class GeographicalUnitAggregator implements AggregatorInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
$builder $builder
->add('date_calc', ChillDateType::class, [ ->add('date_calc', PickRollingDateType::class, [
'label' => 'Address valid at this date', 'label' => 'Address valid at this date',
'required' => true, 'required' => true,
'data' => new DateTimeImmutable('today'), 'data' => new RollingDate(RollingDate::T_TODAY),
'input' => 'datetime_immutable',
]) ])
->add('level', EntityType::class, [ ->add('level', EntityType::class, [
'label' => 'Geographical layer', 'label' => 'Geographical layer',

View File

@ -13,12 +13,13 @@ namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators;
use Chill\MainBundle\Export\AggregatorInterface; use Chill\MainBundle\Export\AggregatorInterface;
use Chill\MainBundle\Export\ExportElementValidatedInterface; 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\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\Household\HouseholdMember; use Chill\PersonBundle\Entity\Household\HouseholdMember;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use Chill\PersonBundle\Repository\Household\PositionRepository; use Chill\PersonBundle\Repository\Household\PositionRepository;
use DateTime;
use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -30,6 +31,8 @@ final class HouseholdPositionAggregator implements AggregatorInterface, ExportEl
{ {
private PositionRepository $positionRepository; private PositionRepository $positionRepository;
private RollingDateConverterInterface $rollingDateConverter;
private TranslatableStringHelper $translatableStringHelper; private TranslatableStringHelper $translatableStringHelper;
private TranslatorInterface $translator; private TranslatorInterface $translator;
@ -37,11 +40,13 @@ final class HouseholdPositionAggregator implements AggregatorInterface, ExportEl
public function __construct( public function __construct(
TranslatorInterface $translator, TranslatorInterface $translator,
TranslatableStringHelper $translatableStringHelper, TranslatableStringHelper $translatableStringHelper,
PositionRepository $positionRepository PositionRepository $positionRepository,
RollingDateConverterInterface $rollingDateConverter
) { ) {
$this->translator = $translator; $this->translator = $translator;
$this->positionRepository = $positionRepository; $this->positionRepository = $positionRepository;
$this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
$this->rollingDateConverter = $rollingDateConverter;
} }
public function addRole(): ?string 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->addSelect('IDENTITY(householdmember.position) AS household_position_aggregator');
$qb->addGroupBy('household_position_aggregator'); $qb->addGroupBy('household_position_aggregator');
@ -80,9 +88,9 @@ final class HouseholdPositionAggregator implements AggregatorInterface, ExportEl
public function buildForm(FormBuilderInterface $builder) 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', 'label' => 'Household position in relation to this date',
'data' => new DateTime(), 'data' => new RollingDate(RollingDate::T_TODAY),
]); ]);
} }

View File

@ -12,16 +12,23 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Export\FilterInterface; 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 Chill\PersonBundle\Export\Declarations;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Query\Expr\Andx; use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class ActiveOnDateFilter implements FilterInterface class ActiveOnDateFilter implements FilterInterface
{ {
private RollingDateConverterInterface $rollingDateConverter;
public function __construct(RollingDateConverterInterface $rollingDateConverter)
{
$this->rollingDateConverter = $rollingDateConverter;
}
public function addRole(): ?string public function addRole(): ?string
{ {
return null; return null;
@ -46,7 +53,10 @@ class ActiveOnDateFilter implements FilterInterface
} }
$qb->add('where', $where); $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 public function applyOn(): string
@ -57,15 +67,15 @@ class ActiveOnDateFilter implements FilterInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
$builder $builder
->add('on_date', ChillDateType::class, [ ->add('on_date', PickRollingDateType::class, [
'data' => new DateTime(), 'data' => new RollingDate(RollingDate::T_TODAY),
]); ]);
} }
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {
return ['Filtered by actives courses: active on %ondate%', [ 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'),
]]; ]];
} }

View File

@ -12,15 +12,22 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Export\FilterInterface; 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 Chill\PersonBundle\Export\Declarations;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class ActiveOneDayBetweenDatesFilter implements FilterInterface class ActiveOneDayBetweenDatesFilter implements FilterInterface
{ {
private RollingDateConverterInterface $rollingDateConverter;
public function __construct(RollingDateConverterInterface $rollingDateConverter)
{
$this->rollingDateConverter = $rollingDateConverter;
}
public function addRole(): ?string public function addRole(): ?string
{ {
return null; return null;
@ -31,8 +38,14 @@ class ActiveOneDayBetweenDatesFilter implements FilterInterface
$clause = "OVERLAPSI (acp.openingDate, acp.closingDate), (:datefrom, :dateto) = 'TRUE'"; $clause = "OVERLAPSI (acp.openingDate, acp.closingDate), (:datefrom, :dateto) = 'TRUE'";
$qb->andWhere($clause); $qb->andWhere($clause);
$qb->setParameter('datefrom', $data['date_from'], Types::DATE_MUTABLE); $qb->setParameter(
$qb->setParameter('dateto', $data['date_to'], Types::DATE_MUTABLE); 'datefrom',
$this->rollingDateConverter->convert($data['date_from'])
);
$qb->setParameter(
'dateto',
$this->rollingDateConverter->convert($data['date_to'])
);
} }
public function applyOn(): string public function applyOn(): string
@ -43,19 +56,19 @@ class ActiveOneDayBetweenDatesFilter implements FilterInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
$builder $builder
->add('date_from', ChillDateType::class, [ ->add('date_from', PickRollingDateType::class, [
'data' => new DateTime(), 'data' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START),
]) ])
->add('date_to', ChillDateType::class, [ ->add('date_to', PickRollingDateType::class, [
'data' => new DateTime(), 'data' => new RollingDate(RollingDate::T_TODAY),
]); ]);
} }
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {
return ['Filtered by actives courses: at least one day between %datefrom% and %dateto%', [ return ['Filtered by actives courses: at least one day between %datefrom% and %dateto%', [
'%datefrom%' => $data['date_from']->format('d-m-Y'), '%datefrom%' => $this->rollingDateConverter->convert($data['date_from'])->format('d-m-Y'),
'%dateto%' => $data['date_to']->format('d-m-Y'), '%dateto%' => $this->rollingDateConverter->convert($data['date_to'])->format('d-m-Y'),
]]; ]];
} }

View File

@ -14,14 +14,15 @@ namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Entity\Address; use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\GeographicalUnit\SimpleGeographicalUnitDTO; use Chill\MainBundle\Entity\GeographicalUnit\SimpleGeographicalUnitDTO;
use Chill\MainBundle\Export\FilterInterface; 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\GeographicalUnitLayerRepositoryInterface;
use Chill\MainBundle\Repository\GeographicalUnitRepositoryInterface; use Chill\MainBundle\Repository\GeographicalUnitRepositoryInterface;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress; use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use DateTimeImmutable;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -35,16 +36,20 @@ class GeographicalUnitStatFilter implements FilterInterface
private GeographicalUnitRepositoryInterface $geographicalUnitRepository; private GeographicalUnitRepositoryInterface $geographicalUnitRepository;
private RollingDateConverterInterface $rollingDateConverter;
private TranslatableStringHelperInterface $translatableStringHelper; private TranslatableStringHelperInterface $translatableStringHelper;
public function __construct( public function __construct(
GeographicalUnitRepositoryInterface $geographicalUnitRepository, GeographicalUnitRepositoryInterface $geographicalUnitRepository,
GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository, GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository,
TranslatableStringHelperInterface $translatableStringHelper TranslatableStringHelperInterface $translatableStringHelper,
RollingDateConverterInterface $rollingDateConverter
) { ) {
$this->geographicalUnitRepository = $geographicalUnitRepository; $this->geographicalUnitRepository = $geographicalUnitRepository;
$this->geographicalUnitLayerRepository = $geographicalUnitLayerRepository; $this->geographicalUnitLayerRepository = $geographicalUnitLayerRepository;
$this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
$this->rollingDateConverter = $rollingDateConverter;
} }
public function addRole(): ?string public function addRole(): ?string
@ -77,7 +82,10 @@ class GeographicalUnitStatFilter implements FilterInterface
$qb $qb
->andWhere($qb->expr()->exists($subQueryDql)) ->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'])); ->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) public function buildForm(FormBuilderInterface $builder)
{ {
$builder $builder
->add('date_calc', ChillDateType::class, [ ->add('date_calc', PickRollingDateType::class, [
'label' => 'Compute geographical location at date', 'label' => 'Compute geographical location at date',
'required' => true, 'required' => true,
'data' => new DateTimeImmutable('today'), 'data' => new RollingDate(RollingDate::T_TODAY),
'input' => 'datetime_immutable',
]) ])
->add('units', ChoiceType::class, [ ->add('units', ChoiceType::class, [
'label' => 'Geographical unit', 'label' => 'Geographical unit',
@ -113,8 +120,8 @@ class GeographicalUnitStatFilter implements FilterInterface
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {
return ['Filtered by geographic unit: computed at %date%, only in %units%', [ return ['Filtered by geographic unit: computed at %date%, only in %units%', [
'%date%' => $data['date_calc']->format('d-m-Y'), '%date%' => $this->rollingDateConverter->convert($data['date_calc'])->format('d-m-Y'),
'%units%' => implode( '%units' => implode(
', ', ', ',
array_map( array_map(
function (SimpleGeographicalUnitDTO $item) { function (SimpleGeographicalUnitDTO $item) {

View File

@ -12,16 +12,24 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Export\FilterInterface; 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\Entity\AccompanyingPeriod\UserHistory;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use DateTimeImmutable;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class HasNoReferrerFilter implements FilterInterface class HasNoReferrerFilter implements FilterInterface
{ {
private RollingDateConverterInterface $rollingDateConverter;
public function __construct(
RollingDateConverterInterface $rollingDateConverter
) {
$this->rollingDateConverter = $rollingDateConverter;
}
public function addRole(): ?string public function addRole(): ?string
{ {
return null; return null;
@ -41,7 +49,10 @@ class HasNoReferrerFilter implements FilterInterface
AND uh.accompanyingPeriod = acp 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 public function applyOn(): string
@ -52,17 +63,16 @@ class HasNoReferrerFilter implements FilterInterface
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
$builder $builder
->add('calc_date', ChillDateType::class, [ ->add('calc_date', PickRollingDateType::class, [
'label' => 'Has no referrer on this date', 'label' => 'Has no referrer on this date',
'data' => new DateTimeImmutable(), 'data' => new RollingDate(RollingDate::T_TODAY),
'input' => 'datetime_immutable',
]); ]);
} }
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {
return ['Filtered acp which has no referrer on date: %date%', [ 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'),
]]; ]];
} }

View File

@ -12,9 +12,10 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Export\FilterInterface; 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 Chill\PersonBundle\Export\Declarations;
use DateTimeImmutable;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use LogicException; use LogicException;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
@ -22,6 +23,14 @@ use Symfony\Component\Form\FormBuilderInterface;
class HasTemporaryLocationFilter implements FilterInterface class HasTemporaryLocationFilter implements FilterInterface
{ {
private RollingDateConverterInterface $rollingDateConverter;
public function __construct(
RollingDateConverterInterface $rollingDateConverter
) {
$this->rollingDateConverter = $rollingDateConverter;
}
public function addRole(): ?string public function addRole(): ?string
{ {
return null; return null;
@ -33,7 +42,10 @@ class HasTemporaryLocationFilter implements FilterInterface
->join('acp.locationHistories', 'acp_having_temporarily_location') ->join('acp.locationHistories', 'acp_having_temporarily_location')
->andWhere('acp_having_temporarily_location.startDate <= :acp_having_temporarily_location_date ->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)') 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']) { switch ($data['having_temporarily']) {
case true: 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', 'label' => 'export.filter.course.having_temporarily.Calculation date',
'input' => 'datetime_immutable', 'data' => new RollingDate(RollingDate::T_TODAY),
'data' => new DateTimeImmutable(),
]); ]);
} }

View File

@ -12,11 +12,12 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters; namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Export\FilterInterface; 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\Form\Type\PickUserDynamicType;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Templating\Entity\UserRender; use Chill\MainBundle\Templating\Entity\UserRender;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use DateTimeImmutable;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -28,11 +29,16 @@ class ReferrerFilter implements FilterInterface
private const PU = 'acp_referrer_filter_users'; private const PU = 'acp_referrer_filter_users';
private RollingDateConverterInterface $rollingDateConverter;
private UserRender $userRender; private UserRender $userRender;
public function __construct(UserRender $userRender) public function __construct(
{ UserRender $userRender,
RollingDateConverterInterface $rollingDateConverter
) {
$this->userRender = $userRender; $this->userRender = $userRender;
$this->rollingDateConverter = $rollingDateConverter;
} }
public function addRole(): ?string public function addRole(): ?string
@ -57,7 +63,10 @@ class ReferrerFilter implements FilterInterface
$qb->expr()->in(self::A . '.user', ':' . self::PU) $qb->expr()->in(self::A . '.user', ':' . self::PU)
) )
->setParameter(self::PU, $data['accepted_referrers']) ->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 public function applyOn(): string
@ -71,9 +80,8 @@ class ReferrerFilter implements FilterInterface
->add('accepted_referrers', PickUserDynamicType::class, [ ->add('accepted_referrers', PickUserDynamicType::class, [
'multiple' => true, 'multiple' => true,
]) ])
->add('date_calc', ChillDateType::class, [ ->add('date_calc', PickRollingDateType::class, [
'input' => 'datetime_immutable', 'data' => new RollingDate(RollingDate::T_TODAY),
'data' => new DateTimeImmutable('now'),
'label' => 'export.filter.course.by_referrer.Computation date for referrer', 'label' => 'export.filter.course.by_referrer.Computation date for referrer',
'required' => true, 'required' => true,
]); ]);

View File

@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\PickRollingDateType; use Chill\MainBundle\Form\Type\PickRollingDateType;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface; use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
@ -43,8 +44,10 @@ class StepFilter implements FilterInterface
*/ */
private $translator; private $translator;
public function __construct(RollingDateConverterInterface $rollingDateConverter, TranslatorInterface $translator) public function __construct(
{ RollingDateConverterInterface $rollingDateConverter,
TranslatorInterface $translator
) {
$this->rollingDateConverter = $rollingDateConverter; $this->rollingDateConverter = $rollingDateConverter;
$this->translator = $translator; $this->translator = $translator;
} }
@ -94,6 +97,7 @@ class StepFilter implements FilterInterface
]) ])
->add('calc_date', PickRollingDateType::class, [ ->add('calc_date', PickRollingDateType::class, [
'label' => 'export.acp.filter.by_step.date_calc', 'label' => 'export.acp.filter.by_step.date_calc',
'data' => new RollingDate(RollingDate::T_TODAY),
]); ]);
} }

View File

@ -14,11 +14,12 @@ namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\UserJob; use Chill\MainBundle\Entity\UserJob;
use Chill\MainBundle\Export\FilterInterface; 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\Repository\UserJobRepositoryInterface;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use DateTimeImmutable;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -34,6 +35,8 @@ class UserJobFilter implements FilterInterface
private const PJ = 'acp_ujob_filter_job'; private const PJ = 'acp_ujob_filter_job';
private RollingDateConverterInterface $rollingDateConverter;
private Security $security; private Security $security;
private TranslatableStringHelper $translatableStringHelper; private TranslatableStringHelper $translatableStringHelper;
@ -43,11 +46,13 @@ class UserJobFilter implements FilterInterface
public function __construct( public function __construct(
Security $security, Security $security,
TranslatableStringHelper $translatableStringHelper, TranslatableStringHelper $translatableStringHelper,
UserJobRepositoryInterface $userJobRepository UserJobRepositoryInterface $userJobRepository,
RollingDateConverterInterface $rollingDateConverter
) { ) {
$this->security = $security; $this->security = $security;
$this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
$this->userJobRepository = $userJobRepository; $this->userJobRepository = $userJobRepository;
$this->rollingDateConverter = $rollingDateConverter;
} }
public function addRole(): ?string 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) ->join(self::A . '.user', self::AU)
->andWhere( ->andWhere(
$qb->expr()->in(self::AU . '.userJob', ':' . self::PJ) $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()), 'choice_label' => fn (UserJob $job) => $this->translatableStringHelper->localize($job->getLabel()),
'label' => 'Job', 'label' => 'Job',
]) ])
->add('date_calc', ChillDateType::class, [ ->add('date_calc', PickRollingDateType::class, [
'input' => 'datetime_immutable', 'data' => new RollingDate(RollingDate::T_TODAY),
'data' => new DateTimeImmutable('now'),
'label' => 'export.filter.course.by_user_scope.Computation date for referrer', 'label' => 'export.filter.course.by_user_scope.Computation date for referrer',
'required' => true, 'required' => true,
]); ]);

View File

@ -14,11 +14,12 @@ namespace Chill\PersonBundle\Export\Filter\AccompanyingCourseFilters;
use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Export\FilterInterface; 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\Repository\ScopeRepositoryInterface;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use DateTimeImmutable;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -34,6 +35,8 @@ class UserScopeFilter implements FilterInterface
private const PS = 'acp_uscope_filter_scopes'; private const PS = 'acp_uscope_filter_scopes';
private RollingDateConverterInterface $rollingDateConverter;
private ScopeRepositoryInterface $scopeRepository; private ScopeRepositoryInterface $scopeRepository;
private Security $security; private Security $security;
@ -43,11 +46,13 @@ class UserScopeFilter implements FilterInterface
public function __construct( public function __construct(
ScopeRepositoryInterface $scopeRepository, ScopeRepositoryInterface $scopeRepository,
Security $security, Security $security,
TranslatableStringHelper $translatableStringHelper TranslatableStringHelper $translatableStringHelper,
RollingDateConverterInterface $rollingDateConverter
) { ) {
$this->scopeRepository = $scopeRepository; $this->scopeRepository = $scopeRepository;
$this->security = $security; $this->security = $security;
$this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
$this->rollingDateConverter = $rollingDateConverter;
} }
public function addRole(): ?string 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) ->join(self::A . '.user', self::AU)
->andWhere( ->andWhere(
$qb->expr()->in(self::AU . '.mainScope', ':' . self::PS) $qb->expr()->in(self::AU . '.mainScope', ':' . self::PS)
@ -91,9 +99,8 @@ class UserScopeFilter implements FilterInterface
'multiple' => true, 'multiple' => true,
'expanded' => true, 'expanded' => true,
]) ])
->add('date_calc', ChillDateType::class, [ ->add('date_calc', PickRollingDateType::class, [
'input' => 'datetime_immutable', 'data' => new RollingDate(RollingDate::T_TODAY),
'data' => new DateTimeImmutable('now'),
'label' => 'export.filter.course.by_user_scope.Computation date for referrer', 'label' => 'export.filter.course.by_user_scope.Computation date for referrer',
'required' => true, 'required' => true,
]); ]);

View File

@ -12,15 +12,23 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\EvaluationFilters; namespace Chill\PersonBundle\Export\Filter\EvaluationFilters;
use Chill\MainBundle\Export\FilterInterface; 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 Chill\PersonBundle\Export\Declarations;
use DateTimeImmutable; use DateTimeImmutable;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class ByEndDateFilter implements FilterInterface class ByEndDateFilter implements FilterInterface
{ {
private RollingDateConverterInterface $rollingDateConverter;
public function __construct(RollingDateConverterInterface $rollingDateConverter)
{
$this->rollingDateConverter = $rollingDateConverter;
}
public function addRole(): ?string public function addRole(): ?string
{ {
return null; return null;
@ -30,8 +38,14 @@ class ByEndDateFilter implements FilterInterface
{ {
$qb $qb
->andWhere('workeval.endDate BETWEEN :work_eval_by_end_date_start_date and :work_eval_by_end_date_end_date') ->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(
->setParameter('work_eval_by_end_date_end_date', $data['end_date'], Types::DATE_IMMUTABLE); '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 public function applyOn(): string
@ -42,23 +56,22 @@ class ByEndDateFilter implements FilterInterface
public function buildForm(FormBuilderInterface $builder): void public function buildForm(FormBuilderInterface $builder): void
{ {
$builder $builder
->add('start_date', ChillDateType::class, [ ->add('start_date', PickRollingDateType::class, [
'label' => 'start period date', 'label' => 'start period date',
'data' => new DateTimeImmutable('1 year ago'), 'data' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START),
'input' => 'datetime_immutable', 'input' => 'datetime_immutable',
]) ])
->add('end_date', ChillDateType::class, [ ->add('end_date', PickRollingDateType::class, [
'label' => 'end period date', 'label' => 'end period date',
'data' => new DateTimeImmutable(), 'data' => new RollingDate(RollingDate::T_TODAY),
'input' => 'datetime_immutable',
]); ]);
} }
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {
return ['Filtered by end date: between %start_date% and %end_date%', [ return ['Filtered by end date: between %start_date% and %end_date%', [
'%start_date%' => $data['start_date']->format('d-m-Y'), '%start_date%' => $this->rollingDateConverter->convert($data['start_date'])->format('d-m-Y'),
'%end_date%' => $data['end_date']->format('d-m-Y'), '%end_date%' => $this->rollingDateConverter->convert($data['end_date'])->format('d-m-Y'),
]]; ]];
} }

View File

@ -12,15 +12,23 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\EvaluationFilters; namespace Chill\PersonBundle\Export\Filter\EvaluationFilters;
use Chill\MainBundle\Export\FilterInterface; 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 Chill\PersonBundle\Export\Declarations;
use DateTimeImmutable; use DateTimeImmutable;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
class ByStartDateFilter implements FilterInterface class ByStartDateFilter implements FilterInterface
{ {
private RollingDateConverterInterface $rollingDateConverter;
public function __construct(RollingDateConverterInterface $rollingDateConverter)
{
$this->rollingDateConverter = $rollingDateConverter;
}
public function addRole(): ?string public function addRole(): ?string
{ {
return null; return null;
@ -30,8 +38,14 @@ class ByStartDateFilter implements FilterInterface
{ {
$qb $qb
->andWhere('workeval.startDate BETWEEN :work_eval_by_start_date_start_date and :work_eval_by_start_date_end_date') ->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(
->setParameter('work_eval_by_start_date_end_date', $data['end_date'], Types::DATE_IMMUTABLE); '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 public function applyOn(): string
@ -42,23 +56,22 @@ class ByStartDateFilter implements FilterInterface
public function buildForm(FormBuilderInterface $builder): void public function buildForm(FormBuilderInterface $builder): void
{ {
$builder $builder
->add('start_date', ChillDateType::class, [ ->add('start_date', PickRollingDateType::class, [
'label' => 'start period date', 'label' => 'start period date',
'data' => new DateTimeImmutable('1 year ago'), 'data' => new RollingDate(RollingDate::T_YEAR_PREVIOUS_START),
'input' => 'datetime_immutable', 'input' => 'datetime_immutable',
]) ])
->add('end_date', ChillDateType::class, [ ->add('end_date', PickRollingDateType::class, [
'label' => 'end period date', 'label' => 'end period date',
'data' => new DateTimeImmutable(), 'data' => new RollingDate(RollingDate::T_TODAY),
'input' => 'datetime_immutable',
]); ]);
} }
public function describeAction($data, $format = 'string'): array public function describeAction($data, $format = 'string'): array
{ {
return ['Filtered by start date: between %start_date% and %end_date%', [ return ['Filtered by start date: between %start_date% and %end_date%', [
'%start_date%' => $data['start_date']->format('d-m-Y'), '%start_date%' => $this->rollingDateConverter->convert($data['start_date'])->format('d-m-Y'),
'%end_date%' => $data['end_date']->format('d-m-Y'), '%end_date%' => $this->rollingDateConverter->convert($data['end_date'])->format('d-m-Y'),
]]; ]];
} }

View File

@ -12,12 +12,12 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\HouseholdFilters; namespace Chill\PersonBundle\Export\Filter\HouseholdFilters;
use Chill\MainBundle\Export\FilterInterface; 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\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\Household\HouseholdCompositionType; use Chill\PersonBundle\Entity\Household\HouseholdCompositionType;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
@ -26,12 +26,16 @@ use function in_array;
class CompositionFilter implements FilterInterface class CompositionFilter implements FilterInterface
{ {
private RollingDateConverterInterface $rollingDateConverter;
private TranslatableStringHelper $translatableStringHelper; private TranslatableStringHelper $translatableStringHelper;
public function __construct( public function __construct(
TranslatableStringHelper $translatableStringHelper TranslatableStringHelper $translatableStringHelper,
RollingDateConverterInterface $rollingDateConverter
) { ) {
$this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
$this->rollingDateConverter = $rollingDateConverter;
} }
public function addRole(): ?string public function addRole(): ?string
@ -58,7 +62,10 @@ class CompositionFilter implements FilterInterface
$qb->andWhere($whereClause); $qb->andWhere($whereClause);
$qb->setParameter('compositions', $data['accepted_composition']); $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 public function applyOn(): string
@ -79,8 +86,8 @@ class CompositionFilter implements FilterInterface
'multiple' => true, 'multiple' => true,
'expanded' => true, 'expanded' => true,
]) ])
->add('on_date', ChillDateType::class, [ ->add('on_date', PickRollingDateType::class, [
'data' => new DateTime('now'), 'data' => new RollingDate(RollingDate::T_TODAY),
]); ]);
} }
@ -96,7 +103,7 @@ class CompositionFilter implements FilterInterface
return ['Filtered by composition: only %compositions% on %ondate%', [ return ['Filtered by composition: only %compositions% on %ondate%', [
'%compositions%' => implode(', ', $compositions), '%compositions%' => implode(', ', $compositions),
'%ondate%' => $data['on_date']->format('d-m-Y'), '%ondate%' => $this->rollingDateConverter->convert($data['on_date'])->format('d-m-Y'),
]]; ]];
} }

View File

@ -13,10 +13,11 @@ namespace Chill\PersonBundle\Export\Filter\PersonFilters;
use Chill\MainBundle\Export\ExportElementValidatedInterface; use Chill\MainBundle\Export\ExportElementValidatedInterface;
use Chill\MainBundle\Export\FilterInterface; 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 Chill\PersonBundle\Export\Declarations;
use DateInterval; use DateInterval;
use DateTimeImmutable;
use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\Extension\Core\Type\IntegerType; use Symfony\Component\Form\Extension\Core\Type\IntegerType;
@ -25,6 +26,13 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
class AgeFilter implements ExportElementValidatedInterface, FilterInterface class AgeFilter implements ExportElementValidatedInterface, FilterInterface
{ {
private RollingDateConverterInterface $rollingDateConverter;
public function __construct(RollingDateConverterInterface $rollingDateConverter)
{
$this->rollingDateConverter = $rollingDateConverter;
}
public function addRole(): ?string public function addRole(): ?string
{ {
return null; return null;
@ -36,7 +44,7 @@ class AgeFilter implements ExportElementValidatedInterface, FilterInterface
$min = null !== $data['min_age'] ? $data['min_age'] : 0; $min = null !== $data['min_age'] ? $data['min_age'] : 0;
$max = null !== $data['max_age'] ? $data['max_age'] : 150; $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')); $minDate = $calc->sub(new DateInterval('P' . $max . 'Y'));
$maxDate = $calc->sub(new DateInterval('P' . $min . 'Y')); $maxDate = $calc->sub(new DateInterval('P' . $min . 'Y'));
@ -78,10 +86,9 @@ class AgeFilter implements ExportElementValidatedInterface, FilterInterface
'label' => 'Maximum age', 'label' => 'Maximum age',
]); ]);
$builder->add('date_calc', ChillDateType::class, [ $builder->add('date_calc', PickRollingDateType::class, [
'label' => 'Calculate age in relation to this date', 'label' => 'Calculate age in relation to this date',
'data' => new DateTimeImmutable('now'), 'data' => new RollingDate(RollingDate::T_TODAY),
'input' => 'datetime_immutable',
]); ]);
} }

View File

@ -13,20 +13,30 @@ namespace Chill\PersonBundle\Export\Filter\PersonFilters;
use Chill\MainBundle\Export\ExportElementValidatedInterface; use Chill\MainBundle\Export\ExportElementValidatedInterface;
use Chill\MainBundle\Export\FilterInterface; 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 Chill\PersonBundle\Export\Declarations;
use DateTime;
use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Validator\Context\ExecutionContextInterface;
class BirthdateFilter implements ExportElementValidatedInterface, FilterInterface class BirthdateFilter implements ExportElementValidatedInterface, FilterInterface
{ {
private RollingDateConverterInterface $rollingDateConverter;
public function __construct(RollingDateConverterInterface $rollingDateConverter)
{
$this->rollingDateConverter = $rollingDateConverter;
}
public function addRole(): ?string public function addRole(): ?string
{ {
return null; return null;
} }
public function alterQuery(\Doctrine\ORM\QueryBuilder $qb, $data) public function alterQuery(QueryBuilder $qb, $data)
{ {
$where = $qb->getDQLPart('where'); $where = $qb->getDQLPart('where');
$clause = $qb->expr()->between( $clause = $qb->expr()->between(
@ -42,8 +52,14 @@ class BirthdateFilter implements ExportElementValidatedInterface, FilterInterfac
} }
$qb->add('where', $where); $qb->add('where', $where);
$qb->setParameter('date_from', $data['date_from']); $qb->setParameter(
$qb->setParameter('date_to', $data['date_to']); 'date_from',
$this->rollingDateConverter->convert($data['date_from'])
);
$qb->setParameter(
'date_to',
$this->rollingDateConverter->convert($data['date_to'])
);
} }
public function applyOn() public function applyOn()
@ -51,16 +67,16 @@ class BirthdateFilter implements ExportElementValidatedInterface, FilterInterfac
return Declarations::PERSON_TYPE; 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', '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', '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: ' return ['Filtered by person\'s birthdate: '
. 'between %date_from% and %date_to%', [ . 'between %date_from% and %date_to%', [
'%date_from%' => $data['date_from']->format('d-m-Y'), '%date_from%' => $this->rollingDateConverter->convert($data['date_from'])->format('d-m-Y'),
'%date_to%' => $data['date_to']->format('d-m-Y'), '%date_to%' => $this->rollingDateConverter->convert($data['date_to'])->format('d-m-Y'),
], ]; ], ];
} }

View File

@ -12,9 +12,10 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\PersonFilters; namespace Chill\PersonBundle\Export\Filter\PersonFilters;
use Chill\MainBundle\Export\FilterInterface; 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 Chill\PersonBundle\Export\Declarations;
use DateTime;
use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
@ -22,6 +23,14 @@ use Symfony\Component\Form\FormBuilderInterface;
class DeadOrAliveFilter implements FilterInterface class DeadOrAliveFilter implements FilterInterface
{ {
private RollingDateConverterInterface $rollingDateConverter;
public function __construct(
RollingDateConverterInterface $rollingDateConverter
) {
$this->rollingDateConverter = $rollingDateConverter;
}
public function addRole(): ?string public function addRole(): ?string
{ {
return null; return null;
@ -32,7 +41,7 @@ class DeadOrAliveFilter implements FilterInterface
$where = $qb->getDQLPart('where'); $where = $qb->getDQLPart('where');
$personState = $data['person_state']; $personState = $data['person_state'];
$calc = $data['date_calc']; $calc = $this->rollingDateConverter->convert($data['date_calc']);
if ('alive' === $personState) { if ('alive' === $personState) {
$clause = $qb->expr()->orX( $clause = $qb->expr()->orX(
@ -91,9 +100,9 @@ class DeadOrAliveFilter implements FilterInterface
'expanded' => true, 'expanded' => true,
]); ]);
$builder->add('date_calc', ChillDateType::class, [ $builder->add('date_calc', PickRollingDateType::class, [
'label' => 'Filter in relation to this date', '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%: ' return ['Filtered by a state of %deadOrAlive%: '
. 'at this date %date_calc%', [ . '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'], '%deadOrAlive%' => $data['person_state'],
], ]; ], ];
} }

View File

@ -13,9 +13,10 @@ namespace Chill\PersonBundle\Export\Filter\PersonFilters;
use Chill\MainBundle\Export\ExportElementValidatedInterface; use Chill\MainBundle\Export\ExportElementValidatedInterface;
use Chill\MainBundle\Export\FilterInterface; 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 Chill\PersonBundle\Export\Declarations;
use DateTime;
use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -23,6 +24,14 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
class DeathdateFilter implements ExportElementValidatedInterface, FilterInterface class DeathdateFilter implements ExportElementValidatedInterface, FilterInterface
{ {
private RollingDateConverterInterface $rollingDateConverter;
public function __construct(
RollingDateConverterInterface $rollingDateConverter
) {
$this->rollingDateConverter = $rollingDateConverter;
}
public function addRole(): ?string public function addRole(): ?string
{ {
return null; return null;
@ -44,8 +53,14 @@ class DeathdateFilter implements ExportElementValidatedInterface, FilterInterfac
} }
$qb->add('where', $where); $qb->add('where', $where);
$qb->setParameter('date_from', $data['date_from']); $qb->setParameter(
$qb->setParameter('date_to', $data['date_to']); 'date_from',
$this->rollingDateConverter->convert($data['date_from'])
);
$qb->setParameter(
'date_to',
$this->rollingDateConverter->convert($data['date_to'])
);
} }
public function applyOn() public function applyOn()
@ -55,14 +70,14 @@ class DeathdateFilter implements ExportElementValidatedInterface, FilterInterfac
public function buildForm(FormBuilderInterface $builder) public function buildForm(FormBuilderInterface $builder)
{ {
$builder->add('date_from', ChillDateType::class, [ $builder->add('date_from', PickRollingDateType::class, [
'label' => 'Death after this date', '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', '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: ' return ['Filtered by person\'s deathdate: '
. 'between %date_from% and %date_to%', [ . 'between %date_from% and %date_to%', [
'%date_from%' => $data['date_from']->format('d-m-Y'), '%date_from%' => $this->rollingDateConverter->convert($data['date_from'])->format('d-m-Y'),
'%date_to%' => $data['date_to']->format('d-m-Y'), '%date_to%' => $this->rollingDateConverter->convert($data['date_to'])->format('d-m-Y'),
], ]; ], ];
} }

View File

@ -12,13 +12,14 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\PersonFilters; namespace Chill\PersonBundle\Export\Filter\PersonFilters;
use Chill\MainBundle\Entity\GeographicalUnit\SimpleGeographicalUnitDTO; 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\GeographicalUnitLayerRepositoryInterface;
use Chill\MainBundle\Repository\GeographicalUnitRepositoryInterface; use Chill\MainBundle\Repository\GeographicalUnitRepositoryInterface;
use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress; use Chill\PersonBundle\Entity\Household\PersonHouseholdAddress;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use DateTimeImmutable;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
@ -29,16 +30,20 @@ class GeographicalUnitFilter implements \Chill\MainBundle\Export\FilterInterface
private GeographicalUnitRepositoryInterface $geographicalUnitRepository; private GeographicalUnitRepositoryInterface $geographicalUnitRepository;
private RollingDateConverterInterface $rollingDateConverter;
private TranslatableStringHelperInterface $translatableStringHelper; private TranslatableStringHelperInterface $translatableStringHelper;
public function __construct( public function __construct(
GeographicalUnitRepositoryInterface $geographicalUnitRepository, GeographicalUnitRepositoryInterface $geographicalUnitRepository,
GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository, GeographicalUnitLayerRepositoryInterface $geographicalUnitLayerRepository,
TranslatableStringHelperInterface $translatableStringHelper TranslatableStringHelperInterface $translatableStringHelper,
RollingDateConverterInterface $rollingDateConverter
) { ) {
$this->geographicalUnitRepository = $geographicalUnitRepository; $this->geographicalUnitRepository = $geographicalUnitRepository;
$this->geographicalUnitLayerRepository = $geographicalUnitLayerRepository; $this->geographicalUnitLayerRepository = $geographicalUnitLayerRepository;
$this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
$this->rollingDateConverter = $rollingDateConverter;
} }
public function addRole(): ?string public function addRole(): ?string
@ -68,7 +73,10 @@ class GeographicalUnitFilter implements \Chill\MainBundle\Export\FilterInterface
->andWhere( ->andWhere(
$qb->expr()->exists($subQuery) $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'])); ->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) public function buildForm(FormBuilderInterface $builder)
{ {
$builder $builder
->add('date_calc', ChillDateType::class, [ ->add('date_calc', PickRollingDateType::class, [
'label' => 'Compute geographical location at date', 'label' => 'Compute geographical location at date',
'required' => true, 'required' => true,
'data' => new DateTimeImmutable('today'), 'data' => new RollingDate(RollingDate::T_TODAY),
'input' => 'datetime_immutable',
]) ])
->add('units', ChoiceType::class, [ ->add('units', ChoiceType::class, [
'label' => 'Geographical unit', 'label' => 'Geographical unit',
@ -106,7 +113,7 @@ class GeographicalUnitFilter implements \Chill\MainBundle\Export\FilterInterface
return [ return [
'exports.by_person.Filtered by person\'s geographical unit (based on address) computed at datecalc, only units', '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( 'units' => implode(
', ', ', ',
array_map( array_map(

View File

@ -12,12 +12,13 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\PersonFilters; namespace Chill\PersonBundle\Export\Filter\PersonFilters;
use Chill\MainBundle\Export\FilterInterface; 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\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\Person\ResidentialAddress; use Chill\PersonBundle\Entity\Person\ResidentialAddress;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory; use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory;
use DateTime;
use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Symfony\Bridge\Doctrine\Form\Type\EntityType; use Symfony\Bridge\Doctrine\Form\Type\EntityType;
@ -26,11 +27,16 @@ use function in_array;
class ResidentialAddressAtThirdpartyFilter implements FilterInterface class ResidentialAddressAtThirdpartyFilter implements FilterInterface
{ {
private RollingDateConverterInterface $rollingDateConverter;
private TranslatableStringHelper $translatableStringHelper; private TranslatableStringHelper $translatableStringHelper;
public function __construct(TranslatableStringHelper $translatableStringHelper) public function __construct(
{ RollingDateConverterInterface $rollingDateConverter,
TranslatableStringHelper $translatableStringHelper
) {
$this->translatableStringHelper = $translatableStringHelper; $this->translatableStringHelper = $translatableStringHelper;
$this->rollingDateConverter = $rollingDateConverter;
} }
public function addRole(): ?string public function addRole(): ?string
@ -77,7 +83,10 @@ class ResidentialAddressAtThirdpartyFilter implements FilterInterface
} }
$qb->setParameter('type', $data['thirdparty_cat']); $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); $qb->add('where', $where);
} }
@ -98,9 +107,9 @@ class ResidentialAddressAtThirdpartyFilter implements FilterInterface
'expanded' => true, 'expanded' => true,
]); ]);
$builder->add('date_calc', ChillDateType::class, [ $builder->add('date_calc', PickRollingDateType::class, [
'label' => 'Date during which residential address was valid', '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%', [ 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()), '%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'),
]]; ]];
} }

View File

@ -12,10 +12,11 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Export\Filter\PersonFilters; namespace Chill\PersonBundle\Export\Filter\PersonFilters;
use Chill\MainBundle\Export\FilterInterface; 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\Entity\Person\ResidentialAddress;
use Chill\PersonBundle\Export\Declarations; use Chill\PersonBundle\Export\Declarations;
use DateTime;
use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\Query\Expr\Andx; use Doctrine\ORM\Query\Expr\Andx;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
@ -23,6 +24,14 @@ use function in_array;
class ResidentialAddressAtUserFilter implements FilterInterface class ResidentialAddressAtUserFilter implements FilterInterface
{ {
private RollingDateConverterInterface $rollingDateConverter;
public function __construct(
RollingDateConverterInterface $rollingDateConverter
) {
$this->rollingDateConverter = $rollingDateConverter;
}
public function addRole(): ?string public function addRole(): ?string
{ {
return null; return null;
@ -57,7 +66,10 @@ class ResidentialAddressAtUserFilter implements FilterInterface
$where = $qb->expr()->andX($clause); $where = $qb->expr()->andX($clause);
} }
$qb->setParameter('date', $data['date_calc']); $qb->setParameter(
'date',
$this->rollingDateConverter->convert($data['date_calc'])
);
$qb->add('where', $where); $qb->add('where', $where);
} }
@ -68,9 +80,9 @@ class ResidentialAddressAtUserFilter implements FilterInterface
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) 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', 'label' => 'Date during which residential address was valid',
'data' => new DateTime('now'), 'data' => new RollingDate(RollingDate::T_TODAY),
]); ]);
} }

View File

@ -13,6 +13,8 @@ namespace Export\Aggregator\AccompanyingCourseAggregators;
use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Repository\ScopeRepositoryInterface; 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\Templating\TranslatableStringHelperInterface;
use Chill\MainBundle\Test\Export\AbstractAggregatorTest; use Chill\MainBundle\Test\Export\AbstractAggregatorTest;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod;
@ -40,9 +42,13 @@ final class ReferrerScopeAggregatorTest extends AbstractAggregatorTest
(new Scope())->setName(['fr' => 'scope']) (new Scope())->setName(['fr' => 'scope'])
); );
$dateConverter = $this->prophesize(RollingDateConverterInterface::class);
$dateConverter->convert(Argument::type(RollingDate::class))->willReturn(new DateTimeImmutable());
return new ReferrerScopeAggregator( return new ReferrerScopeAggregator(
$scopeRepository->reveal(), $scopeRepository->reveal(),
$translatableStringHelper->reveal() $translatableStringHelper->reveal(),
$dateConverter->reveal()
); );
} }

View File

@ -12,12 +12,21 @@ declare(strict_types=1);
namespace Chill\ReportBundle\Export\Filter; namespace Chill\ReportBundle\Export\Filter;
use Chill\MainBundle\Export\FilterInterface; use Chill\MainBundle\Export\FilterInterface;
use Chill\MainBundle\Form\Type\ChillDateType; use Chill\MainBundle\Form\Type\PickRollingDateType;
use DateTime; use Chill\MainBundle\Service\RollingDate\RollingDate;
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
use Doctrine\ORM\Query\Expr; use Doctrine\ORM\Query\Expr;
class ReportDateFilter implements FilterInterface class ReportDateFilter implements FilterInterface
{ {
private RollingDateConverterInterface $rollingDateConverter;
public function __construct(
RollingDateConverterInterface $rollingDateConverter
) {
$this->rollingDateConverter = $rollingDateConverter;
}
public function addRole(): ?string public function addRole(): ?string
{ {
return null; return null;
@ -39,8 +48,14 @@ class ReportDateFilter implements FilterInterface
} }
$qb->add('where', $where); $qb->add('where', $where);
$qb->setParameter('report_date_filter_date_from', $data['date_from']); $qb->setParameter(
$qb->setParameter('report_date_filter_date_to', $data['date_to']); '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() public function applyOn()
@ -50,14 +65,14 @@ class ReportDateFilter implements FilterInterface
public function buildForm(\Symfony\Component\Form\FormBuilderInterface $builder) 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', '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', '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: ' return ['Filtered by report\'s date: '
. 'between %date_from% and %date_to%', [ . 'between %date_from% and %date_to%', [
'%date_from%' => $data['date_from']->format('d-m-Y'), '%date_from%' => $this->rollingDateConverter->convert($data['date_from'])->format('d-m-Y'),
'%date_to%' => $data['date_to']->format('d-m-Y'), '%date_to%' => $this->rollingDateConverter->convert($data['date_to'])->format('d-m-Y'),
], ]; ], ];
} }