/**
  * Set registration process active / in-active
  *
  * @param $user
  * @return mixed
  */
 public function toggleRegistrationProcess($user)
 {
     if ($user === 'staff') {
         if ($this->isRegistrationActive('staff')) {
             unlink(storage_path() . '/app/activeForStaff');
             // Clear the tables
             Grade::truncate();
             ElectiveCount::truncate();
             TeacherRequest::truncate();
             AllocatedElective::truncate();
             AdminStaffRequest::truncate();
             HostelStaffRequest::truncate();
             CurrentStudentState::truncate();
             LibraryStaffRequest::truncate();
             ChiefWardenStaffRequest::truncate();
             Teacher::where('semNo', '>', '0')->update(['semNo' => null]);
         } else {
             touch(storage_path() . '/app/activeForStaff');
         }
     } else {
         if ($user === 'students') {
             if ($this->isRegistrationActive('student')) {
                 unlink(storage_path() . '/app/activeForStudents');
             } else {
                 touch(storage_path() . '/app/activeForStudents');
             }
         }
     }
     return redirect()->back();
 }
 /**
  * Handle an incoming request. Current state of the student in the registration process
  * is called step. There are a total of 3 steps in the semester registration
  * process and the step numbering used is as follows:
  *
  *  ______________________________
  * | #Step | Represented step     |
  *  ------------------------------
  * |   1   | initial details      |
  * |   2   | feeAndHostel details |
  * |   3   | course details       |
  *  ------------------------------
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  integer $currentStep
  * @return mixed
  */
 public function handle($request, Closure $next, $currentStep)
 {
     if (Auth::guard('student')->check()) {
         $currentStudentState = CurrentStudentState::find(Auth::guard('student')->user()->rollNo);
         /**
          * If student has not completed the first step
          * then redirect him to initial details page
          * other wise redirect him to the correct
          * page accourding to his current state
          */
         if ($currentStudentState == null) {
             /*
              * This check avoids redirection loop
              * in case the student is accessing
              * the initial details page
              */
             if ($currentStep != 1) {
                 return redirect('/students/semesterRegistration/initialDetails');
             }
             return $next($request);
         } else {
             $step = $currentStudentState->step;
             /**
              * Redirect if student tries to visit a step
              * without completing the previous one and
              * let the request pass to the inner
              * layers if his request if valid
              */
             if ($currentStep != $step + 1) {
                 if ($step == 1) {
                     return redirect('/students/semesterRegistration/feeAndHostelDetails');
                 } elseif ($step == 2) {
                     return redirect('/students/semesterRegistration/courseDetails');
                 } else {
                     return redirect('/students/semesterRegistration/status');
                 }
             }
             return $next($request);
         }
     }
     return $next($request);
 }
 /**
  * Register a student for new semester
  *
  * @param Request $request
  * @return mixed
  */
 public function registerStudent(Request $request)
 {
     if (!$this->isRegistrationActive('staff')) {
         return view($this->inactiveView);
     }
     $rollNo = $request['rollNo'];
     // Now register the student
     $verificationCode = $this->generateVerificationCode($rollNo);
     CurrentStudentState::find($rollNo)->update(['approved' => true, 'verificationCode' => $verificationCode]);
     Student::find($rollNo)->update(['semNo' => CurrentStudentState::find($rollNo)->semNo]);
     return redirect()->back();
 }
 /**
  * Add initial details of student
  *
  * @param Request $request
  */
 public function addInitialDetails(Request $request)
 {
     if (!$this->isRegistrationActive('student')) {
         return view($this->inactiveView);
     }
     $this->validateRequest($request);
     $data = ['rollNo' => Auth::guard('student')->user()->rollNo, 'semNo' => $request['semNo'], 'loanCase' => $request['loanCase'] == 'yes' ? true : false, 'feeReceipt' => $request['feeReceipt'] == 'yes' ? true : false, 'hostler' => $request['hostler'] == 'yes' ? true : false];
     // Insert the details into database
     $this->addGrades($request);
     $currentStudentState = CurrentStudentState::firstOrNew(['rollNo' => $data['rollNo']]);
     $currentStudentState->feeReceipt = $data['feeReceipt'];
     $currentStudentState->loanCase = $data['loanCase'];
     $currentStudentState->hostler = $data['hostler'];
     $currentStudentState->semNo = $data['semNo'];
     $currentStudentState->approved = false;
     $currentStudentState->step = 1;
     $currentStudentState->save();
     // Now redirect to next step
     return redirect('/students/semesterRegistration/feeAndHostelDetails');
 }