Browse Source

correctif de FindSlot pour prise en compte de chevauchements de dates sur des périodes

garthh 3 weeks ago
parent
commit
8848c74da1

+ 7 - 5
src/Service/SlotFinder.php

@@ -3,6 +3,8 @@
 namespace App\Service;
 
 use App\Entity\Slot;
+use App\Entity\Space;
+use App\Entity\Period;
 
 class SlotFinder
 {
@@ -12,19 +14,19 @@ class SlotFinder
     public function __construct(iterable $slots)
     {
         foreach ($slots as $slot) {
-            $this->index[$this->makeKey($slot->getStartOn(), $slot->getSpace()->getId())] = $slot;
+            $this->index[$this->makeKey($slot->getStartOn(), $slot->getSpace()->getId(), $slot->getPeriod()->getId())] = $slot;
         }
     }
 
-    public function find(\DateTimeInterface $dateRef, $space): ?Slot
+    public function find(\DateTimeInterface $dateRef, Space $space, Period $period): ?Slot
     {
-        $key = $this->makeKey($dateRef, $space->getId());
+        $key = $this->makeKey($dateRef, $space->getId(), $period->getId());
         $found = $this->index[$key] ?? null;
         return $found;
     }
 
-    private function makeKey(\DateTimeInterface $startOn, $spaceId): string
+    private function makeKey(\DateTimeInterface $startOn, $spaceId, $periodId): string
     {
-        return $startOn->format('Y-m-d H:i:s') . '|' . $spaceId;
+        return $startOn->format('Y-m-d H:i:s') . '|' . $spaceId . '|' .$periodId;
     }
 }

+ 2 - 2
src/Twig/Components/Planning.php

@@ -52,9 +52,9 @@ class Planning
         return $dates;
     }
 
-    public function getThisSlotInfo(\DateTimeInterface $dateRef, Space $space): ?Slot
+    public function getThisSlotInfo(\DateTimeInterface $dateRef, Space $space, Period $period): ?Slot
     {
-        $found = $this->finder->find($dateRef, $space);
+        $found = $this->finder->find($dateRef, $space, $period);
         return $found;
     }
 

+ 1 - 1
templates/components/Planning.html.twig

@@ -32,7 +32,7 @@
                     {% for space in event.getSpaces() %}
                         {# extraction du slot de cet espace, ce moment et cette période #}
                         {# set thisSlot = this.getThisSlot(dateRef, space, period) #}
-                        {% set thisSlot = this.getThisSlotInfo(dateRef, space) %}
+                        {% set thisSlot = this.getThisSlotInfo(dateRef, space, period) %}
 
                         {# si le slot est Indisponible #}
                         {% if thisSlot.unavailable %}