Added show scores + some fixes

This commit is contained in:
m.zargarov 2024-05-17 18:46:12 +04:00
parent c269765c39
commit 25d3463182
9 changed files with 100 additions and 7 deletions

14
app/Enums/ScoreEnum.php Normal file
View File

@ -0,0 +1,14 @@
<?php
namespace App\Enums;
enum ScoreEnum: string
{
case One = '1';
case Two = '2';
case Three = '3';
case Four = '4';
case Five = '5';
case Absent = 'Н';
case Sick = 'Б';
}

View File

@ -2,9 +2,24 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Enums\ScoreEnum;
use App\Models\Lesson;
use App\Services\ServiceInterface;
class ScoreController extends Controller
{
//
public function __construct(
protected ServiceInterface $service,
){
}
public function show(Lesson $lesson)
{
return view('scores.show', [
'students' => $this->service->getAll($lesson),
'lesson' => $lesson,
'scores' => ScoreEnum::cases(),
]);
}
}

View File

@ -45,7 +45,7 @@ class Lesson extends Model
public function students(): BelongsToMany
{
return $this->belongsToMany(Student::class);
return $this->belongsToMany(Student::class)->withPivot('score');
}
public function scopeFilter(Builder $query): void

View File

@ -39,7 +39,7 @@ class Student extends Model
public function lessons(): BelongsToMany
{
return $this->belongsToMany(Lesson::class)->withPivot('score');
return $this->belongsToMany(Lesson::class);
}
public function scopeFilter(Builder $query): void

View File

@ -6,6 +6,7 @@ use App\Http\Controllers\GradeController;
use App\Http\Controllers\GradeSubjectController;
use App\Http\Controllers\GradeTeacherController;
use App\Http\Controllers\LessonController;
use App\Http\Controllers\ScoreController;
use App\Http\Controllers\StudentController;
use App\Http\Controllers\SubjectController;
use App\Http\Controllers\SubjectTeacherController;
@ -14,6 +15,7 @@ use App\Services\GradeService;
use App\Services\GradeSubjectService;
use App\Services\GradeTeacherService;
use App\Services\LessonService;
use App\Services\ScoreService;
use App\Services\ServiceInterface;
use App\Services\StudentService;
use App\Services\SubjectService;
@ -75,6 +77,13 @@ class ModelServiceProvider extends ServiceProvider
->give(function () {
return new LessonService();
});
$this->app->when(ScoreController::class)
->needs(ServiceInterface::class)
->give(function () {
return new ScoreService();
});
}
/**

View File

@ -20,7 +20,7 @@
</div>
</div>
<div class="card-footer">
<a href="{{ route('lessons.students.index', $lesson) }}" class="btn btn-success">Оценки</a>
<a href="{{ route('lessons.scores.show', $lesson) }}" class="btn btn-success">Оценки</a>
<a href="{{ route('grades.lessons.edit', [$grade, $lesson]) }}" class="btn btn-primary">Редактировать</a>
</div>
</div>

View File

@ -0,0 +1,53 @@
@extends('layouts.app')
@section('content')
<div class="container col-md-4">
<div class="row justify-content-center">
<div class="card mt-4">
<div class="card-header">
<p>{{ $lesson->name }}</p>
</div>
<div class="card-body">
<form action="{{ route('lessons.scores.update', [$lesson]) }}" method="POST">
@csrf
@method('PUT')
@if(count($students))
<table class="table table-striped">
<thead>
<th>ФИО</th>
<th>Оценка</th>
</thead>
<tbody>
@foreach ($students as $student)
<tr>
<td class="table-text">
<div>
<p>{{ $student->fio }}</p>
</div>
</td>
<td>
<div>
<select id="score" name="score" class="form-select form-select-sm" required>
<option value="">Нет оценки</option>
@foreach($scores as $score)
<option value="{{ $score }}" {{ isset($student->pivot->score) && $student->pivot->score == $score ? 'selected' : '' }}>
{{ $score }}
</option>
@endforeach
</select>
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
@else
<p>Ученики остутствуют</p>
@endif
<button type="submit" class="btn btn-success">Подтвердить</button>
</form>
</div>
</div>
</div>
</div>
@endsection

View File

@ -31,7 +31,7 @@
<tr>
<td class="table-text">
<div>
<a href="{{ route('students.show', $student) }}" class="btn btn-block col-8">{{ $student->last_name }} {{ $student->name }} {{ $student->middle_name }}</a>
<a href="{{ route('students.show', $student) }}" class="btn btn-block col-8">{{ $student->fio }}</a>
</div>
</td>
<td>

View File

@ -4,6 +4,7 @@ use App\Http\Controllers\GradeController;
use App\Http\Controllers\GradeSubjectController;
use App\Http\Controllers\GradeTeacherController;
use App\Http\Controllers\LessonController;
use App\Http\Controllers\ScoreController;
use App\Http\Controllers\StudentController;
use App\Http\Controllers\SubjectController;
use App\Http\Controllers\SubjectTeacherController;
@ -25,4 +26,5 @@ Route::resources([
Route::resource('teachers.subjects', SubjectTeacherController::class)->except('index');
Route::resource('teachers.subjects.grades', GradeTeacherController::class)->except('index', 'show');
Route::resource('grades.subjects', GradeSubjectController::class)->except('index', 'show');
Route::resource('lessons.students', ScoreController::class)->except('show');
Route::get('lessons/{lesson}/scores', [ScoreController::class, 'show'])->name('lessons.scores.show');
Route::put('lessons/{lesson}/scores', [ScoreController::class, 'update'])->name('lessons.scores.update');