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

59 lines
1.8 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') {
2019-12-04 10:21:58 +01:00
$user_id = Auth::id();
$subjects = Subject::where('user_id', $user_id)->orderBy('name','ASC')->get();
2019-12-01 23:36:12 +01:00
$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'];
$defaultTime = date("H:i");
2019-12-15 12:43:40 +01:00
if(date('w')-1 < 0 ) {
$defaultWeekday = $weekdays[6];
} else {
$defaultWeekday = $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
]);
return redirect()->back();
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();
return redirect()->back();
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);
return redirect()->back();
2019-12-01 23:36:12 +01:00
}
}