-
Notifications
You must be signed in to change notification settings - Fork 1
Subject Management #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Controllers; | ||
|
|
||
| use App\Enums\CourseTypes; | ||
| use Illuminate\Http\Request; | ||
| use Illuminate\Support\Facades\Auth; | ||
| use App\Models\Subject; | ||
| use App\Models\Course; | ||
| use App\Models\Faculty; | ||
| use App\Models\Classroom; | ||
| use App\Http\Requests\SubjectRequest; | ||
|
|
||
| class CourseController extends Controller | ||
| { | ||
|
|
||
| /* | ||
| *Middleware for checking whether user is HOD | ||
| */ | ||
|
|
||
|
|
||
| public function index(){ | ||
| $auth_user = Auth::user(); | ||
| $faculty = $auth_user->faculty; | ||
| $department_code = $faculty->department_code; | ||
|
|
||
| if ($faculty && $faculty->isHOD()) { | ||
| $courses = Course::with(['Classroom','Subject','Faculty'])->get(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| // No idea to filter hod's department related stuff from database,so basically filtering in views | ||
| return view('courses.index',["courses" => $courses,"department_code" => $department_code]); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| public function create(){ | ||
| // HOD create subjects here - get request do it returns | ||
| // that page to HOD | ||
| $auth_user = Auth::user(); | ||
| $faculty = $auth_user->faculty; | ||
| // print $faculty; | ||
| $department_code = $faculty->department_code; | ||
|
|
||
| $classrooms = Classroom::all(); | ||
| $faculties = Faculty::where('department_code',$department_code)->get(); | ||
| $subjects = Subject::where('department_code',$department_code)->get(); | ||
| $types = CourseTypes::getKeys(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use this enum directly in views, no need to pass from controller |
||
|
|
||
| return view('courses.create',["classrooms"=>$classrooms,"faculties"=>$faculties,"types"=>$types,"subjects"=>$subjects]); | ||
| } | ||
|
|
||
| public function store(Request $request){ | ||
| // create new subject - POST | ||
|
|
||
| /* | ||
| * Needs to do request validation | ||
| * Move Course creation to model | ||
| * Javascipt function to check Course is already existing or not | ||
| * Optimise Course creation | ||
| */ | ||
|
|
||
| $auth_user = Auth::user(); | ||
| $faculty = $auth_user->faculty; | ||
| $department_code = $faculty->department_code; | ||
|
|
||
| $data = $request->input(); | ||
|
|
||
| $course = new Course(); | ||
| $course->type = CourseTypes::getValue($data["type"]); | ||
| $course->faculty_id=$data["faculty"]; | ||
| $course->classroom_id = $data["classroom"]; | ||
| $course->subject_code = $data["subject"]; | ||
| // Here is room for improvement instead of again querying in database table,we can infer it from above | ||
| // message/ do we need this in the first place <<Semester>> | ||
| $course->semester = Classroom::where('id',$data["classroom"])->get('semester')->first()->semester; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do course need a semester as it is always linked to classroom?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question, classroom was added after semester, so we do need to to think about it. Maybe we could make semester null for other courses, and add a getter |
||
| $course->save(); | ||
|
|
||
|
|
||
|
|
||
| return redirect()->route('courses.index'); | ||
|
|
||
|
|
||
| } | ||
|
|
||
|
|
||
| public function edit($id){ | ||
| //get page for updating specific subject | ||
| // check whether this hod has permission to update this course | ||
|
|
||
| $auth_user = Auth::user(); | ||
| $faculty = $auth_user->faculty; | ||
| $department_code = $faculty->department_code; | ||
|
|
||
| $classrooms = Classroom::all(); | ||
| $faculties = Faculty::where('department_code',$department_code)->get(); | ||
| $subjects = Subject::where('department_code',$department_code)->get(); | ||
| $types = CourseTypes::getKeys(); | ||
| $course = Course::where('id',$id)->first(); | ||
| $courseType = CourseTypes::getKey($course->type); // we need this as as we are displaying value of enum but store key in db | ||
| return view('courses.edit',["classrooms"=>$classrooms,"faculties"=>$faculties,"types"=>$types,"subjects"=>$subjects,"course"=>$course,"courseType"=>$courseType]); | ||
| } | ||
|
|
||
| public function update(Request $request ,$id){ | ||
| // modifying the existing course resource | ||
|
|
||
| /* | ||
| * Needs to do request validation | ||
| * Move Course creation to model | ||
| * Javascipt function to check subject code is unique or not in client side | ||
| * Optimise Course creation | ||
| * Update method - PUT/PATCH ? | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PATCH |
||
| * Check whether this HOD has power to update this course | ||
| */ | ||
|
|
||
| $auth_user = Auth::user(); | ||
| $faculty = $auth_user->faculty; | ||
| $department_code = $faculty->department_code; | ||
|
|
||
| $data = $request->input(); | ||
| $editCourse = Course::where('id',$id)->first(); // need to find better method than this | ||
| // this queries and retreives , but we dont' need retreival here ,only updation is needed | ||
| $editCourse->faculty_id=$data["faculty"]; | ||
| $editCourse->classroom_id = $data["classroom"]; | ||
| $editCourse->subject_code = $data["subject"]; | ||
| $editCourse->type = CourseTypes::getValue($data["type"]); | ||
|
Comment on lines
+121
to
+124
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should all fields be updatable? |
||
| $editCourse->semester = Classroom::where('id',$data["classroom"])->get('semester')->first()->semester; | ||
| $editCourse->save(); | ||
| return redirect()->route('courses.index'); | ||
|
|
||
| } | ||
|
|
||
| public function destroy($id){ | ||
| // delete specific subjects - delete request | ||
| // check for permission to delete this stuff by current hod | ||
| $response=Course::where('id',$id)->delete(); | ||
| return redirect()->route('courses.index'); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Controllers; | ||
|
|
||
| use Illuminate\Http\Request; | ||
| use Illuminate\Support\Facades\Auth; | ||
| use App\Models\Subject; | ||
| use App\Models\Faculty; | ||
| use App\Http\Requests\SubjectRequest; | ||
|
|
||
| class SubjectController extends Controller | ||
| { | ||
|
|
||
|
|
||
|
|
||
|
|
||
| /* | ||
| *Middleware for checking whether user is HOD | ||
| */ | ||
|
|
||
|
|
||
|
|
||
| public function index(){ | ||
| $auth_user = Auth::user(); | ||
| $faculty = $auth_user->faculty; | ||
| // print $faculty; | ||
| $department_code = $faculty->department_code; | ||
| // print $department_code; | ||
|
|
||
| if ($faculty && $faculty->isHOD()) { | ||
| $subjects = Subject::where('department_code',$department_code)->get(); | ||
| // $faculty = Faculty::where('department_code',$department_code)->get(); | ||
| return view('subjects.index',["subjects" => $subjects]); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| public function create(){ | ||
| // HOD create subjects here - get request do it returns | ||
| // that page to HOD | ||
| return view('subjects.create'); | ||
| } | ||
|
|
||
| public function store(Request $request){ | ||
| // create new subject - POST | ||
|
|
||
| /* | ||
| * Needs to do request validation | ||
| * Move subject creation to model | ||
| * Javascipt function to check subject code is already existing or not | ||
| * Optimise Subject creation | ||
| */ | ||
| $auth_user = Auth::user(); | ||
| $faculty = $auth_user->faculty; | ||
| $department_code = $faculty->department_code; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Admin can create subjects. They may no be a faculty.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't it better that HOD's do subject creation , since subject belongs to a department
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Admin can literally do anything, admin is GOD, so don't restrict admin. |
||
|
|
||
| $data = $request->input(); | ||
|
|
||
| $subject = new Subject(); | ||
| $subject->name = $data["name"]; | ||
| $subject->credits = $data["credit"]; | ||
| $subject->code = $data["courseId"]; | ||
| //This is the primary key check for its uniqueness and return error | ||
| $subject->department_code = $department_code; | ||
| $subject->save(); | ||
|
|
||
|
|
||
|
|
||
| return redirect()->route('subjects.index'); | ||
|
|
||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| public function edit($subject_code){ | ||
| //get page for updating specific subject | ||
| // check whether this hod has permission to see this subject | ||
| $subject = Subject::where('code',$subject_code)->get()->first(); | ||
| return view('subjects.edit',["subject"=>$subject]); | ||
| } | ||
|
|
||
| public function update(Request $request){ | ||
| // modifying the existing subject configuration | ||
|
|
||
| /* | ||
| * Needs to do request validation | ||
| * Move subject creation to model | ||
| * Javascipt function to check subject code is unique or not in client side | ||
| * Optimise Subject creation | ||
| * Update method - PUT/PATCH ? | ||
| * Check whether this HOD has power to update this subject | ||
| */ | ||
| $auth_user = Auth::user(); | ||
| $faculty = $auth_user->faculty; | ||
| $department_code = $faculty->department_code; | ||
| print $request; | ||
| // Since subject-code is unique check whether that is existing and return error,currently we dont do that | ||
| $data = $request->input(); | ||
| $code = $data["code"]; | ||
| $subject = Subject::where('code',$code)->first(); | ||
| $subject->name = $data["name"]; | ||
| $subject->credits = $data["credit"]; | ||
| $subject->code = $data["code"]; | ||
| $subject->save(); | ||
| return redirect()->route('subjects.index'); | ||
|
|
||
| } | ||
|
|
||
| public function destroy($subject_code){ | ||
| // delete specific subjects - delete request | ||
| // check for permission to delete this stuff by current hod | ||
| $auth_user = Auth::user(); | ||
| $faculty = $auth_user->faculty; | ||
| $department_code = $faculty->department_code; | ||
|
|
||
| $response=Subject::where('code',$subject_code)->delete(); | ||
| // use this to send response to confirm deletion | ||
| return redirect()->route('subjects.index'); | ||
|
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| @extends("layouts.layout") | ||
|
|
||
| @section("head") | ||
| <script> | ||
| function deleteAttendance(url){ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| @extends('layouts.layout') | ||
|
|
||
|
|
||
| @section('content') | ||
| <h1> Create New Course </h1> | ||
| <form action="{{route('courses.store')}}" method="POST"> | ||
| @csrf | ||
| <div> | ||
| <label for="subject">Select a subject :</label> | ||
| <select name="subject" id="subject"> | ||
| @foreach ($subjects as $subject) | ||
| <option value="{{$subject->code}}">{{$subject->code}} {{$subject->name}}</option> | ||
| @endforeach | ||
| </select> | ||
| <a href ="{{route('subjects.create')}}">Add New Subject</a> | ||
| </div> | ||
| <br> | ||
| <div> | ||
| <label for="faculty">Select a faculty :</label> | ||
| <select name="faculty" id="faculty"> | ||
| @foreach ($faculties as $faculty) | ||
| <option value="{{$faculty->id}}">{{$faculty->id}} {{$faculty->name}}</option> | ||
| @endforeach | ||
| </select> | ||
| </div> | ||
| <br> | ||
| <div> | ||
| <label for="classroom">Select a classroom :</label> | ||
| <select name="classroom" id="classroom"> | ||
| @foreach ($classrooms as $classroom) | ||
| <option value="{{$classroom->id}}">{{$classroom->degree_type}} Semester {{$classroom->semester}} {{$classroom->department_code}}</option> | ||
| @endforeach | ||
| </select> | ||
| </div> | ||
| <br> | ||
| <div> | ||
| <label for="type">Select Couse Type :</label> | ||
| <select name="type" id="type"> | ||
| @foreach ($types as $type) | ||
| <option value="{{$type}}">{{$type}} </option> | ||
| @endforeach | ||
| </select> | ||
| </div> | ||
| <br> | ||
| <div> | ||
| <button>Create Course</button> | ||
| </div> | ||
| </form> | ||
| @endsection |
Uh oh!
There was an error while loading. Please reload this page.