/**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(StoreTimeslotRequest $request)
 {
     foreach ($request->time as $time) {
         $timeslot = new Timeslot();
         $timeslot->location_id = $request->location_id;
         $timeslot->day = $request->day;
         $timeslot->time = $time;
         $timeslot->save();
     }
     return redirect()->back()->with('message', 'Timeslot added.');
 }
示例#2
0
 public function addRoom($room)
 {
     $conference = Conference::orderBy('id', 'desc')->first()->id;
     //Getting all unique times existing in this conference
     $times = Timeslot::where('conference_id', $conference)->select('time')->distinct()->get();
     $days = Timeslot::where('conference_id', $conference)->select('day')->distinct()->get();
     foreach ($days as $day) {
         foreach ($times as $time) {
             $timeslot = new Timeslot();
             $timeslot->conference_id = $conference;
             $timeslot->day = $day->day;
             $timeslot->time = $time->time;
             $timeslot->room_code = $room;
             $timeslot->save();
         }
     }
     return redirect()->route('room.index');
 }
示例#3
0
 public function store(Request $request)
 {
     if (Room::count() == 0) {
         flash()->error("You must add at least one room before creating\n                      a conference");
         return back()->withInput();
     }
     $this->validate($request, ['name' => 'required|min:5|max:255']);
     $first = $request['start_time'];
     $last = $request['end_time'];
     if (empty($first[0]) or empty($last[0])) {
         flash()->error("You must add a start time and an end time");
         return back()->withInput();
     }
     $conference = new Conference();
     $conference->name = $request['name'];
     $conference->save();
     $rooms = Room::where('available', true)->get();
     $numDays = sizeOf($first);
     //start day loop from here
     if ($numDays == 1) {
         $times = [];
         $tStart = strtotime($first[0]);
         $tEnd = strtotime($last[0]);
         $tNow = $tStart;
         $i = 1;
         $times[0] = date("H:i", $tNow) . "\n";
         while ($tNow < $tEnd) {
             $tNow = strtotime('+30 minutes', $tNow);
             $times[$i] = date("H:i", $tNow) . "\n";
             $i = $i + 1;
         }
         foreach ($rooms as $room) {
             foreach ($times as $time) {
                 $timeslot = new Timeslot();
                 $timeslot->day = 1;
                 $timeslot->room_code = $room->code;
                 $timeslot->conference_id = $conference->id;
                 $timeslot->time = $time;
                 $timeslot->save();
             }
         }
     } else {
         for ($day = 1, $index = 0; $day < $numDays || $index < $numDays - 1; $day++, $index++) {
             $times = [];
             $tStart = strtotime($first[$index]);
             $tEnd = strtotime($last[$index]);
             $tNow = $tStart;
             $i = 1;
             $times[0] = date("H:i", $tNow) . "\n";
             while ($tNow < $tEnd) {
                 $tNow = strtotime('+30 minutes', $tNow);
                 $times[$i] = date("H:i", $tNow) . "\n";
                 $i = $i + 1;
             }
             //$i os the number of timeslots
             foreach ($rooms as $room) {
                 foreach ($times as $time) {
                     $timeslot = new Timeslot();
                     $timeslot->day = $day;
                     $timeslot->room_code = $room->code;
                     $timeslot->conference_id = $conference->id;
                     $timeslot->time = $time;
                     $timeslot->save();
                 }
             }
         }
     }
     flash()->success("New conference created successfully!!");
     return redirect()->route('user.show');
 }