prod #14

Merged
klllst merged 24 commits from develop into master 2024-06-25 21:58:29 +04:00
6 changed files with 76 additions and 1 deletions
Showing only changes of commit 733bb76122 - Show all commits

View File

@ -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();
}
}

View File

@ -52,4 +52,9 @@ class StudentPolicy
{
return $user->userable_type == Student::class;
}
public function avgScores(User $user): bool
{
return $user->userable_type == Student::class;
}
}

View File

@ -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');
}
}

View 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>

View File

@ -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">

View File

@ -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');
});
});