public function getTimetable(Request $request)
 {
     $user_id = $request->input('id');
     /**
      * Dữ liệu trả về
      */
     $response = new stdClass();
     $user = User::getInfoById($user_id);
     if ($user == null) {
         $response->error = true;
         $response->error_msg = 'Đã có vấn đề xảy ra! Bạn vui long quay lại sau.';
         return response()->json($response);
     }
     /**
      * Giáo viên
      */
     if ($user->type == 'teacher') {
         $u_x_id = $user->id;
         $classSubXS = SubClassSubject::all()->where('teacher', intval($u_x_id))->where('nhom', 0);
         if ($classSubXS->count() == 0) {
             $response->error = true;
             $response->error_msg = 'Đã có vấn đề xảy ra! Bạn vui long quay lại sau.';
             return response()->json($response);
         }
         $arr_items = [];
         foreach ($classSubXS as $i => $s) {
             $s_id = $s->id;
             $subClassSubject = SubClassSubject::all()->where('id', intval($s_id))->first();
             $class_id = $subClassSubject->classSubject;
             $classSubject = ClassSubject::all()->where('id', intval($class_id))->first();
             $subject_id = $classSubject->subject;
             $subject = Subject::all()->where('id', intval($subject_id))->first();
             $item_s = new stdClass();
             $item_s->maMH = $subject->maMH;
             $item_s->maLMH = $classSubject->maLMH;
             $item_s->name = $subject->name;
             $item_s->soTin = $subject->soTin;
             $item_s->viTri = $subClassSubject->viTri;
             $item_s->soTiet = $subClassSubject->soTiet;
             $item_s->soSV = $subClassSubject->soSV;
             $item_s->nhom = $subClassSubject->nhom;
             $item_s->address = $subClassSubject->address;
             $item_s->teacher = User::getInfoById($subClassSubject->teacher);
             $arr_items[] = $item_s;
         }
     } else {
         $timetable = TimeTable::all()->where('user', intval($user_id));
         if ($timetable->count() == 0) {
             $response->error = true;
             $response->error_msg = 'Bạn chưa đồng bộ thời khóa biểu!';
             return response()->json($response);
         }
         $arr_items = [];
         foreach ($timetable as $i => $s) {
             $s_id = $s->subClass;
             $subClassSubject = SubClassSubject::all()->where('id', intval($s_id))->first();
             $class_id = $subClassSubject->classSubject;
             $classSubject = ClassSubject::all()->where('id', intval($class_id))->first();
             $subject_id = $classSubject->subject;
             $subject = Subject::all()->where('id', intval($subject_id))->first();
             $item_s = new stdClass();
             $item_s->maMH = $subject->maMH;
             $item_s->maLMH = $classSubject->maLMH;
             $item_s->name = $subject->name;
             $item_s->soTin = $subject->soTin;
             $item_s->viTri = $subClassSubject->viTri;
             $item_s->soTiet = $subClassSubject->soTiet;
             $item_s->soSV = $subClassSubject->soSV;
             $item_s->nhom = $subClassSubject->nhom;
             $item_s->address = $subClassSubject->address;
             $item_s->teacher = User::getInfoById($subClassSubject->teacher);
             $arr_items[] = $item_s;
         }
     }
     $filter = [];
     $filter[0] = $arr_items[0];
     $j = 0;
     for ($i = 1; $i < count($arr_items); $i++) {
         if ($filter[$j]->maLMH != $arr_items[$i]->maLMH || $filter[$j]->nhom != $arr_items[$i]->nhom) {
             $j++;
             $filter[$j] = $arr_items[$i];
         }
     }
     $response->error = false;
     $response->timetable = $filter;
     return response()->json($response);
 }
 public function getGroup(Request $request)
 {
     onlyAllowPostRequest($request);
     $id_user = intval($request->input('id'));
     $base = $request->input('base');
     /**
      * Dữ liệu trả về
      */
     $response = new stdClass();
     $users = User::all()->where('id', $id_user);
     if ($users->count() == 0) {
         //
         $response->error = true;
         $response->error_msg = 'Không tồn tại người dùng này!';
         return response()->json($response);
     }
     $user = $users->first();
     $arrGroup = [];
     if ($base == 'class_xes') {
         $id_class = $user->class;
         $classX = ClassX::all()->where('id', $id_class)->first();
         $class_x = new stdClass();
         $class_x->id = $classX->id;
         $class_x->base = $base;
         $class_x->name = $classX->name;
         $class_x->soSV = ClassX::getCountStudentByClassId($id_class);
         $class_x->teacher = User::getInfoById($classX->teacher);
         $arrGroup = [$class_x];
     }
     if ($base == 'classSubject') {
         /**
          * Giáo viên
          */
         if ($user->type == 'teacher') {
             $u_x_id = $user->id;
             $classSubXS = SubClassSubject::all()->where('teacher', intval($u_x_id))->where('nhom', 0);
             if ($classSubXS->count() == 0) {
                 $response->error = true;
                 $response->error_msg = 'Đã có vấn đề xảy ra! Bạn vui long quay lại sau.';
                 return response()->json($response);
             }
             $arrGroup = [];
             foreach ($classSubXS as $k => $cls) {
                 $sub_id = $cls->id;
                 $subClassSubject = SubClassSubject::all()->where('id', intval($sub_id))->first();
                 $teacher_id = $subClassSubject->teacher;
                 $lmh_id = $subClassSubject->classSubject;
                 $classSubject = ClassSubject::all()->where('id', intval($lmh_id))->first();
                 $maLMH = $classSubject->maLMH;
                 $subject_id = $classSubject->subject;
                 $subject = Subject::all()->where('id', intval($subject_id))->first();
                 $cl = new stdClass();
                 $cl->base = 'classSubject';
                 $cl->id = $classSubject->id;
                 $cl->maLMH = $maLMH;
                 $cl->name = $subject->name;
                 $cl->soSV = $subClassSubject->soSV;
                 $cl->teacher = User::getInfoById($teacher_id);
                 $arrGroup[] = $cl;
             }
         } else {
             $timeTables = TimeTable::all()->where('user', $user->id);
             if ($timeTables->count() == 0) {
                 $response->error = true;
                 $response->error_msg = 'Tài khoản chưa có lớp môn học nào!';
                 return response()->json($response);
             }
             foreach ($timeTables as $tt) {
                 $sub_id = $tt->subClass;
                 $subClassSubject = SubClassSubject::all()->where('id', intval($sub_id))->first();
                 $teacher_id = $subClassSubject->teacher;
                 $lmh_id = $subClassSubject->classSubject;
                 $classSubject = ClassSubject::all()->where('id', intval($lmh_id))->first();
                 $maLMH = $classSubject->maLMH;
                 $subject_id = $classSubject->subject;
                 $subject = Subject::all()->where('id', intval($subject_id))->first();
                 $cl = new stdClass();
                 $cl->base = 'classSubject';
                 $cl->id = $classSubject->id;
                 $cl->maLMH = $maLMH;
                 $cl->name = $subject->name;
                 $cl->soSV = $subClassSubject->soSV;
                 $cl->teacher = User::getInfoById($teacher_id);
                 if ($subClassSubject->nhom == 0) {
                     $arrGroup[] = $cl;
                 }
             }
         }
     }
     $filter = [];
     $filter[0] = $arrGroup[0];
     $j = 0;
     for ($i = 1; $i < count($arrGroup); $i++) {
         if ($filter[$j]->maLMH != $arrGroup[$i]->maLMH) {
             $j++;
             $filter[$j] = $arrGroup[$i];
         }
     }
     $arrGroup = $filter;
     $response->error = false;
     $response->group = $arrGroup;
     return response()->json($response);
 }