academico-sis /
academico
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Http\Controllers; |
||
| 4 | |||
| 5 | use App\Models\Course; |
||
| 6 | use App\Models\Room; |
||
| 7 | use App\Models\Teacher; |
||
| 8 | use Illuminate\Http\Request; |
||
| 9 | use Illuminate\Support\Facades\Log; |
||
| 10 | |||
| 11 | class EventController extends Controller |
||
| 12 | { |
||
| 13 | public function __construct() |
||
| 14 | { |
||
| 15 | parent::__construct(); |
||
| 16 | $this->middleware('permission:courses.view'); |
||
| 17 | $this->middleware('permission:courses.edit', ['only' => ['syncEventsTeacher', 'update_course_teacher', 'update_course_room', 'syncEventsRoom', 'store', 'destroy']]); |
||
| 18 | } |
||
| 19 | |||
| 20 | /** |
||
| 21 | * get all events for a course. |
||
| 22 | */ |
||
| 23 | public function getCourseEvents($course) |
||
| 24 | { |
||
| 25 | $this->middleware(['permission:courses.view']); |
||
| 26 | |||
| 27 | return Course::findOrFail($course)->events; |
||
| 28 | } |
||
| 29 | |||
| 30 | public function update_course_teacher(Request $request) |
||
| 31 | { |
||
| 32 | Log::notice('Calendar events updated by user '.backpack_user()->id); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 33 | $course = Course::findOrFail($request->input('course_id')); |
||
| 34 | if ($request->input('resource_id') == 'tbd') { |
||
| 35 | $teacher_id = null; |
||
| 36 | } else { |
||
| 37 | $teacher_id = Teacher::findOrFail($request->input('resource_id'))->id; |
||
| 38 | } |
||
| 39 | |||
| 40 | $course->teacher_id = $teacher_id; |
||
| 41 | $course->save(); |
||
| 42 | $course->events()->update(['teacher_id' => $teacher_id]); |
||
| 43 | |||
| 44 | // if the course has a parent, update the children of the parent as well. |
||
| 45 | if ($course->parent_course_id !== null) { |
||
| 46 | $parent = Course::find($course->parent_course_id); |
||
| 47 | $parent->teacher_id = $teacher_id; |
||
| 48 | foreach ($parent->children as $child) { |
||
| 49 | $child->events()->update(['teacher_id' => $teacher_id]); |
||
| 50 | } |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | public function update_course_room(Request $request) |
||
| 55 | { |
||
| 56 | Log::notice('Calendar events updated by user '.backpack_user()->id); |
||
|
0 ignored issues
–
show
|
|||
| 57 | |||
| 58 | $course = Course::findOrFail($request->input('course_id')); |
||
| 59 | if ($request->input('resource_id') == 'tbd') { |
||
| 60 | $room_id = null; |
||
| 61 | } else { |
||
| 62 | $room_id = Room::findOrFail($request->input('resource_id'))->id; |
||
| 63 | } |
||
| 64 | |||
| 65 | $course->room_id = $room_id; |
||
| 66 | $course->save(); |
||
| 67 | $course->events()->update(['room_id' => $room_id]); |
||
| 68 | // if the course has a parent, update the children of the parent as well. |
||
| 69 | if ($course->parent_course_id !== null) { |
||
| 70 | $parent = Course::find($course->parent_course_id); |
||
| 71 | $parent->room_id = $room_id; |
||
| 72 | foreach ($parent->children as $child) { |
||
| 73 | $child->events()->update(['room_id' => $room_id]); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } |
||
| 77 | } |
||
| 78 |