2019-12-01 23:36:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\User;
|
|
|
|
|
2019-12-04 16:55:59 +01:00
|
|
|
use App\Attendance;
|
2019-12-01 23:36:12 +01:00
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
use App\Subject;
|
|
|
|
use App\Classes;
|
2019-12-04 16:55:59 +01:00
|
|
|
use App\Room;
|
|
|
|
|
2019-12-04 10:21:58 +01:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2019-12-06 22:34:25 +01:00
|
|
|
use Illuminate\Support\Facades\Session;
|
2019-12-01 23:36:12 +01:00
|
|
|
|
|
|
|
class UserClassesController extends Controller
|
|
|
|
{
|
2019-12-06 22:34:25 +01:00
|
|
|
public function index($groupBy='subject_id')
|
2019-12-01 23:36:12 +01:00
|
|
|
{
|
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_ids = $subjects->pluck('id')->toArray();
|
|
|
|
$classes = Classes::whereIn('subject_id', $subjects_ids)->get();
|
|
|
|
$classes_grouped = $classes->groupBy($groupBy);
|
2019-12-06 22:34:25 +01:00
|
|
|
$defaultDate = date("Y-m-d");
|
|
|
|
return view('user.user_classes', ['classes' => $classes, 'classes_grouped' => $classes_grouped, 'subjects' => $subjects, 'grouped_by' => $groupBy, 'defaultDate' => $defaultDate]);
|
2019-12-01 23:36:12 +01:00
|
|
|
}
|
|
|
|
|
2019-12-04 10:21:58 +01:00
|
|
|
public function add_classes(Request $request)
|
2019-12-01 23:36:12 +01:00
|
|
|
{
|
|
|
|
$subject_id = $request->input('subject_id');
|
|
|
|
$date = $request->input('date');
|
|
|
|
Classes::create([
|
|
|
|
'subject_id' => $subject_id,
|
|
|
|
'date' => $date
|
|
|
|
]);
|
2019-12-06 22:34:25 +01:00
|
|
|
$classes_id = Classes::orderBy('created_at', 'desc')->first()->id;
|
|
|
|
return redirect(route('user_start_classes', ['classes_id' => $classes_id]));
|
2019-12-01 23:36:12 +01:00
|
|
|
}
|
|
|
|
|
2019-12-04 10:21:58 +01:00
|
|
|
public function delete_classes($classes_id)
|
2019-12-01 23:36:12 +01:00
|
|
|
{
|
|
|
|
Classes::find($classes_id)->delete();
|
2019-12-04 10:21:58 +01:00
|
|
|
return redirect(route('user_classes'));
|
2019-12-01 23:36:12 +01:00
|
|
|
}
|
|
|
|
|
2019-12-04 10:21:58 +01:00
|
|
|
public function edit_classes($classes_id)
|
2019-12-01 23:36:12 +01:00
|
|
|
{
|
|
|
|
Classes::find($classes_id);
|
2019-12-04 10:21:58 +01:00
|
|
|
return redirect(route('user_classes'));
|
2019-12-01 23:36:12 +01:00
|
|
|
}
|
2019-12-04 16:55:59 +01:00
|
|
|
|
|
|
|
public function start_classes($classes_id)
|
|
|
|
{
|
|
|
|
$classes_code = generateRandomString(10);
|
|
|
|
session([
|
|
|
|
'CLASSES_CODE' => $classes_code,
|
|
|
|
'CLASSES_ID' => $classes_id
|
|
|
|
]);
|
2019-12-06 22:34:25 +01:00
|
|
|
$classes = Classes::find($classes_id);
|
|
|
|
return view('user.user_classes_start', ['verified' => false, 'classes_code' => $classes_code, 'classes' => $classes]);
|
2019-12-04 16:55:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function start_classes_verified(Request $request)
|
|
|
|
{
|
|
|
|
$classes = Classes::find($request->get('classes_id'));
|
|
|
|
$room = Room::find(Subject::find($classes->subject_id)->room_id)->name;
|
|
|
|
$student_id_number = $request->input('student_id_number');
|
|
|
|
$student_name = $request->input('student_name');
|
|
|
|
$student_surname = $request->input('student_surname');
|
|
|
|
$seat_number = $request->input('seat_number');
|
|
|
|
Attendance::create([
|
|
|
|
'classes_id' => $classes->id,
|
|
|
|
'student_id_number' => $student_id_number,
|
|
|
|
'student_name' => $student_name,
|
|
|
|
'student_surname' => $student_surname,
|
|
|
|
'seat_number' => $seat_number,
|
|
|
|
]);
|
|
|
|
$attendances = Attendance::where('classes_id', $classes->id)->get();
|
|
|
|
return view('user.user_classes_start', ['verified' => true, 'room' => $room, 'attendances' => $attendances]);
|
|
|
|
}
|
2019-12-01 23:36:12 +01:00
|
|
|
}
|