예제 #1
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($date, $area, $professorId = null)
 {
     if ($professorId == null) {
     }
     $insert_control = Insert_control::where('period', $date)->first();
     if ($insert_control == null) {
         $insert_control = 0;
     } else {
         $insert_control = $insert_control->available;
     }
     $userRole = Auth::user()->role()->first()->name;
     $dateExp = explode("-", $date);
     $year = $dateExp[0];
     $semester = $dateExp[1];
     $professor = Professor::find($professorId);
     $professorFromAreas = Area::where('name', $area)->first()->professors()->get();
     $arrayProfessors = array();
     foreach ($professorFromAreas as $professorFromArea) {
         $arrayProfessors[$professorFromArea->id] = $professorFromArea->name;
     }
     if (!isset($professor)) {
         $status = 1;
         $arrayProfessorss = $arrayProfessors;
         $arrayProfessorss[""] = "";
         return view('schedules.show', compact("status", "year", "semester", "arrayProfessorss"));
     }
     $todasAreas = Area::all()->toArray();
     $arrayAreas = array();
     foreach ($todasAreas as $unArea) {
         $arrayAreas[$unArea['id']] = $unArea['name'];
     }
     $professorLoad = 0;
     $arrayCourses = array();
     $areaCourses = Course::join('areas', 'areas.id', '=', 'courses.area_id')->where('areas.name', $area)->where('courses.year', $year)->where('courses.semester', $semester)->select('courses.id', 'courses.year', 'courses.semester', 'areas.name', 'courses.branch', 'courses.section', 'courses.code', 'courses.schedule')->get();
     $courseSelect = array();
     foreach ($areaCourses as $oneCourse) {
         if (count($oneCourse->schedule()->groupBy('professor_id')->get()) == 0) {
             $courseSelect[$oneCourse->id] = $oneCourse->code . "-" . $oneCourse->section . "-" . $oneCourse->year . "-" . $oneCourse->semester . " " . $oneCourse->branch . " (" . $oneCourse->schedule . ")";
         }
     }
     $schedules = Schedule::join('courses', 'courses.id', '=', 'schedules.course_id')->where('schedules.professor_id', $professorId)->where('courses.year', $year)->where('courses.semester', $semester)->get();
     foreach ($schedules as $schedule) {
         $course = array();
         $code = $schedule->course()->first()->code;
         $course['name'] = $schedule->course()->first()->name;
         $course['area'] = $arrayAreas[$schedule->course()->first()->area_id];
         $course['branch'] = $schedule->course()->first()->branch;
         $course['section'] = $schedule->course()->first()->section;
         $course['semester'] = $schedule->course()->first()->semester;
         $course['id'] = $schedule->course()->first()->id;
         $course['year'] = $schedule->course()->first()->year;
         $course['schedule'] = explode("-", $schedule->course()->first()->schedule);
         $course['code'] = $code;
         $arrayCourses[$code . "-" . $course['section']] = $course;
         // $professorLoad = $professorLoad + count($course['schedule'])*22.5;
         foreach ($course['schedule'] as $horario) {
             $array[$horario] = $course['code'] . "-" . $course['section'];
         }
     }
     $schedulesYear = Schedule::join('courses', 'courses.id', '=', 'schedules.course_id')->where('schedules.professor_id', $professorId)->where('courses.year', $year)->get();
     foreach ($schedulesYear as $sche) {
         $professorLoad = $professorLoad + count(explode("-", $sche->course()->first()->schedule)) * 22.5;
     }
     if ($semester == 1) {
         $nextSemester = 2;
         $nextYear = $year;
         $previewsYear = $year - 1;
     } else {
         $nextSemester = 1;
         $nextYear = $year + 1;
         $previewsYear = $year;
     }
     $nextDate = $nextYear . "-" . $nextSemester;
     $previewsDate = $previewsYear . "-" . $nextSemester;
     $urlAnterior = "schedules/{$previewsDate}/{$area}/{$professor->id}";
     $urlSiguiente = "schedules/{$nextDate}/{$area}/{$professor->id}";
     return view('schedules.show', compact('year', 'semester', 'urlAnterior', 'urlSiguiente', 'professor', 'courseSelect', 'arrayCourses', 'arrayProfessors', 'array', 'area', 'professorLoad', 'userRole', 'insert_control'));
 }