Skip to content
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

Subject Management #55

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Contributing.MD
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Table of contents

- [Standard of Code](#standard-of-code)
- [Laravel Best Practices ](https://github.com/alexeymezenin/laravel-best-practices)
- [Initial Setup](#initial-setup-and-credentials)
- [Running shell commands inside container](#running-shell-commands-inside-the-container)
- [Installing PHP Packages](#installing-php-packages)
Expand Down
4 changes: 3 additions & 1 deletion src/app/Http/Controllers/AttendanceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ public function index(AttendanceRequest $request)
// HOD can view their dept
// Staff advisor, Faculty can view their class
$request->validated();
print $request->ip();

$auth_user = Auth::user();
$faculty = $auth_user->faculty;
// print $auth_user;
if ($auth_user->isAdmin() || $faculty?->isPrincipal()) {
// OR Principal
$query = Attendance::getBaseQuery($request->get("from"), $request->get("to"));
Expand Down Expand Up @@ -258,7 +260,7 @@ public function update(AttendanceRequest $request, $attendance_id)
}
$absentee->leave_excuse = $leave_type;

// TODO Bulk update is possible?
// TODO Bulk update is <po></po>ssible?
$absentee->save();
}

Expand Down
137 changes: 137 additions & 0 deletions src/app/Http/Controllers/CourseController.php
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Classroom, Subject okke lower case alle vende

// 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();
Copy link
Member

Choose a reason for hiding this comment

The 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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use find to get by id. Classroom::find($data["classroom"])->semester

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do course need a semester as it is always linked to classroom?

Copy link
Member

Choose a reason for hiding this comment

The 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.
But an obvious reason for semester is Minor courses. They don't have a particular classroom.

Maybe we could make semester null for other courses, and add a getter getSemester() to Course model, which will either get from classroom or from the semester field.

$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 ?
Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should all fields be updatable?
Faculty is ok, because they can be changed in between.
But subject, classroom and course_type?

$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');
}
}
122 changes: 122 additions & 0 deletions src/app/Http/Controllers/SubjectController.php
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Admin can create subjects. They may no be a faculty.
Checkout faculty.store, where I encountered a similar situation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The 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');

}
}
4 changes: 3 additions & 1 deletion src/app/Models/Subject.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Subject extends Model

protected $fillable = [
'name',
'credit'
'credits'
];

protected function courses()
Expand All @@ -29,4 +29,6 @@ protected function department()
{
return $this->hasOne(Department::class);
}


}
1 change: 0 additions & 1 deletion src/resources/views/attendance/index.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@extends("layouts.layout")

@section("head")
<script>
function deleteAttendance(url){
Expand Down
49 changes: 49 additions & 0 deletions src/resources/views/courses/create.blade.php
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
Loading