Esempio n. 1
0
 public static function generate($shift)
 {
     // Delete all existing slots for this shift
     Slot::where('shift_id', $shift->id)->delete();
     // Loop over shift days
     $date = new Carbon($shift->start_date);
     $end_date = new Carbon($shift->end_date);
     while ($date->lte($end_date)) {
         // Convert shift times to seconds
         $start = Slot::timeToSeconds($shift->start_time);
         $end = Slot::timeToSeconds($shift->end_time);
         $duration = Slot::timeToSeconds($shift->duration);
         // Now loop over the times based on the slot duration
         for ($time = $start; $time + $duration <= $end; $time += $duration) {
             $slot = ['shift_id' => $shift->id, 'start_date' => $date->format('Y-m-d'), 'start_time' => Slot::secondsToTime($time), 'end_time' => Slot::secondsToTime($time + $duration)];
             Slot::create($slot);
         }
         $date->addDay();
     }
 }