Added show scores + some fixes
This commit is contained in:
parent
c269765c39
commit
25d3463182
14
app/Enums/ScoreEnum.php
Normal file
14
app/Enums/ScoreEnum.php
Normal 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 = 'Б';
|
||||||
|
}
|
@ -2,9 +2,24 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use App\Enums\ScoreEnum;
|
||||||
|
use App\Models\Lesson;
|
||||||
|
use App\Services\ServiceInterface;
|
||||||
|
|
||||||
class ScoreController extends Controller
|
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(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ class Lesson extends Model
|
|||||||
|
|
||||||
public function students(): BelongsToMany
|
public function students(): BelongsToMany
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(Student::class);
|
return $this->belongsToMany(Student::class)->withPivot('score');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeFilter(Builder $query): void
|
public function scopeFilter(Builder $query): void
|
||||||
|
@ -39,7 +39,7 @@ class Student extends Model
|
|||||||
|
|
||||||
public function lessons(): BelongsToMany
|
public function lessons(): BelongsToMany
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(Lesson::class)->withPivot('score');
|
return $this->belongsToMany(Lesson::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scopeFilter(Builder $query): void
|
public function scopeFilter(Builder $query): void
|
||||||
|
@ -6,6 +6,7 @@ use App\Http\Controllers\GradeController;
|
|||||||
use App\Http\Controllers\GradeSubjectController;
|
use App\Http\Controllers\GradeSubjectController;
|
||||||
use App\Http\Controllers\GradeTeacherController;
|
use App\Http\Controllers\GradeTeacherController;
|
||||||
use App\Http\Controllers\LessonController;
|
use App\Http\Controllers\LessonController;
|
||||||
|
use App\Http\Controllers\ScoreController;
|
||||||
use App\Http\Controllers\StudentController;
|
use App\Http\Controllers\StudentController;
|
||||||
use App\Http\Controllers\SubjectController;
|
use App\Http\Controllers\SubjectController;
|
||||||
use App\Http\Controllers\SubjectTeacherController;
|
use App\Http\Controllers\SubjectTeacherController;
|
||||||
@ -14,6 +15,7 @@ use App\Services\GradeService;
|
|||||||
use App\Services\GradeSubjectService;
|
use App\Services\GradeSubjectService;
|
||||||
use App\Services\GradeTeacherService;
|
use App\Services\GradeTeacherService;
|
||||||
use App\Services\LessonService;
|
use App\Services\LessonService;
|
||||||
|
use App\Services\ScoreService;
|
||||||
use App\Services\ServiceInterface;
|
use App\Services\ServiceInterface;
|
||||||
use App\Services\StudentService;
|
use App\Services\StudentService;
|
||||||
use App\Services\SubjectService;
|
use App\Services\SubjectService;
|
||||||
@ -75,6 +77,13 @@ class ModelServiceProvider extends ServiceProvider
|
|||||||
->give(function () {
|
->give(function () {
|
||||||
return new LessonService();
|
return new LessonService();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$this->app->when(ScoreController::class)
|
||||||
|
->needs(ServiceInterface::class)
|
||||||
|
->give(function () {
|
||||||
|
return new ScoreService();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer">
|
<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>
|
<a href="{{ route('grades.lessons.edit', [$grade, $lesson]) }}" class="btn btn-primary">Редактировать</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
53
resources/views/scores/show.blade.php
Normal file
53
resources/views/scores/show.blade.php
Normal 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
|
@ -31,7 +31,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td class="table-text">
|
<td class="table-text">
|
||||||
<div>
|
<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>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -4,6 +4,7 @@ use App\Http\Controllers\GradeController;
|
|||||||
use App\Http\Controllers\GradeSubjectController;
|
use App\Http\Controllers\GradeSubjectController;
|
||||||
use App\Http\Controllers\GradeTeacherController;
|
use App\Http\Controllers\GradeTeacherController;
|
||||||
use App\Http\Controllers\LessonController;
|
use App\Http\Controllers\LessonController;
|
||||||
|
use App\Http\Controllers\ScoreController;
|
||||||
use App\Http\Controllers\StudentController;
|
use App\Http\Controllers\StudentController;
|
||||||
use App\Http\Controllers\SubjectController;
|
use App\Http\Controllers\SubjectController;
|
||||||
use App\Http\Controllers\SubjectTeacherController;
|
use App\Http\Controllers\SubjectTeacherController;
|
||||||
@ -25,4 +26,5 @@ Route::resources([
|
|||||||
Route::resource('teachers.subjects', SubjectTeacherController::class)->except('index');
|
Route::resource('teachers.subjects', SubjectTeacherController::class)->except('index');
|
||||||
Route::resource('teachers.subjects.grades', GradeTeacherController::class)->except('index', 'show');
|
Route::resource('teachers.subjects.grades', GradeTeacherController::class)->except('index', 'show');
|
||||||
Route::resource('grades.subjects', GradeSubjectController::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');
|
||||||
|
Loading…
Reference in New Issue
Block a user