/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Update $request, $id) { $day = Day::find($id); $day->recipes()->detach(); foreach ($request->only('menu') as $id) { $day->recipes()->attach($id); } return redirect('/'); }
public function postAutoAssign(Request $request) { // Weekend booths only = 1 // if this is a weekend booth, can assign to everyone // if this is a weekday booth, can only assign to troops with 0 $isWeekend = Day::find($request->date)->weekend; $brownies = User::getTroops('Brownie', $isWeekend)->toArray(); $juniors = User::getTroops('Junior', $isWeekend)->toArray(); $cadettes = User::getTroops('Cadette', $isWeekend)->toArray(); $seniors = User::getTroops('Senior', $isWeekend)->toArray(); $ambassadors = User::getTroops('Ambassador', $isWeekend)->toArray(); $all = array_merge($brownies, $juniors, $cadettes, $seniors, $ambassadors); $nonCsa = array_merge($brownies, $juniors); $csa = array_merge($cadettes, $seniors, $ambassadors); if ($isWeekend) { $booths = Booth::getBooths($request->date, '', $isWeekend); if ($booths->count()) { shuffle($all); foreach ($booths as $key => $booth) { $booth = Booth::find($booth['id']); $id = array_rand($all); $troop = $all[$id]; $booth->user_id = $troop['id']; $booth->save(); } } } else { $earlyBooths = Booth::getBooths($request->date, true, $isWeekend); $lateBooths = Booth::getBooths($request->date, false, $isWeekend); if ($earlyBooths->count()) { shuffle($nonCsa); foreach ($earlyBooths as $key => $booth) { $booth = Booth::find($booth['id']); $id = array_rand($nonCsa); $troop = $nonCsa[$id]; $booth->user_id = $troop['id']; $booth->save(); } } if ($lateBooths->count()) { shuffle($csa); foreach ($lateBooths as $key => $booth) { $booth = Booth::find($booth['id']); $id = array_rand($csa); $troop = $csa[$id]; $booth->user_id = $troop['id']; $booth->save(); } } } return redirect('/admin/booths'); }
public static function checkInstructor($instructor, $time, $day) { $instructor_sched = Day_period::getInstructorsSched($instructor); $subject_time = explode(' / ', $time); $subject_day = explode(' / ', $day); foreach ($instructor_sched as $sched) { if (!in_array('TBA', $subject_day)) { $inst_day = Day::find($sched->day); if (!in_array($inst_day, $subject_day)) { $from = Time::find($sched->from_time); $to = Time::find($sched->to_time); foreach ($subject_time as $key) { $keys = explode('-', $key); $isConflict = intersectCheck($from->time, $keys[0], $to->time, $keys[1]); if ($isConflict) { return true; } } } } } return false; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $days = Day::find($id); $days->delete(); Session::flash('message', 'You have successfully deleted day'); return Redirect::to('dashboard/admin/days'); }
/** * @param Requests\TimeslotRequest $request * @return \stdClass */ public function getFormInput(Requests\TimeslotRequest $request) { $input = new \stdClass(); $input->day = Day::find($request->get('day_id')); $input->begin = Carbon::createFromFormat('d-m-Y H:i:s', $request->get('begin')); $input->end = Carbon::createFromFormat('d-m-Y H:i:s', $request->get('end')); $roomIds = array_flatten($request->get('rooms')); $roomIds = array_map('intval', $roomIds); $input->rooms = Room::whereIn('id', $roomIds)->get(); return $input; }