mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +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');
|
$where = $qb->getDQLPart('where');
|
||||||
|
|
||||||
$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'] : 200;
|
$max = null !== $data['max_age'] ? $data['max_age'] : 3000;
|
||||||
$calc = $data['date_calc'];
|
$calc = $data['date_calc'];
|
||||||
|
|
||||||
|
$minDate = $calc->sub(new \DateInterval('P' . $max . 'Y'));
|
||||||
|
$maxDate = $calc->sub(new \DateInterval('P' . $min . 'Y'));
|
||||||
|
|
||||||
$clause = $qb->expr()->andX(
|
$clause = $qb->expr()->andX(
|
||||||
$qb->expr()->gte(
|
$qb->expr()->gte(
|
||||||
'DATE_DIFF(:calc_date, person.birthdate)/365',
|
'person.birthdate',
|
||||||
':min_age'
|
':min_date'
|
||||||
),
|
),
|
||||||
$qb->expr()->lte(
|
$qb->expr()->lte(
|
||||||
'DATE_DIFF(:calc_date, person.birthdate)/365',
|
'person.birthdate',
|
||||||
':max_age'
|
':max_date'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -55,9 +58,8 @@ class AgeFilter implements ExportElementValidatedInterface, FilterInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$qb->add('where', $where);
|
$qb->add('where', $where);
|
||||||
$qb->setParameter('min_age', $min);
|
$qb->setParameter('min_date', $minDate);
|
||||||
$qb->setParameter('max_age', $max);
|
$qb->setParameter('max_date', $maxDate);
|
||||||
$qb->setParameter('calc_date', $calc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyOn()
|
public function applyOn()
|
||||||
@ -77,7 +79,8 @@ class AgeFilter implements ExportElementValidatedInterface, FilterInterface
|
|||||||
|
|
||||||
$builder->add('date_calc', ChillDateType::class, [
|
$builder->add('date_calc', ChillDateType::class, [
|
||||||
'label' => 'Calculate age in relation to this date',
|
'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