Exemplo n.º 1
0
 public function index(Request $request)
 {
     $sessions = StudentClassroomSession::select('csa.valid as attended', 'cs.subject_subject_id as subject_id', 'scs.student_link', 'scs.id', 'cse.status as excuseStatus', 'cs.start_at', 'scs.classroom_session_id')->with(['classroomSession', 'classroomSession.interval' => function ($query) {
         $query->select('enable_excuses', 'enable_attendances', 'title', 'id');
     }, 'classroomSession.subject' => function ($query) {
         return $query->select('id', 'name');
     }])->join('classroom_sessions as cs', 'cs.id', '=', 'scs.classroom_session_id')->join('student_subjects as ss', function ($join) {
         $join->on('ss.subject_id', '=', 'cs.subject_subject_id')->where('ss.state', '=', 'study')->where('ss.student_id', '=', $this->student->id);
     })->join('classroom_students as clst', function ($query) {
         return $query->on('clst.classroom_id', '=', 'cs.classroom_id')->where('clst.student_id', '=', $this->student->id);
     })->from('student_classroom_sessions as scs')->leftJoin('classroom_session_attendances as csa', function ($query) {
         $query->on('csa.classroom_session_id', '=', 'scs.classroom_session_id')->where('csa.student_id', '=', $this->student->id);
     })->leftJoin('classroom_session_excuses as cse', function ($query) {
         $query->on('cse.session_id', '=', 'scs.classroom_session_id')->where('cse.student_id', '=', $this->student->id)->where('cse.semester_id', '=', $this->semester->id);
     })->where('scs.student_id', $this->student->id)->orderBy('start_at', 'ASC')->groupBy('scs.id')->get();
     // if($request->has('ps')) {
     foreach ($sessions as $session) {
         $session->classroomSession->recording_link = str_replace('http', 'https', $session->classroomSession->recording_link);
         $session->student_link = str_replace('http', 'https', $session->student_link);
     }
     // }
     // Cache::put('student_'.$this->student->id.'_api_sessions', $sessions, 300);
     return response()->json($sessions, 200, [], JSON_NUMERIC_CHECK);
 }