prod #14
@ -6,6 +6,7 @@ use App\Http\Requests\StudentPostRequest;
|
||||
use App\Models\Grade;
|
||||
use App\Models\Student;
|
||||
use App\Models\Subject;
|
||||
use App\Services\FileService;
|
||||
use App\Services\StudentService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\View\View;
|
||||
@ -134,4 +135,9 @@ class StudentController extends Controller
|
||||
'lessons' => $service->getDebts(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function exportAvgScores(StudentService $service)
|
||||
{
|
||||
return $service->exportAvgScores();
|
||||
}
|
||||
}
|
||||
|
@ -52,4 +52,9 @@ class StudentPolicy
|
||||
{
|
||||
return $user->userable_type == Student::class;
|
||||
}
|
||||
|
||||
public function avgScores(User $user): bool
|
||||
{
|
||||
return $user->userable_type == Student::class;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ use App\Enums\ScoreEnum;
|
||||
use App\Models\Student;
|
||||
use App\Models\Subject;
|
||||
use App\Models\User;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@ -82,4 +83,18 @@ class StudentService
|
||||
|
||||
return $student->lessons()->whereIn('score', ScoreEnum::getDebtScores())->get();
|
||||
}
|
||||
|
||||
public function exportAvgScores()
|
||||
{
|
||||
$subjects = Auth::user()->userable->grade->subjects;
|
||||
$avgScores = collect();
|
||||
|
||||
$subjects->each(function ($subject) use ($avgScores) {
|
||||
$avgScores->put($subject->name, $this->getAvgScore($subject));
|
||||
});
|
||||
|
||||
return Pdf::loadView('students.avg-scores', [
|
||||
'avgScores' => $avgScores,
|
||||
])->download('Успеваемость.pdf');
|
||||
}
|
||||
}
|
||||
|
43
resources/views/students/avg-scores.blade.php
Normal file
43
resources/views/students/avg-scores.blade.php
Normal file
@ -0,0 +1,43 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<style>
|
||||
* { font-family: DejaVu Sans !important; }
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
table, th, td {
|
||||
border: 1px solid black;
|
||||
}
|
||||
th, td {
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
th {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
</style>
|
||||
<title>Успеваемость ученика</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Информация об успеваемости</h1>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Предмет</th>
|
||||
<th>Средняя оценка</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($avgScores as $key => $item)
|
||||
<tr>
|
||||
<td>{{ $key }}</td>
|
||||
<td>{{ $item }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
@ -18,7 +18,12 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="card mt-4">
|
||||
<div class="card-header">{{__('Предметы')}}</div>
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
{{__('Предметы')}}
|
||||
@can('avgScores', \App\Models\Student::class)
|
||||
<a href="{{ route('export-avg-scores') }}" class="btn btn-primary">Успеваемость</a>
|
||||
@endcan
|
||||
</div>
|
||||
<div class="card-body">
|
||||
@if (count($subjects))
|
||||
<table class="table table-striped">
|
||||
|
@ -54,6 +54,7 @@ Route::middleware('auth')->group(function () {
|
||||
Route::get('subjects/{subject}/student-scores', [StudentController::class, 'scores'])->name('student-scores');
|
||||
Route::get('student-debts', [StudentController::class, 'debts'])->name('student-debts');
|
||||
Route::get('teachers/{teacher}/subjects', [SubjectTeacherController::class, 'index'])->name('teachers.subjects.index');
|
||||
Route::get('export-avg-scores', [StudentController::class, 'exportAvgScores'])->name('export-avg-scores');
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user