54 lines
1.9 KiB
PHP
54 lines
1.9 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers\User;
|
||
|
|
||
|
use App\Http\Controllers\Controller;
|
||
|
use Illuminate\Http\Request;
|
||
|
|
||
|
use App\Subject;
|
||
|
use App\Classes;
|
||
|
use App\Attendance;
|
||
|
|
||
|
class UserAttendancesController extends Controller
|
||
|
{
|
||
|
public function index($user_id, $groupBy)
|
||
|
{
|
||
|
$subjects = Subject::where('user_id', $user_id)->get();
|
||
|
$subjects_ids = $subjects->pluck('id')->toArray();
|
||
|
$classes = Classes::whereIn('subject_id', $subjects_ids)->get();
|
||
|
$classes_ids = $classes->pluck('id')->toArray();
|
||
|
$attendances = Attendance::whereIn('classes_id', $classes_ids)->get();
|
||
|
$attendances_grouped = $attendances->groupBy($groupBy);
|
||
|
return view('user.user_attendances', ['attendances' => $attendances, 'attendances_grouped' => $attendances_grouped, 'classes' => $classes, 'grouped_by' => $groupBy]);
|
||
|
}
|
||
|
|
||
|
public function add_attendance($user_id, Request $request)
|
||
|
{
|
||
|
$classes_id = $request->input('classes_id');
|
||
|
$student_id_number = $request->input('student_id');
|
||
|
$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,
|
||
|
]);
|
||
|
return redirect(route('user_attendances', [$user_id, 'classes_id']));
|
||
|
}
|
||
|
|
||
|
public function delete_attendance($user_id, $attendance_id, $groupBy)
|
||
|
{
|
||
|
Attendance::find($attendance_id)->delete();
|
||
|
return redirect(route('user_attendances', [$user_id, $groupBy]));
|
||
|
}
|
||
|
|
||
|
public function edit_attendance($user_id, $attendance_id, $groupBy)
|
||
|
{
|
||
|
Attendance::find($attendance_id);
|
||
|
return redirect(route('user_attendances', [$user_id, $groupBy]));
|
||
|
}
|
||
|
}
|