Task-10 (Journal) #11

Merged
klllst merged 7 commits from feature/task-10 into develop 2024-06-23 17:03:05 +04:00
5 changed files with 89 additions and 20 deletions
Showing only changes of commit 24b5683090 - Show all commits

View File

@ -5,7 +5,7 @@ namespace App\Http\Controllers;
use App\Http\Requests\GradeSubjectPostRequest;
use App\Models\Grade;
use App\Models\Subject;
use App\Services\ServiceInterface;
use App\Services\JournalService;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;
@ -26,27 +26,18 @@ class GradeSubjectController extends Controller
return redirect()->route('grades.show', $grade);
}
public function edit(Grade $grade, Subject $subject): View
{
return view('grade-subject.edit', [
'grade' => $grade,
'updateSubject' => $subject,
'subjects' => Subject::all(),
]);
}
public function update(GradeSubjectPostRequest $request, Grade $grade, Subject $subject): RedirectResponse
{
$grade->subjects()->detach($subject);
$grade->subjects()->attach($request->subject_id);
return redirect()->route('grades.show', $grade);
}
public function destroy(Grade $grade, Subject $subject): RedirectResponse
{
$grade->subjects()->detach($subject);
return redirect()->route('grades.show', $grade);
}
public function journal(Grade $grade, Subject $subject, JournalService $service): View
{
return view('grade-subject.journal', [
'lessons' => $grade->lessons()->where('subject_id', $subject->id)->with('students')->get(),
'students' => $grade->students()->orderBy('last_name')->get(),
]);
}
}

View File

@ -0,0 +1,19 @@
<?php
namespace App\Services;
use App\Models\Grade;
use App\Models\Subject;
use Illuminate\Support\Facades\DB;
class JournalService
{
public function getLessons(Grade $grade, Subject $subject)
{
return DB::table('lessons')
->where('grade_id', $grade->id)
->where('subject_id', $subject->id)
->orderBy('lesson_date')
->get();
}
}

View File

@ -0,0 +1,57 @@
@extends('layouts.application')
@section('content')
<div class="container col-md-8">
<div class="row justify-content-center">
@if (count($students))
<div class="card mt-4">
<div class="card-header">{{__('Журнал')}}</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th scope="col">ФИО</th>
@foreach ($lessons as $lesson)
<th scope="col">{{ $lesson->lesson_date }}</th>
@endforeach
</tr>
<tr>
<th scope="col"></th>
@foreach ($lessons as $lesson)
<th scope="col">{{ $lesson->type }}</th>
@endforeach
</tr>
</thead>
<tbody>
@foreach ($students as $student)
<tr>
<td> {{ $student->fio }}</td>
@foreach ($lessons as $lesson)
<td style="text-align: center; vertical-align: middle;">
{{ $student->lessons->find($lesson->id)->pivot->score ?? "-" }}
</td>
@endforeach
</tr>
@endforeach
{{-- <tr>--}}
{{-- <td>Средняя оценка</td>--}}
{{-- @foreach ($avgScores as $avgScore)--}}
{{-- <td style="text-align: center; vertical-align: middle;">--}}
{{-- {{ $avgScore ? $avgScore : "" }}--}}
{{-- </td>--}}
{{-- @endforeach--}}
{{-- </tr>--}}
</tbody>
</table>
</div>
</div>
</div>
{{-- <div class="mt-4">--}}
{{-- @include('journals.list', ['users' => $goods, 'studentName' => 'хорошистов'])--}}
{{-- @include('journals.list', ['users' => $perfects, 'studentName' => 'отличников'])--}}
{{-- </div>--}}
@endif
</div>
</div>
@endsection

View File

@ -35,7 +35,7 @@
</td>
<td>
<div>
<a href="{{ route('grades.subjects.edit', [$grade, $subject]) }}" class="btn btn-warning">Редактировать</a>
<a href="{{ route('grades.subjects.journal', [$grade, $subject]) }}" class="btn btn-primary">Журнал</a>
</div>
</td>
<td>

View File

@ -35,11 +35,13 @@ Route::middleware('auth')->group(function () {
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('grades.subjects', GradeSubjectController::class)->except('index', 'show', 'edit', 'update');
Route::get('lessons/{lesson}/scores', [ScoreController::class, 'show'])->name('lessons.scores.show');
Route::put('lessons/{lesson}/scores', [ScoreController::class, 'update'])->name('lessons.scores.update');
Route::get('export-pdf', [SubjectController::class, 'exportToPDF'])->name('export-pdf');
Route::get('grades/{grade}/subjects/{subject}/journal', [GradeSubjectController::class, 'journal'])->name('grades.subjects.journal');
});
require __DIR__.'/auth.php';