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 showAgenda() { $model = new Slot(); $exist = Agenda::find()->where(['agendaID' => $this->agendaID])->one(); $permAgendaID = Agenda::find()->where(['owner' => $exist['owner'], 'type' => 'perm'])->one(); $tempSlotIDs = array(); if ($exist['type'] == 'temp') { $tempSlotIDs = $model->getIDs($this->agendaID); } $permSlotIDs = $model->getIDs($permAgendaID['agendaID']); $permindex = 0; $tempindex = 0; $agendforShow = array(); $index = 0; while ($permindex < sizeof($permSlotIDs) && $tempindex < sizeof($tempSlotIDs)) { if ($tempSlotIDs[$tempindex]['slotnum'] == $permSlotIDs[$permindex]['slotnum']) { $agendforShow[$index]['slotID'] = $tempSlotIDs[$tempindex]['slotID']; $agendforShow[$index]['maxBookers'] = $tempSlotIDs[$tempindex]['numberOfBookers']; $agendforShow[$index]['content'] = $tempSlotIDs[$tempindex]['content']; $count = Book::find()->where(['slotID' => $agendforShow[$index]['slotID'], 'date' => $exist['lastUpdate']])->count(); $agendforShow[$index]['bookCount'] = $count; $tempindex++; $index++; } else { $agendforShow[$index]['slotID'] = $permSlotIDs[$permindex]['slotID']; $agendforShow[$index]['maxBookers'] = $permSlotIDs[$permindex]['numberOfBookers']; $agendforShow[$index]['content'] = $permSlotIDs[$permindex]['content']; $count = Book::find()->where(['slotID' => $agendforShow[$index]['slotID'], 'date' => $exist['lastUpdate']])->count(); $agendforShow[$index]['bookCount'] = $count; $index++; } $permindex++; } while ($tempindex < sizeof($tempSlotIDs)) { $agendforShow[$index]['slotID'] = $tempSlotIDs[$tempindex]['slotID']; $agendforShow[$index]['maxBookers'] = $tempSlotIDs[$tempindex]['numberOfBookers']; $agendforShow[$index]['content'] = $tempSlotIDs[$tempindex]['content']; $count = Book::find()->where(['slotID' => $agendforShow[$index]['slotID'], 'date' => $exist['lastUpdate']])->count(); $agendforShow[$index]['bookCount'] = $count; $tempindex++; $index++; } while ($permindex < sizeof($permSlotIDs)) { $agendforShow[$index]['slotID'] = $permSlotIDs[$permindex]['slotID']; $agendforShow[$index]['maxBookers'] = $permSlotIDs[$permindex]['numberOfBookers']; $agendforShow[$index]['content'] = $permSlotIDs[$permindex]['content']; $count = Book::find()->where(['slotID' => $agendforShow[$index]['slotID'], 'date' => $exist['lastUpdate']])->count(); $agendforShow[$index]['bookCount'] = $count; $permindex++; $index++; } return $agendforShow; }
public function getTakenSlots(request $request) { $event = Event::find($request['event_id']); if ($event->place->rows != null) { $slots = []; $taken = []; $reserved = []; $slot_presentation = DB::table('slot_presentation')->where('presentation_id', $request['function_id'])->where('status', config('constants.seat_taken'))->get(); foreach ($slot_presentation as $s_p) { $slot = Slot::find($s_p->slot_id); if ($slot->zone->id == $request['zone_id']) { array_push($taken, $slot->row . "_" . $slot->column); } } $slot_presentation = DB::table('slot_presentation')->where('presentation_id', $request['function_id'])->where('status', config('constants.seat_reserved'))->get(); foreach ($slot_presentation as $s_p) { $slot = Slot::find($s_p->slot_id); if ($slot->zone->id == $request['zone_id']) { array_push($reserved, $slot->row . "_" . $slot->column); } } array_push($slots, $taken); array_push($slots, $reserved); } else { $slots = -1; } return $slots; }
public function cloneEvent(Request $request, Event $event) { $this->authorize('create-event'); $this->validate($request, ['start_date' => 'required|date_format:Y-m-d']); // Set up event information $startDate = new Carbon($event->start_date); $endDate = new Carbon($event->end_date); $newStartDate = new Carbon($request->input('start_date')); $departments = $event->departments; // Find the difference of the start dates $difference = $startDate->diffInSeconds($newStartDate); // Create new event from old event data $newEvent = Event::create(['name' => $event->name, 'description' => $event->description, 'start_date' => $startDate->addSeconds($difference)->format('Y-m-d'), 'end_date' => $endDate->addSeconds($difference)->format('Y-m-d')]); // Add the image manually because it's not automatically fillable if ($event->image) { $newEvent->image = $event->image; $newEvent->save(); } // Loop through event departments foreach ($departments as $department) { // Create new department $newDepartment = new Department(); $newDepartment->event_id = $newEvent->id; $newDepartment->save(); // Because the event_id isn't fillable, we have to define it first and then update $newDepartment->update(['name' => $department->name, 'description' => $department->description, 'roles' => $department->roles]); // Loop through shifts $shifts = $department->shifts; foreach ($shifts as $shift) { // Adjust shift dates $shift->start_date = new Carbon($shift->start_date); $shift->end_date = new Carbon($shift->end_date); $shift->start_date = $shift->start_date->addSeconds($difference)->format('Y-m-d'); $shift->end_date = $shift->end_date->addSeconds($difference)->format('Y-m-d'); // Update the department ID $shift->department_id = $newDepartment->id; $newShift = Shift::create(['department_id' => $newDepartment->id, 'name' => $shift->name, 'start_date' => $shift->start_date, 'end_date' => $shift->end_date, 'start_time' => $shift->start_time, 'end_time' => $shift->end_time, 'duration' => $shift->duration, 'roles' => $shift->roles]); Slot::generate($newShift); } } $request->session()->flash('success', 'Event has been cloned.'); return redirect('/event/' . $newEvent->id); }
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; }
/** * @return \yii\db\ActiveQuery */ public function getSlot() { return $this->hasOne(Slot::className(), ['slotID' => 'slotID']); }
public function updateSlot($content, $slotbuffer, $slotID) { $updated = Slot::updateAll(array('content' => $content, 'numberOfBookers' => $slotbuffer), ['slotID' => $slotID]); return $updated; }
public function edit(ShiftRequest $request, Shift $shift) { $this->authorize('edit-shift'); $input = $request->all(); $department = Department::find($input['department_id']); // Convert roles into JSON $input['roles'] = json_encode($input['roles']); // Check if the current roles match the department roles if ($input['roles'] == $department->roles) { // Unset the roles, use department as default instead unset($input['roles']); } // Make sure dates and times are set properly and formatted $input = Shift::setDates($department, $input); $input = Shift::setTimes($input); $shift->formatTimes(); // Check if the start time, end time, or duration are changing $regenerateSlots = false; if ($shift->start_date != $input['start_date'] || $shift->end_date != $input['end_date'] || $shift->start_time != $input['start_time'] || $shift->end_time != $input['end_time'] || $shift->duration != $input['duration']) { $regenerateSlots = true; } $shift->update($input); // Regenerate slots after the updated shift information is saved if ($regenerateSlots) { Slot::generate($shift); } event(new EventChanged($shift->event, ['type' => 'shift', 'status' => 'edited'])); $request->session()->flash('success', 'Shift has been updated.'); return redirect('/event/' . $shift->event->id); }