mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
[export] use a rolling date on age aggregator (Person)
This query allow to detects the saved export which won't work any more: ```sql select s.id, user_id, description, title, u.label from chill_main_saved_export s join users u on u.id = s.user_id WHERE options->'export'->'export'->'aggregators'->'person_age_aggregator'->'enabled' is not null; ```
This commit is contained in:
parent
c019fffbe7
commit
b7df62d4f5
5
.changes/unreleased/Fixed-20230629-231503.yaml
Normal file
5
.changes/unreleased/Fixed-20230629-231503.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
kind: Fixed
|
||||
body: '[export] set rolling date on person age aggregator'
|
||||
time: 2023-06-29T23:15:03.20841309+02:00
|
||||
custom:
|
||||
Issue: ""
|
@ -13,20 +13,18 @@ namespace Chill\PersonBundle\Export\Aggregator\PersonAggregators;
|
||||
|
||||
use Chill\MainBundle\Export\AggregatorInterface;
|
||||
use Chill\MainBundle\Export\ExportElementValidatedInterface;
|
||||
use DateTime;
|
||||
use Chill\MainBundle\Form\Type\PickRollingDateType;
|
||||
use Chill\MainBundle\Service\RollingDate\RollingDate;
|
||||
use Chill\MainBundle\Service\RollingDate\RollingDateConverterInterface;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Symfony\Component\Form\Extension\Core\Type\DateType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
final class AgeAggregator implements AggregatorInterface, ExportElementValidatedInterface
|
||||
final readonly class AgeAggregator implements AggregatorInterface, ExportElementValidatedInterface
|
||||
{
|
||||
private TranslatorInterface $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
public function __construct(
|
||||
private RollingDateConverterInterface $rollingDateConverter,
|
||||
) {
|
||||
}
|
||||
|
||||
public function addRole(): ?string
|
||||
@ -37,7 +35,7 @@ final class AgeAggregator implements AggregatorInterface, ExportElementValidated
|
||||
public function alterQuery(QueryBuilder $qb, $data)
|
||||
{
|
||||
$qb->addSelect('DATE_DIFF(:date_age_calculation, person.birthdate)/365 as person_age');
|
||||
$qb->setParameter('date_age_calculation', $data['date_age_calculation']);
|
||||
$qb->setParameter('date_age_calculation', $this->rollingDateConverter->convert($data['date_age_calculation']));
|
||||
$qb->addGroupBy('person_age');
|
||||
}
|
||||
|
||||
@ -48,16 +46,13 @@ final class AgeAggregator implements AggregatorInterface, ExportElementValidated
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder->add('date_age_calculation', DateType::class, [
|
||||
$builder->add('date_age_calculation', PickRollingDateType::class, [
|
||||
'label' => 'Calculate age in relation to this date',
|
||||
'attr' => ['class' => 'datepicker'],
|
||||
'widget' => 'single_text',
|
||||
'format' => 'dd-MM-yyyy',
|
||||
]);
|
||||
}
|
||||
public function getFormDefaultData(): array
|
||||
{
|
||||
return ['date_age_calculation' => new DateTime()];
|
||||
return ['date_age_calculation' => new RollingDate(RollingDate::T_TODAY)];
|
||||
}
|
||||
|
||||
public function getLabels($key, array $values, $data)
|
||||
@ -67,11 +62,7 @@ final class AgeAggregator implements AggregatorInterface, ExportElementValidated
|
||||
return 'Age';
|
||||
}
|
||||
|
||||
if (null === $value) {
|
||||
return $this->translator->trans('without data');
|
||||
}
|
||||
|
||||
return $value;
|
||||
return $value ?? '';
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user