/** * 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(); }
/** * Add elective counts * * @param Request $request * @return mixed */ public function addElectiveCounts(Request $request) { if (!$this->isRegistrationActive('staff')) { return view($this->inactiveView); } $this->validate($request, ['openElectives' => 'required|min:0', 'departmentElectives' => 'required|min:0']); $data = ['dCode' => Auth::guard('teacher')->user()->dCode, 'semNo' => Auth::guard('teacher')->user()->semNo, 'openElectives' => $request['openElectives'], 'departmentElectives' => $request['departmentElectives']]; // Insert into databse $electiveCount = ElectiveCount::where(['dCode' => Auth::guard('teacher')->user()->dCode, 'semNo' => Auth::guard('teacher')->user()->semNo])->get(); if (count($electiveCount) > 0) { ElectiveCount::where(['dCode' => Auth::guard('teacher')->user()->dCode, 'semNo' => Auth::guard('teacher')->user()->semNo])->delete(); ElectiveCount::create($data); } else { ElectiveCount::create($data); } return redirect()->back()->with('status', 'Updated Successfully'); }
/** * Allocate department/open elective subjects to the students * * @param Request $request */ public function allocateElectives(Request $request) { $currentStudentState = $this->getCurrentStudentState(); if ($request->has('courseCode')) { $this->validate($request, ['courseCode' => 'required']); $courseCode = $request['courseCode']; // Get the elective count $electiveCount = ElectiveCount::where(['dCode' => Auth::guard('student')->user()->dCode, 'semNo' => $this->getCurrentStudentState()->semNo])->get(); $totalElectives = $electiveCount[0]->openElectives + $electiveCount[0]->departmentElectives; // Validate that no two electives are same $courseCount = array_count_values($courseCode); for ($no = 0; $no < $totalElectives; $no++) { if ($courseCount[$courseCode[$no]] > 1) { return redirect()->back()->with('status', 'Please don not choose identical electives'); } } // Check if seats are available in the chosen electives for ($no = 0; $no < $totalElectives; $no++) { $maxStrength = 90; $currentStrength = AllocatedElective::where('courseCode', $courseCode[$no])->count(); if ($currentStrength >= $maxStrength) { return redirect()->back()->with('status', 'Sorry, elective ' . $courseCode[$no] . ' is not having any vacant seats. Please choose another one.'); } } // Allocate the electives to student for ($no = 0; $no < $totalElectives; $no++) { AllocatedElective::create(['rollNo' => Auth::guard('student')->user()->rollNo, 'courseCode' => $courseCode[$no]]); } } $currentStudentState->step = 3; $currentStudentState->save(); // Now redirect to the status view return redirect('/students/semesterRegistration/status'); }