public function postSetInitial(Request $request) { $session_id = $request->input('session_id'); $input = ['session_id' => $session_id]; $validator = validator::make($request->all(), ['session_id' => 'required']); if ($validator->fails()) { return ApiResponseClass::errorResponse('You Have Some Input Errors. Please Try Again!!', $input, $validator->errors()); } else { $user_registered_to_school = UsersRegisteredToSchool::where('user_id', Auth::user()->id)->get()->first(); if ($user_registered_to_school) { $user_registered_to_session = UsersRegisteredToSession::where('session_id', $session_id)->where('user_id', Auth::user()->id)->get()->first(); if ($user_registered_to_session) { return ApiResponseClass::successResponse($user_registered_to_session, $input); } $user_registered_to_session = new UsersRegisteredToSession(); $user_registered_to_session->session_id = $session_id; $user_registered_to_session->school_id = $user_registered_to_school->school_id; $user_registered_to_session->user_id = Auth::user()->id; $user_registered_to_session->save(); if ($user_registered_to_session->save()) { return ApiResponseClass::successResponse($user_registered_to_session, $input); } } } return ApiResponseClass::errorResponse('There is Something Wrong. Please Try Again!!', $input); }
/** * SchoolAndUserBasicInfo constructor. * @param $user * @param $userId * @param $schoolId */ public function __construct() { $userId = Auth::user()->id; $this->userId = $userId; $this->user = User::find($userId); $this->schoolId = UsersRegisteredToSchool::where('user_id', $userId)->get()->first()->school_id; $this->currentSchoolSession = SchoolSession::where('school_id', $this->schoolId)->where('current_session', 1)->get()->first(); $this->currentSchoolSessionId = $this->currentSchoolSession->id; }
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); }
protected function goToAfterSignInAdmin($user_id) { $userType = RequiredFunctions::checkUserTypeByUserId($user_id); if ($userType != Groups::Administrator_Group_ID) { return redirect(route('admin-welcome-settings'))->with('global', 'Sorry Something went Wrong. Please try again Later!!'); } $user_registered_to_school = UsersRegisteredToSchool::where('user_id', $user_id)->get()->first(); if ($user_registered_to_school && $user_registered_to_school->count() > 0) { $school_session = SchoolSession::where('school_id', '=', $user_registered_to_school->school_id)->where('current_session', '=', 1)->get()->first(); if ($school_session && $school_session->count() > 0) { if ($this->userLoginInfo(Auth::user()->id, $user_registered_to_school->school_id)) { return redirect(route('admin-home')); } } else { return redirect(route('admin-class-set-initial'))->with('global', 'Loggedin Successfully. You Have to Register For new School Session first'); } } else { return redirect(route('admin-welcome-settings')); } return redirect(route('account-admin-sign-in'))->with('global', 'Sorry Something went Wrong. Please try again Later!!'); }