/**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index($semester = null, $year = null)
 {
     $user = Auth::user();
     $split = explode(" ", $user->role->name);
     $role_area = $split[count($split) - 1];
     $areas = Area::with('professors')->get()->toArray();
     $profe = Professor::with('areas')->get()->toArray();
     $prof_areas = array();
     foreach ($profe as $prof) {
         $prof_areas[$prof['id']] = $prof['areas'];
     }
     $collection = collect($areas);
     $area_professors = $collection->keyBy('name')->toArray();
     // TODO: Pasar esto a un Helper
     if ($semester == null) {
         \Carbon\Carbon::now()->month >= 5 ? $semester = 2 : ($semester = 1);
     }
     $year == null ? $year = \Carbon\Carbon::now()->year : ($year = $year);
     $courses = Course::with('area')->get()->toArray();
     if ($role_area == "Administrador") {
         $professors = Professor::all()->toArray();
         //TODO: Pasar esto a un scope
         $unasigned_courses = Course::with('area')->where('taken', 0)->where('semester', $semester)->where('year', $year)->get();
         $asigned_courses = Course::with('area')->where('taken', 1)->where('semester', $semester)->where('year', $year)->get();
     } else {
         $professors = Area::with('professors')->where('name', $role_area)->get()->toArray()[0]["professors"];
         $area = Area::where('name', $role_area)->first();
         $unasigned_courses = Course::where('taken', 0)->where('area_id', $area->id)->where('semester', $semester)->where('year', $year)->get();
         $asigned_courses = Course::where('taken', 1)->where('area_id', $area->id)->where('semester', $semester)->where('year', $year)->get();
     }
     $professorCourse = array();
     foreach ($courses as $course) {
         if (Schedule::where('course_id', $course['id'])->first() != null) {
             $professorId = Schedule::where('course_id', $course['id'])->first()->professor_id;
             $professorCourse[$course['id']] = Professor::where('id', $professorId)->first()->name;
         }
     }
     return view('schedules.index', compact('area_professors', 'prof_areas', 'professors', 'courses', 'professorCourse', 'unasigned_courses', 'asigned_courses', 'year', 'semester'));
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $professor = Professor::with('areas')->findOrFail($id);
     $areas = Area::all();
     return view('professors.edit', compact('professor', 'areas'));
 }