コード例 #1
0
 /**
  * @Get("horario")
  */
 public function showSchedule()
 {
     $aWeek = array('M' => 1, 'T' => 2, 'W' => 3, 'Tu' => 4, 'F' => 5, 'S' => 6, 'Su' => 7);
     $aOcuppied = array();
     $days = array(1 => "", 2 => "", 3 => "", 4 => "", 5 => "", 6 => "", 7 => "");
     $schedule = Schedule::where('active', 1)->get()->first();
     $events = ClaseSchedule::where('schedule_id', $schedule->id)->orderBy('date')->orderBy('startTime')->get();
     foreach ($events as $event) {
         $todayWeek = date('N');
         $reserveDay = $aWeek[$event->date];
         $daysBetween = $this->subtractDate($todayWeek, $reserveDay);
         $reserveDate = date('Y-m-d', strtotime("now + " . $daysBetween . " day"));
         $placesOcuppied = Reserve::where('reserve_day', $reserveDate)->where('event_id', $event->id)->count();
         $aOcuppied[$event->date][$event->id] = $event->capMax - $placesOcuppied;
         if ($days[$aWeek[$event->date]] == "") {
             $dateExplode = explode('-', $reserveDate);
             $days[$aWeek[$event->date]] = $dateExplode[2] . "/" . $dateExplode[1] . "/" . $dateExplode[0];
         }
     }
     // foreach ($days as $key => $value) {
     //     if($value == "")
     //         $days[$key] = date('Y-m-d', strtotime($days[($key-1 == 0)?7:$key-1]." + 1 day"));
     // }
     return view('schedule.viewSchedule', ['schedule' => $schedule, 'clases' => Clase::lists('name', 'id'), 'schedules' => Schedule::lists('name', 'id'), 'rooms' => Room::lists('name', 'id'), 'instructors' => User::where('type_id', 2)->lists('name', 'id'), 'places' => $aOcuppied, 'events' => $events, 'days' => $days]);
 }