Beispiel #1
0
 public function postValidateSchool(Request $request)
 {
     $registration_code = $request->input('registration_code');
     $group_id = $request->input('group_id');
     $input = ['group_id' => $group_id, 'registration_code' => $registration_code];
     $validator = validator::make($request->all(), ['group_id' => 'required', 'registration_code' => 'required']);
     if ($validator->fails()) {
         return ApiResponseClass::errorResponse('You Have Some Input Errors. Please Try Again!!', $input, $validator->errors());
     } else {
         $code = array();
         $group = Groups::find($group_id);
         if ($group && $group->count() > 0) {
             if ($group_id == Groups::Teacher_Group_Id) {
                 $code_for_teachers = $request->input('code_for_teachers');
                 $school = Schools::where('registration_code', $registration_code)->where('code_for_teachers', $code_for_teachers)->get()->first();
                 $code = array('code_for_teachers' => $code_for_teachers);
             } elseif ($group_id == Groups::Student_Group_Id) {
                 $code_for_students = $request->input('code_for_students');
                 $school = Schools::where('registration_code', $registration_code)->where('code_for_students', $code_for_students)->get()->first();
                 $code = array('code_for_students' => $code_for_students);
             } elseif ($group_id == Groups::Administrator_Group_ID) {
                 $code_for_admin = $request->input('code_for_admin');
                 $school = Schools::where('registration_code', $registration_code)->where('code_for_admin', $code_for_admin)->get()->first();
                 $code = array('code_for_admin' => $code_for_admin);
             }
             $input = array('registration_code' => $registration_code, 'group_id' => $group_id);
             $input = array_merge($input, $code);
             if ($school && $school->count() > 0) {
                 $result = array('school' => $school);
                 $users_registered_to_school = UsersRegisteredToSchool::where('user_id', Auth::user()->id)->where('school_id', $school->id)->get()->first();
                 if ($users_registered_to_school) {
                     return ApiResponseClass::successResponse($result, $input);
                 }
                 $users_registered_to_school = new UsersRegisteredToSchool();
                 $users_registered_to_school->user_id = Auth::user()->id;
                 $users_registered_to_school->school_id = $school->id;
                 $users_registered_to_school->registration_date = date('Y-m-d H:i:s');
                 $users_registered_to_school->save();
                 if ($users_registered_to_school->save()) {
                     return ApiResponseClass::successResponse($result, $input);
                 }
             } else {
                 return ApiResponseClass::errorResponse('School Codes are InValid. Please Try again with Correct Codes!!', $input);
             }
         }
     }
     return ApiResponseClass::errorResponse('Some Problem Occured. Please Try again With Correct Codes!!', $input);
 }
 public function postGetSchoolInformation()
 {
     $school = Schools::find($this->getSchoolAndUserBasicInfo()->getSchoolId());
     return ApiResponseClass::successResponse($school);
 }