Release 2.54 (#5896)
This commit is contained in:
@@ -29,20 +29,30 @@ final class ContractExtensions extends AbstractExtension
|
||||
return [
|
||||
/* @var array{user: User, date: \DateTimeInterface} $values */
|
||||
new TwigTest('work_day', function (array $values): bool {
|
||||
$user = $values['user'];
|
||||
if ($user->getId() === null) {
|
||||
return false;
|
||||
// TODO remove me in 3.0, deprecate with 2.55
|
||||
if (!\array_key_exists('user', $values) || !\array_key_exists('date', $values)) {
|
||||
throw new \Exception('Missing variable "user" or "date" to check for "is work_day');
|
||||
}
|
||||
|
||||
$id = 'user_' . $user->getId();
|
||||
if (!\array_key_exists($id, $this->calculators)) {
|
||||
$this->calculators[$id] = $this->workingTimeService->getContractMode($user)->getCalculator($user);
|
||||
}
|
||||
|
||||
$date = $values['date'];
|
||||
|
||||
return $this->calculators[$id]->isWorkDay($date);
|
||||
return $this->isWorkingDay($values['date'], $values['user']);
|
||||
}),
|
||||
new TwigTest('working_day', function (\DateTimeInterface $date, User $user): bool {
|
||||
return $this->isWorkingDay($date, $user);
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
private function isWorkingDay(\DateTimeInterface $date, User $user): bool
|
||||
{
|
||||
if ($user->getId() === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$id = 'user_' . $user->getId();
|
||||
if (!\array_key_exists($id, $this->calculators)) {
|
||||
$this->calculators[$id] = $this->workingTimeService->getContractMode($user)->getCalculator($user);
|
||||
}
|
||||
|
||||
return $this->calculators[$id]->isWorkDay($date);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user