-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathAssignedTeacherController.php
99 lines (84 loc) · 2.59 KB
/
AssignedTeacherController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace App\Http\Controllers;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use App\Traits\SchoolSession;
use App\Interfaces\SemesterInterface;
use App\Interfaces\SchoolSessionInterface;
use App\Http\Requests\TeacherAssignRequest;
use App\Repositories\AssignedTeacherRepository;
class AssignedTeacherController extends Controller
{
use SchoolSession;
protected $semesterRepository;
/**
* Create a new Controller instance
*
* @param SchoolSessionInterface $schoolSessionRepository
* @return void
*/
public function __construct(SemesterInterface $semesterRepository) {
$this->semesterRepository = $semesterRepository;
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* @param Request $request
* @return Application|Factory|View
*/
public function getTeacherCourses(Request $request)
{
$courses = [];
$teacherId = $request->query('teacher_id');
$semesterId = $request->query('semester_id');
if (is_null($teacherId)) {
abort(404);
}
$currentSchoolSessionId = $this->getSchoolCurrentSession();
$semesters = $this->semesterRepository->getAll($currentSchoolSessionId);
$assignedTeacherRepository = new AssignedTeacherRepository();
if (!is_null($semesterId)) {
$courses = $assignedTeacherRepository->getTeacherCourses($currentSchoolSessionId, $teacherId, $semesterId);
}
return view('courses.teacher')
->with([
'courses' => $courses,
'semesters' => $semesters,
'selected_semester_id' => $semesterId
]);
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param TeacherAssignRequest $request
* @return \Illuminate\Http\Response
*/
public function store(TeacherAssignRequest $request)
{
try {
$assignedTeacherRepository = new AssignedTeacherRepository();
$assignedTeacherRepository->assign($request->validated());
return back()->with('status', 'Assigning teacher was successful!');
} catch (\Exception $e) {
return back()->withError($e->getMessage());
}
}
}