mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
[export][person] Fixed: filter per person's age: use calculatio non year interval
This commit is contained in:
parent
89bdc76565
commit
6cdb3033db
@ -34,17 +34,20 @@ class AgeFilter implements ExportElementValidatedInterface, FilterInterface
|
||||
$where = $qb->getDQLPart('where');
|
||||
|
||||
$min = null !== $data['min_age'] ? $data['min_age'] : 0;
|
||||
$max = null !== $data['max_age'] ? $data['max_age'] : 200;
|
||||
$max = null !== $data['max_age'] ? $data['max_age'] : 3000;
|
||||
$calc = $data['date_calc'];
|
||||
|
||||
$minDate = $calc->sub(new \DateInterval('P' . $max . 'Y'));
|
||||
$maxDate = $calc->sub(new \DateInterval('P' . $min . 'Y'));
|
||||
|
||||
$clause = $qb->expr()->andX(
|
||||
$qb->expr()->gte(
|
||||
'DATE_DIFF(:calc_date, person.birthdate)/365',
|
||||
':min_age'
|
||||
'person.birthdate',
|
||||
':min_date'
|
||||
),
|
||||
$qb->expr()->lte(
|
||||
'DATE_DIFF(:calc_date, person.birthdate)/365',
|
||||
':max_age'
|
||||
'person.birthdate',
|
||||
':max_date'
|
||||
)
|
||||
);
|
||||
|
||||
@ -55,9 +58,8 @@ class AgeFilter implements ExportElementValidatedInterface, FilterInterface
|
||||
}
|
||||
|
||||
$qb->add('where', $where);
|
||||
$qb->setParameter('min_age', $min);
|
||||
$qb->setParameter('max_age', $max);
|
||||
$qb->setParameter('calc_date', $calc);
|
||||
$qb->setParameter('min_date', $minDate);
|
||||
$qb->setParameter('max_date', $maxDate);
|
||||
}
|
||||
|
||||
public function applyOn()
|
||||
@ -77,7 +79,8 @@ class AgeFilter implements ExportElementValidatedInterface, FilterInterface
|
||||
|
||||
$builder->add('date_calc', ChillDateType::class, [
|
||||
'label' => 'Calculate age in relation to this date',
|
||||
'data' => new DateTime('now'),
|
||||
'data' => new \DateTimeImmutable('now'),
|
||||
'input' => 'datetime_immutable'
|
||||
]);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user