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(); } }
public function getSelectedSlots($seats, $zone_id) { $seats = json_decode($seats); foreach ($seats as $key => $seat) { $seats[$key] = explode("_", $seat); $seats[$key] = Slot::where('column', $seats[$key][1])->where('row', $seats[$key][0])->where('zone_id', $zone_id)->first()->id; } return $seats; }
public function getZoneSeatArray(Request $request) { $zona = Zone::find($request['zone_id']); $local = $zona->event->place; $arreglo = array(); $slots = $zona->slots; /* for($j=$zona->start_row; $j<$zona->start_row +$zona->rows; $j++){ $texto = ''; for($i=$zona->start_column; $i<$zona->start_column +$zona->columns; $i++){ $res = $slots->where('column', $i)->where('row', $j); if($res->isEmpty()) $texto = $texto.'_'; else $texto = $texto.'a'; } array_push($arreglo, $texto); }*/ for ($j = 1; $j <= $local->rows; $j++) { $texto = ''; for ($i = 1; $i <= $local->columns; $i++) { $res = Slot::where('column', $i)->where('row', $j)->where('zone_id', $request['zone_id'])->get(); if ($res->isEmpty()) { $texto = $texto . '_'; } else { $texto = $texto . 'a'; } } array_push($arreglo, $texto); } return $arreglo; }