56 lines
1.8 KiB
PHP
56 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\User;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\User;
|
|
use App\Subject;
|
|
use App\Room;
|
|
|
|
class UserSubjectsController extends Controller
|
|
{
|
|
public function index($user_id, $groupBy)
|
|
{
|
|
$subjects = Subject::where('user_id', $user_id)->get();
|
|
$subjects_grouped = $subjects->groupBy($groupBy);
|
|
$rooms = Room::all();
|
|
$weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
|
|
$types = ['Lecture', 'Excercises', 'Labs', 'Other'];
|
|
return view('user.user_subjects', ['subjects' => $subjects, 'rooms' => $rooms, 'weekdays' => $weekdays,
|
|
'types' => $types, 'subjects_grouped' => $subjects_grouped, 'grouped_by' => $groupBy]);
|
|
}
|
|
|
|
public function add_subject($user_id, Request $request)
|
|
{
|
|
$name = $request->input('name');
|
|
$type = $request->input('type');
|
|
$weekday = $request->input('weekday');
|
|
$time = $request->input('time');
|
|
$room_id = $request->input('room_id');
|
|
$user_id_n = $user_id;
|
|
Subject::create([
|
|
'name' => $name,
|
|
'type' => $type,
|
|
'weekday'=> $weekday,
|
|
'time' => $time,
|
|
'room_id' => $room_id,
|
|
'user_id' => $user_id_n
|
|
]);
|
|
return redirect(route('user_subjects', [$user_id, 'weekday']));
|
|
}
|
|
|
|
public function delete_subject($user_id, $subject_id, $groupBy)
|
|
{
|
|
Subject::find($subject_id)->delete();
|
|
return redirect(route('user_subjects', [$user_id, $groupBy]));
|
|
}
|
|
|
|
public function edit_subject($user_id, $subject_id, $groupBy)
|
|
{
|
|
Subject::find($subject_id);
|
|
return redirect(route('user_subjects', [$user_id, $groupBy]));
|
|
}
|
|
}
|