atcheck/app/Http/Controllers/User/UserSubjectsController.php

61 lines
2.0 KiB
PHP
Raw Normal View History

2019-12-01 23:36:12 +01:00
<?php
namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
2019-12-04 10:21:58 +01:00
use Illuminate\Support\Facades\Auth;
2019-12-01 23:36:12 +01:00
use App\Subject;
use App\Room;
class UserSubjectsController extends Controller
{
2019-12-16 15:45:28 +01:00
public function index($groupBy = 'weekday') {
setlocale(LC_ALL, 'pl', 'pl_PL', 'pl_PL.ISO8859-2', 'plk', 'polish', 'Polish');
2019-12-04 10:21:58 +01:00
$user_id = Auth::id();
2019-12-01 23:36:12 +01:00
$subjects = Subject::where('user_id', $user_id)->get();
$subjects_grouped = $subjects->groupBy($groupBy);
2019-12-09 12:17:23 +01:00
$rooms = Room::all();
$weekdays = ['Poniedziałek', 'Wtorek', 'Środa', 'Czwartek', 'Piątek', 'Sobota', 'Niedziela'];
// $types = ['Lecture', 'Excercises', 'Labs', 'Other'];
$defaultTime = date("H:i");
2019-12-15 12:43:40 +01:00
if(date('w')-1 < 0 ) {
$defaultWeekday = $weekdays[6];
} else {
$defaultWeekday = "Poniedziałek";//$weekdays[date('w') - 1];
2019-12-15 12:43:40 +01:00
}
2019-12-16 15:45:28 +01:00
return view('user.user_subjects', ['subjects' => $subjects, 'weekdays' => $weekdays, 'subjects_grouped' => $subjects_grouped, 'grouped_by' => $groupBy, 'defaultTime' => $defaultTime, 'defaultWeekday' => $defaultWeekday, 'rooms' => $rooms]);
2019-12-01 23:36:12 +01:00
}
2019-12-16 15:45:28 +01:00
public function add_subject(Request $request) {
2019-12-01 23:36:12 +01:00
$name = $request->input('name');
// $type = $request->input('type');
2019-12-01 23:36:12 +01:00
$weekday = $request->input('weekday');
$time = $request->input('time');
2019-12-09 12:17:23 +01:00
$room_id = $request->input('room_id');
2019-12-04 10:21:58 +01:00
$user_id_n = Auth::id();
2019-12-01 23:36:12 +01:00
Subject::create([
'name' => $name,
// 'type' => $type,
2019-12-01 23:36:12 +01:00
'weekday'=> $weekday,
'time' => $time,
2019-12-09 12:17:23 +01:00
'room_id' => $room_id,
2019-12-01 23:36:12 +01:00
'user_id' => $user_id_n
]);
2019-12-04 10:21:58 +01:00
return redirect(route('user_subjects'));
2019-12-01 23:36:12 +01:00
}
2019-12-04 10:21:58 +01:00
public function delete_subject($subject_id)
2019-12-01 23:36:12 +01:00
{
Subject::find($subject_id)->delete();
2019-12-04 10:21:58 +01:00
return redirect(route('user_subjects'));
2019-12-01 23:36:12 +01:00
}
2019-12-04 10:21:58 +01:00
public function edit_subject($subject_id)
2019-12-01 23:36:12 +01:00
{
Subject::find($subject_id);
2019-12-04 10:21:58 +01:00
return redirect(route('user_subjects'));
2019-12-01 23:36:12 +01:00
}
}