diff --git a/src/Bundle/ChillMainBundle/Entity/User.php b/src/Bundle/ChillMainBundle/Entity/User.php index 61263ef85..4ff7aca14 100644 --- a/src/Bundle/ChillMainBundle/Entity/User.php +++ b/src/Bundle/ChillMainBundle/Entity/User.php @@ -45,6 +45,8 @@ class User implements UserInterface, \Stringable, PasswordAuthenticatedUserInter #[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE, nullable: true)] private ?\DateTimeImmutable $absenceStart = null; + #[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE, nullable: true)] + private ?\DateTimeImmutable $absenceEnd = null; /** * Array where SAML attributes's data are stored. */ @@ -157,6 +159,11 @@ class User implements UserInterface, \Stringable, PasswordAuthenticatedUserInter return $this->absenceStart; } + public function getAbsenceEnd(): ?\DateTimeImmutable + { + return $this->absenceEnd; + } + /** * Get attributes. * @@ -336,7 +343,13 @@ class User implements UserInterface, \Stringable, PasswordAuthenticatedUserInter public function isAbsent(): bool { - return null !== $this->getAbsenceStart() && $this->getAbsenceStart() <= new \DateTimeImmutable('now'); + $now = new \DateTimeImmutable('now'); + $absenceStart = $this->getAbsenceStart(); + $absenceEnd = $this->getAbsenceEnd(); + + return null !== $absenceStart + && $absenceStart <= $now + && (null === $absenceEnd || $now <= $absenceEnd); } /** @@ -410,6 +423,11 @@ class User implements UserInterface, \Stringable, PasswordAuthenticatedUserInter $this->absenceStart = $absenceStart; } + public function setAbsenceEnd(?\DateTimeImmutable $absenceEnd): void + { + $this->absenceEnd = $absenceEnd; + } + public function setAttributeByDomain(string $domain, string $key, $value): self { $this->attributes[$domain][$key] = $value; diff --git a/src/Bundle/ChillMainBundle/Form/AbsenceType.php b/src/Bundle/ChillMainBundle/Form/AbsenceType.php index d0aed640c..a10e3c0a2 100644 --- a/src/Bundle/ChillMainBundle/Form/AbsenceType.php +++ b/src/Bundle/ChillMainBundle/Form/AbsenceType.php @@ -12,6 +12,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Form; use Chill\MainBundle\Entity\User; +use Chill\MainBundle\Form\Type\ChillDateTimeType; use Chill\MainBundle\Form\Type\ChillDateType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; @@ -22,10 +23,15 @@ class AbsenceType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('absenceStart', ChillDateType::class, [ - 'required' => true, + ->add('absenceStart', ChillDateTimeType::class, [ + 'required' => false, 'input' => 'datetime_immutable', 'label' => 'absence.Absence start', + ]) + ->add('absenceEnd', ChillDateTimeType::class, [ + 'required' => false, + 'input' => 'datetime_immutable', + 'label' => 'absence.Absence end', ]); } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Menu/absence.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Menu/absence.html.twig index 3258b5ac1..687d6f307 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Menu/absence.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Menu/absence.html.twig @@ -8,36 +8,31 @@
{{ 'absence.You are listed as absent, as of'|trans }} {{ user.absenceStart|format_date('long') }}
- -{{ 'absence.No absence listed'|trans }}
-