/**
  * @Post("/reservas/create")
  */
 public function store(Request $request)
 {
     $aWeek = array('M' => 1, 'T' => 2, 'W' => 3, 'Tu' => 4, 'F' => 5, 'S' => 6, 'Su' => 7);
     $todayWeek = date('N');
     $reserveDay = $aWeek[$request->day];
     $daysBetween = $this->subtractDate($todayWeek, $reserveDay);
     $reserveDate = date('Y-m-d', strtotime("now + " . $daysBetween . " day"));
     $reserve = new Reserve();
     $reserve->user_id = $request->user;
     $reserve->event_id = $request->event;
     $reserve->reserve_day = $reserveDate;
     $reserve->save();
     Session::flash('message-success', 'Reserva realizada con exito');
     return Redirect::to("/reservas/nueva");
 }
 /**
  * @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]);
 }
 /**
  * @Get("user/profile/{id}/{tab?}")
  */
 public function profile($id, $tab = 1)
 {
     $today = date('Y-m-d', strtotime('now'));
     $reserves = Reserve::where('user_id', $id)->where('reserve_day', '>', $today)->orderBy('reserve_day')->get();
     $allReserves = Reserve::where('user_id', $id)->orderBy('reserve_day')->get();
     $user = User::find($id);
     $user_exercises = $user->exercise;
     $aData = null;
     $tipos = ActivityType::all();
     foreach ($tipos as $tipo) {
         foreach ($tipo->exercises as $exercise) {
             $flag = false;
             foreach ($user_exercises as $exer) {
                 if ($exer->id == $exercise->id) {
                     $aData['' . $tipo->name][] = [$exercise, $exer->pivot->number];
                     $flag = true;
                 }
             }
             if ($flag == false) {
                 $aData['' . $tipo->name][] = [$exercise, '-'];
             }
         }
     }
     $limiInf = strtotime('now');
     while (date('w', $limiInf) > 1) {
         $limiInf -= 86400;
     }
     $limitSup = date('Y-m-d', $limiInf + 6 * 86400);
     $limiInf = date('Y-m-d', $limiInf);
     $reservesDone = Reserve::where('user_id', \Auth::user()->id)->whereBetween('reserve_day', [$limiInf, $limitSup])->count();
     return view('user.profile', ['user' => $user, 'tipos' => $aData, 'tab' => $tab, 'reserves' => $reserves, 'allReserves' => $allReserves, 'leftOverReserves' => $user->payment == null ? "" : $user->payment->weekReserves - $reservesDone]);
 }