From 22db06ec64d755a3cde61561a695d451ef7037a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Wed, 18 Oct 2023 17:51:44 +0200 Subject: [PATCH] Feat: Implement overridable effective pickup date --- src/Entity/Assignment.php | 29 ++++++++++++++++++---- src/Form/AssignmentType.php | 2 +- templates/admin/assignment/index.html.twig | 2 +- templates/teamer/index.html.twig | 2 +- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/Entity/Assignment.php b/src/Entity/Assignment.php index ff2b732..982901b 100644 --- a/src/Entity/Assignment.php +++ b/src/Entity/Assignment.php @@ -172,13 +172,32 @@ class Assignment implements BlameableEntityInterface, TimestampableEntityInterfa return $this; } - public function getTotalPeriod(): CarbonPeriod + public function getTotalPeriod(): ?CarbonPeriod { - $destination = $this->getDestination(); - $dateFrom = $this->getDateFrom() ?? $destination->getDateFrom(); - $dateTo = $this->getDateTo() ?? $destination->getDateTo(); + if (null !== $destination = $this->getDestination()) { + $dateFrom = $this->getDateFrom() ?? $destination->getDateFrom(); + $dateTo = $this->getDateTo() ?? $destination->getDateTo(); - return new CarbonPeriod($dateFrom, $dateTo); + return new CarbonPeriod($dateFrom, $dateTo); + } + + return null; + } + + public function getEffectivePickupDate(): ?\DateTimeImmutable + { + if (null !== $this->pickupDate) { + return $this->pickupDate; + } + + if (0 !== (int) $this->pickup && null !== $destination = $this->getDestination()) { + return $destination + ->getDateFrom() + ->modify('-1 day') + ; + } + + return null; } public function getPickupDate(): ?\DateTimeImmutable diff --git a/src/Form/AssignmentType.php b/src/Form/AssignmentType.php index 4f75af4..ef1c66d 100644 --- a/src/Form/AssignmentType.php +++ b/src/Form/AssignmentType.php @@ -53,7 +53,7 @@ class AssignmentType extends AbstractType 'required' => false, ]) ->add('pickupDate', DatepickerType::class, [ - 'label' => 'Busabfahrt', + 'label' => 'abweichende Busabfahrt', 'required' => false, ]) ->add('pickup', BpnPickupType::class, [ diff --git a/templates/admin/assignment/index.html.twig b/templates/admin/assignment/index.html.twig index 540d78d..3c729ad 100644 --- a/templates/admin/assignment/index.html.twig +++ b/templates/admin/assignment/index.html.twig @@ -54,7 +54,7 @@ {{ assignment.pickup ? assignment.pickup|bpn_pickup_label|default('-') : '-' }}
- {{ assignment.pickupDate ? assignment.pickupDate|date('d.m.Y') : '' }} + {{ assignment.effectivePickupDate ? assignment.effectivePickupDate|date('d.m.Y') : '' }} {{ assignment.applications|length }}/{{ assignment.availableDispositions - assignment.dispositions|length }} diff --git a/templates/teamer/index.html.twig b/templates/teamer/index.html.twig index a4810dc..9a95eba 100644 --- a/templates/teamer/index.html.twig +++ b/templates/teamer/index.html.twig @@ -62,7 +62,7 @@ {{ assignment.pickup ? assignment.pickup|bpn_pickup_label|default('-') : '-' }}
- {{ assignment.pickupDate ? assignment.pickupDate|date('d.m.Y') : '' }} + {{ assignment.effectivePickupDate ? assignment.effectivePickupDate|date('d.m.Y') : '' }}