From 24b5683090aacf964c5cacc5ae9b227780511a69 Mon Sep 17 00:00:00 2001 From: "m.zargarov" Date: Thu, 20 Jun 2024 12:27:05 +0400 Subject: [PATCH 1/6] Add journal --- .../Controllers/GradeSubjectController.php | 27 +++------ app/Services/JournalService.php | 19 +++++++ .../views/grade-subject/journal.blade.php | 57 +++++++++++++++++++ resources/views/grades/show.blade.php | 2 +- routes/web.php | 4 +- 5 files changed, 89 insertions(+), 20 deletions(-) create mode 100644 app/Services/JournalService.php create mode 100644 resources/views/grade-subject/journal.blade.php diff --git a/app/Http/Controllers/GradeSubjectController.php b/app/Http/Controllers/GradeSubjectController.php index d7ee45d..3ec4ed8 100644 --- a/app/Http/Controllers/GradeSubjectController.php +++ b/app/Http/Controllers/GradeSubjectController.php @@ -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(), + ]); + } } diff --git a/app/Services/JournalService.php b/app/Services/JournalService.php new file mode 100644 index 0000000..daa1238 --- /dev/null +++ b/app/Services/JournalService.php @@ -0,0 +1,19 @@ +where('grade_id', $grade->id) + ->where('subject_id', $subject->id) + ->orderBy('lesson_date') + ->get(); + } +} diff --git a/resources/views/grade-subject/journal.blade.php b/resources/views/grade-subject/journal.blade.php new file mode 100644 index 0000000..02f3cb1 --- /dev/null +++ b/resources/views/grade-subject/journal.blade.php @@ -0,0 +1,57 @@ +@extends('layouts.application') + +@section('content') +
+
+ @if (count($students)) +
+
{{__('Журнал')}}
+
+
+ + + + + @foreach ($lessons as $lesson) + + @endforeach + + + + @foreach ($lessons as $lesson) + + @endforeach + + + + @foreach ($students as $student) + + + @foreach ($lessons as $lesson) + + @endforeach + + @endforeach +{{-- --}} +{{-- --}} +{{-- @foreach ($avgScores as $avgScore)--}} +{{-- --}} +{{-- @endforeach--}} +{{-- --}} + +
ФИО{{ $lesson->lesson_date }}
{{ $lesson->type }}
{{ $student->fio }} + {{ $student->lessons->find($lesson->id)->pivot->score ?? "-" }} +
Средняя оценка--}} +{{-- {{ $avgScore ? $avgScore : "" }}--}} +{{--
+
+
+
+{{--
--}} +{{-- @include('journals.list', ['users' => $goods, 'studentName' => 'хорошистов'])--}} +{{-- @include('journals.list', ['users' => $perfects, 'studentName' => 'отличников'])--}} +{{--
--}} + @endif +
+
+@endsection diff --git a/resources/views/grades/show.blade.php b/resources/views/grades/show.blade.php index 80fa23f..dc25c85 100644 --- a/resources/views/grades/show.blade.php +++ b/resources/views/grades/show.blade.php @@ -35,7 +35,7 @@
- Редактировать + Журнал
diff --git a/routes/web.php b/routes/web.php index 95a8b77..aafe04d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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'; -- 2.25.1 From 2255a901be2567d759683772ba2af947e2ea2e0e Mon Sep 17 00:00:00 2001 From: "m.zargarov" Date: Thu, 20 Jun 2024 15:57:12 +0400 Subject: [PATCH 2/6] Fix --- app/Http/Controllers/StudentController.php | 7 +++++++ app/Models/Student.php | 2 +- app/Services/StudentService.php | 12 ++++++++++++ routes/web.php | 2 ++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/StudentController.php b/app/Http/Controllers/StudentController.php index 5217ca6..80cb66a 100644 --- a/app/Http/Controllers/StudentController.php +++ b/app/Http/Controllers/StudentController.php @@ -91,4 +91,11 @@ class StudentController extends Controller return redirect()->route('students.index'); } + + public function scores(StudentService $service): View + { + return view('students.scores', [ + 'scores' => $service->getScores(), + ]); + } } diff --git a/app/Models/Student.php b/app/Models/Student.php index fdc1552..1c96a5f 100644 --- a/app/Models/Student.php +++ b/app/Models/Student.php @@ -39,7 +39,7 @@ class Student extends Model public function lessons(): BelongsToMany { - return $this->belongsToMany(Lesson::class); + return $this->belongsToMany(Lesson::class)->withPivot('score'); } public function scopeFilter(Builder $query): void diff --git a/app/Services/StudentService.php b/app/Services/StudentService.php index 94643b3..fbfdaac 100644 --- a/app/Services/StudentService.php +++ b/app/Services/StudentService.php @@ -5,7 +5,9 @@ namespace App\Services; use App\Enums\ScoreEnum; use App\Models\Student; use App\Models\User; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Pagination\LengthAwarePaginator; +use Illuminate\Support\Facades\Auth; class StudentService { @@ -53,4 +55,14 @@ class StudentService $model->user()->delete(); $model->delete(); } + + public function getScores(): Collection + { + $student = Auth::user()->userable; + foreach ($student->lessons as $lesson) { + dd($lesson->pivot->score); + } + + return $student->lessons; + } } diff --git a/routes/web.php b/routes/web.php index aafe04d..74da970 100644 --- a/routes/web.php +++ b/routes/web.php @@ -42,6 +42,8 @@ Route::middleware('auth')->group(function () { Route::get('export-pdf', [SubjectController::class, 'exportToPDF'])->name('export-pdf'); Route::get('grades/{grade}/subjects/{subject}/journal', [GradeSubjectController::class, 'journal'])->name('grades.subjects.journal'); + + Route::get('student-scores', [StudentController::class, 'scores'])->name('student-scores'); }); require __DIR__.'/auth.php'; -- 2.25.1 From 1216f6b81bf6cddc0b8b86a86f82bd3a93be650f Mon Sep 17 00:00:00 2001 From: "m.zargarov" Date: Sun, 23 Jun 2024 00:57:29 +0400 Subject: [PATCH 3/6] Rebase --- .../Controllers/GradeSubjectController.php | 27 ++++----- app/Services/JournalService.php | 19 +++++++ .../views/grade-subject/journal.blade.php | 57 +++++++++++++++++++ resources/views/grades/show.blade.php | 2 +- routes/web.php | 1 + 5 files changed, 88 insertions(+), 18 deletions(-) create mode 100644 app/Services/JournalService.php create mode 100644 resources/views/grade-subject/journal.blade.php diff --git a/app/Http/Controllers/GradeSubjectController.php b/app/Http/Controllers/GradeSubjectController.php index 0d8a69a..cc335e2 100644 --- a/app/Http/Controllers/GradeSubjectController.php +++ b/app/Http/Controllers/GradeSubjectController.php @@ -5,6 +5,8 @@ namespace App\Http\Controllers; use App\Http\Requests\GradeSubjectPostRequest; use App\Models\Grade; use App\Models\Subject; + +use App\Services\JournalService; use Illuminate\Http\RedirectResponse; use Illuminate\View\View; @@ -25,27 +27,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(), + ]); + } } diff --git a/app/Services/JournalService.php b/app/Services/JournalService.php new file mode 100644 index 0000000..daa1238 --- /dev/null +++ b/app/Services/JournalService.php @@ -0,0 +1,19 @@ +where('grade_id', $grade->id) + ->where('subject_id', $subject->id) + ->orderBy('lesson_date') + ->get(); + } +} diff --git a/resources/views/grade-subject/journal.blade.php b/resources/views/grade-subject/journal.blade.php new file mode 100644 index 0000000..02f3cb1 --- /dev/null +++ b/resources/views/grade-subject/journal.blade.php @@ -0,0 +1,57 @@ +@extends('layouts.application') + +@section('content') +
+
+ @if (count($students)) +
+
{{__('Журнал')}}
+
+
+ + + + + @foreach ($lessons as $lesson) + + @endforeach + + + + @foreach ($lessons as $lesson) + + @endforeach + + + + @foreach ($students as $student) + + + @foreach ($lessons as $lesson) + + @endforeach + + @endforeach +{{-- --}} +{{-- --}} +{{-- @foreach ($avgScores as $avgScore)--}} +{{-- --}} +{{-- @endforeach--}} +{{-- --}} + +
ФИО{{ $lesson->lesson_date }}
{{ $lesson->type }}
{{ $student->fio }} + {{ $student->lessons->find($lesson->id)->pivot->score ?? "-" }} +
Средняя оценка--}} +{{-- {{ $avgScore ? $avgScore : "" }}--}} +{{--
+
+
+
+{{--
--}} +{{-- @include('journals.list', ['users' => $goods, 'studentName' => 'хорошистов'])--}} +{{-- @include('journals.list', ['users' => $perfects, 'studentName' => 'отличников'])--}} +{{--
--}} + @endif +
+
+@endsection diff --git a/resources/views/grades/show.blade.php b/resources/views/grades/show.blade.php index 80fa23f..dc25c85 100644 --- a/resources/views/grades/show.blade.php +++ b/resources/views/grades/show.blade.php @@ -35,7 +35,7 @@
- Редактировать + Журнал
diff --git a/routes/web.php b/routes/web.php index db41072..498a15c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -44,6 +44,7 @@ Route::middleware('auth')->group(function () { Route::middleware([TeacherAction::class])->group(function () { 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('grades/{grade}/subjects/{subject}/journal', [GradeSubjectController::class, 'journal'])->name('grades.subjects.journal'); }); Route::get('export-pdf', [SubjectController::class, 'exportToPDF'])->name('export-pdf'); -- 2.25.1 From bcdec4dcc77d8e193133d4457a48cae223d79cc7 Mon Sep 17 00:00:00 2001 From: "m.zargarov" Date: Sun, 23 Jun 2024 00:58:31 +0400 Subject: [PATCH 4/6] Rebase --- app/Http/Controllers/StudentController.php | 7 +++++++ app/Models/Student.php | 2 +- app/Services/StudentService.php | 12 ++++++++++++ routes/web.php | 2 ++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/StudentController.php b/app/Http/Controllers/StudentController.php index f0fd10b..a2dcc49 100644 --- a/app/Http/Controllers/StudentController.php +++ b/app/Http/Controllers/StudentController.php @@ -118,4 +118,11 @@ class StudentController extends Controller return redirect()->route('students.index'); } + + public function scores(StudentService $service): View + { + return view('students.scores', [ + 'scores' => $service->getScores(), + ]); + } } diff --git a/app/Models/Student.php b/app/Models/Student.php index fdc1552..1c96a5f 100644 --- a/app/Models/Student.php +++ b/app/Models/Student.php @@ -39,7 +39,7 @@ class Student extends Model public function lessons(): BelongsToMany { - return $this->belongsToMany(Lesson::class); + return $this->belongsToMany(Lesson::class)->withPivot('score'); } public function scopeFilter(Builder $query): void diff --git a/app/Services/StudentService.php b/app/Services/StudentService.php index 94643b3..fbfdaac 100644 --- a/app/Services/StudentService.php +++ b/app/Services/StudentService.php @@ -5,7 +5,9 @@ namespace App\Services; use App\Enums\ScoreEnum; use App\Models\Student; use App\Models\User; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Pagination\LengthAwarePaginator; +use Illuminate\Support\Facades\Auth; class StudentService { @@ -53,4 +55,14 @@ class StudentService $model->user()->delete(); $model->delete(); } + + public function getScores(): Collection + { + $student = Auth::user()->userable; + foreach ($student->lessons as $lesson) { + dd($lesson->pivot->score); + } + + return $student->lessons; + } } diff --git a/routes/web.php b/routes/web.php index 498a15c..6c38224 100644 --- a/routes/web.php +++ b/routes/web.php @@ -48,6 +48,8 @@ Route::middleware('auth')->group(function () { }); Route::get('export-pdf', [SubjectController::class, 'exportToPDF'])->name('export-pdf'); + + Route::get('student-scores', [StudentController::class, 'scores'])->name('student-scores'); }); require __DIR__.'/auth.php'; -- 2.25.1 From 539526108415af2fb5ccab268b467a672e04a637 Mon Sep 17 00:00:00 2001 From: "m.zargarov" Date: Sun, 23 Jun 2024 00:51:15 +0400 Subject: [PATCH 5/6] hz --- package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 1f1c287..698845b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "course_work", + "name": "CourseWork", "lockfileVersion": 3, "requires": true, "packages": { -- 2.25.1 From 6fb18f6949d70c464bdc60c6730b64e5ee9a2cd5 Mon Sep 17 00:00:00 2001 From: "m.zargarov" Date: Sun, 23 Jun 2024 17:02:18 +0400 Subject: [PATCH 6/6] Add mnogo chego --- app/Console/Commands/AddAdmin.php | 43 ++++++++++ app/Enums/ScoreEnum.php | 11 ++- app/Http/Controllers/StudentController.php | 13 ++- .../Controllers/SubjectTeacherController.php | 8 ++ app/Http/Controllers/TeacherController.php | 4 +- app/Http/Middleware/StudentAction.php | 26 ++++++ app/Policies/TeacherPolicy.php | 4 +- app/Services/FileService.php | 2 +- app/Services/StudentService.php | 27 ++++-- app/Services/SubjectService.php | 4 +- app/Services/TeacherService.php | 29 +++++++ config/tinker.php | 50 +++++++++++ database/seeders/DatabaseSeeder.php | 84 ++++++++++++++----- resources/views/grade-lesson/show.blade.php | 10 ++- resources/views/layouts/navigation.blade.php | 24 ++++-- resources/views/students/debts.blade.php | 28 +++++++ resources/views/students/scores.blade.php | 24 ++++++ .../views/subject-teacher/index.blade.php | 19 +++++ resources/views/subjects/index.blade.php | 39 +++++---- resources/views/teachers/index.blade.php | 35 +++++--- routes/web.php | 10 ++- 21 files changed, 419 insertions(+), 75 deletions(-) create mode 100644 app/Console/Commands/AddAdmin.php create mode 100644 app/Http/Middleware/StudentAction.php create mode 100644 config/tinker.php create mode 100644 resources/views/students/debts.blade.php create mode 100644 resources/views/students/scores.blade.php create mode 100644 resources/views/subject-teacher/index.blade.php diff --git a/app/Console/Commands/AddAdmin.php b/app/Console/Commands/AddAdmin.php new file mode 100644 index 0000000..d3d00e0 --- /dev/null +++ b/app/Console/Commands/AddAdmin.php @@ -0,0 +1,43 @@ + 'admin' . $admin->id . '@mail', + 'password' => 'password', + ]); + + $admin->user()->save($user); + + $this->info('Admin created successfully!'); + $this->info('email = ' . $user->email); + $this->info('password = password'); + } +} diff --git a/app/Enums/ScoreEnum.php b/app/Enums/ScoreEnum.php index fd17bbe..f7f5121 100644 --- a/app/Enums/ScoreEnum.php +++ b/app/Enums/ScoreEnum.php @@ -5,11 +5,20 @@ namespace App\Enums; enum ScoreEnum: string { case WithoutScore = 'Без оценки'; - case One = '1'; case Two = '2'; case Three = '3'; case Four = '4'; case Five = '5'; case Absent = 'Н'; case Sick = 'Б'; + + public static function getNumScores(): array + { + return [self::Two, self::Three, self::Four, self::Five]; + } + + public static function getDebtScores(): array + { + return [self::Absent, self::Sick]; + } } diff --git a/app/Http/Controllers/StudentController.php b/app/Http/Controllers/StudentController.php index a2dcc49..f0ce8cf 100644 --- a/app/Http/Controllers/StudentController.php +++ b/app/Http/Controllers/StudentController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use App\Http\Requests\StudentPostRequest; use App\Models\Grade; use App\Models\Student; +use App\Models\Subject; use App\Services\StudentService; use Illuminate\Http\RedirectResponse; use Illuminate\View\View; @@ -119,10 +120,18 @@ class StudentController extends Controller return redirect()->route('students.index'); } - public function scores(StudentService $service): View + public function scores(StudentService $service, Subject $subject): View { return view('students.scores', [ - 'scores' => $service->getScores(), + 'lessons' => $service->getScores($subject), + 'avgScore' => $service->getAvgScore($subject), + ]); + } + + public function debts(StudentService $service): View + { + return view('students.debts', [ + 'lessons' => $service->getDebts(), ]); } } diff --git a/app/Http/Controllers/SubjectTeacherController.php b/app/Http/Controllers/SubjectTeacherController.php index 880ce4b..f0656b7 100644 --- a/app/Http/Controllers/SubjectTeacherController.php +++ b/app/Http/Controllers/SubjectTeacherController.php @@ -5,11 +5,19 @@ namespace App\Http\Controllers; use App\Http\Requests\SubjectTeacherPostRequest; use App\Models\Subject; use App\Models\Teacher; +use App\Services\TeacherService; use Illuminate\Http\RedirectResponse; use Illuminate\View\View; class SubjectTeacherController extends Controller { + public function index(Teacher $teacher, TeacherService $service) + { + return view('subject-teacher.index', [ + 'subjects' => $service->getSubjects($teacher), + ]); + } + public function create(Teacher $teacher): View { return view('subject-teacher.create', [ diff --git a/app/Http/Controllers/TeacherController.php b/app/Http/Controllers/TeacherController.php index 13fa149..eb2bf08 100644 --- a/app/Http/Controllers/TeacherController.php +++ b/app/Http/Controllers/TeacherController.php @@ -18,14 +18,14 @@ class TeacherController extends Controller /** * Display a listing of the resource. */ - public function index(): View + public function index(TeacherService $service): View { if(request()->user()->cannot('viewAny', Teacher::class)) { abort(403); } return view('teachers.index', [ - 'teachers' => Teacher::filter()->paginate(5)->withQueryString(), + 'teachers' => $service->getTeachers(), ]); } diff --git a/app/Http/Middleware/StudentAction.php b/app/Http/Middleware/StudentAction.php new file mode 100644 index 0000000..8fba04c --- /dev/null +++ b/app/Http/Middleware/StudentAction.php @@ -0,0 +1,26 @@ +userable_type != Student::class) { + abort(403); + } + + return $next($request); + } +} diff --git a/app/Policies/TeacherPolicy.php b/app/Policies/TeacherPolicy.php index ac37cca..209a5d4 100644 --- a/app/Policies/TeacherPolicy.php +++ b/app/Policies/TeacherPolicy.php @@ -14,7 +14,7 @@ class TeacherPolicy */ public function viewAny(User $user): bool { - return $user->userable_type != Student::class; + return $user->userable_type != Teacher::class; } /** @@ -22,7 +22,7 @@ class TeacherPolicy */ public function view(User $user, Teacher $teacher): bool { - return $user->userable_type == Teacher::class; + return $user->userable_type == Admin::class; } /** diff --git a/app/Services/FileService.php b/app/Services/FileService.php index d5971ac..46bd75d 100644 --- a/app/Services/FileService.php +++ b/app/Services/FileService.php @@ -22,6 +22,6 @@ class FileService }); }); - return Pdf::loadView('subjects.pdf', ['subjects' => $listSubjects])->download('subjects.pdf'); + return Pdf::loadView('subjects.pdf', ['subjects' => $listSubjects])->download('Предметы.pdf'); } } diff --git a/app/Services/StudentService.php b/app/Services/StudentService.php index fbfdaac..7e83f62 100644 --- a/app/Services/StudentService.php +++ b/app/Services/StudentService.php @@ -4,6 +4,7 @@ namespace App\Services; use App\Enums\ScoreEnum; use App\Models\Student; +use App\Models\Subject; use App\Models\User; use Illuminate\Database\Eloquent\Collection; use Illuminate\Pagination\LengthAwarePaginator; @@ -56,13 +57,29 @@ class StudentService $model->delete(); } - public function getScores(): Collection + public function getScores(Subject $subject): Collection { $student = Auth::user()->userable; - foreach ($student->lessons as $lesson) { - dd($lesson->pivot->score); - } - return $student->lessons; + return $student->lessons()->where('subject_id', $subject->id)->get(); + } + + public function getAvgScore(Subject $subject) + { + $student = Auth::user()->userable; + $scores = $student + ->lessons() + ->where('subject_id', $subject->id) + ->whereIn('score', ScoreEnum::getNumScores()) + ->pluck('score'); + + return round($scores->avg(), 2); + } + + public function getDebts(): Collection + { + $student = Auth::user()->userable; + + return $student->lessons()->whereIn('score', ScoreEnum::getDebtScores())->get(); } } diff --git a/app/Services/SubjectService.php b/app/Services/SubjectService.php index 854de9f..1a07737 100644 --- a/app/Services/SubjectService.php +++ b/app/Services/SubjectService.php @@ -11,9 +11,7 @@ class SubjectService public function getSubjects() { if(Auth::user()->userable_type == Student::class) { - $student = Auth::user()->userable; - - return Subject::whereIn('id', $student->grade->subjects->pluck('id')) + return Subject::whereIn('id', Auth::user()->userable->grade->subjects->pluck('id')) ->filter() ->paginate(5) ->withQueryString(); diff --git a/app/Services/TeacherService.php b/app/Services/TeacherService.php index 4059882..74da357 100644 --- a/app/Services/TeacherService.php +++ b/app/Services/TeacherService.php @@ -2,9 +2,12 @@ namespace App\Services; +use App\Models\Student; +use App\Models\Subject; use App\Models\Teacher; use App\Models\User; use Illuminate\Pagination\LengthAwarePaginator; +use Illuminate\Support\Facades\Auth; class TeacherService { @@ -47,4 +50,30 @@ class TeacherService $teacher->user()->delete(); $teacher->delete(); } + + public function getTeachers() + { + if (Auth::user()->userable_type == Student::class) { + return Teacher::join('grade_teacher', 'teachers.id', '=', 'grade_teacher.teacher_id') + ->where('grade_id', Auth::user()->userable->grade_id) + ->filter() + ->paginate(5) + ->withQueryString(); + } + + return Teacher::filter()->paginate(5)->withQueryString(); + } + + public function getSubjects(Teacher $teacher) + { + if (Auth::user()->userable_type == Student::class) { + return Subject::join('subject_teacher', 'subject_teacher.subject_id', '=', 'subjects.id') + ->join('grade_subject', 'grade_subject.subject_id', '=', 'subjects.id') + ->where('grade_subject.grade_id', Auth::user()->userable->grade_id) + ->where('subject_teacher.teacher_id', $teacher->id) + ->get(); + } + + return $teacher->subjects; + } } diff --git a/config/tinker.php b/config/tinker.php new file mode 100644 index 0000000..459fe7b --- /dev/null +++ b/config/tinker.php @@ -0,0 +1,50 @@ + [ + App\Console\Commands\AddAdmin::class, + ], + + /* + |-------------------------------------------------------------------------- + | Auto Aliased Classes + |-------------------------------------------------------------------------- + | + | Tinker will not automatically alias classes in your vendor namespaces + | but you may explicitly allow a subset of classes to get aliased by + | adding the names of each of those classes to the following list. + | + */ + + 'alias' => [ + // + ], + + /* + |-------------------------------------------------------------------------- + | Classes That Should Not Be Aliased + |-------------------------------------------------------------------------- + | + | Typically, Tinker automatically aliases classes as you require them in + | Tinker. However, you may wish to never alias certain classes, which + | you may accomplish by listing the classes in the following array. + | + */ + + 'dont_alias' => [ + 'App\Nova', + ], + +]; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 1344e92..875bce2 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -18,9 +18,39 @@ class DatabaseSeeder extends Seeder */ public function run(): void { + $namesSubjects = [ + 'Русский язык', + 'Математика', + 'Английский язык', + 'Биология', + 'Химия', + 'Литература', + 'География', + 'История', + 'Обществознание', + 'Информатика', + ]; + $subjects = collect(); + + foreach ($namesSubjects as $name) { + $subjects->push(Subject::factory()->create([ + 'name' => $name, + ])); + } + + $letterGrades = ['A', 'Б', 'В',]; + $numberGrades = 11; + $grades = collect(); + + while($numberGrades > 0) { + foreach ($letterGrades as $letter) { + $grades->push(Grade::factory()->create([ + 'name' => $numberGrades . $letter, + ])); + } + $numberGrades--; + } $teachers = Teacher::factory(15)->create(); - $grades = Grade::factory(10)->create(); - $subjects = Subject::factory(10)->create(); $scores = ScoreEnum::cases(); $teachers->each(function ($teacher) { @@ -28,33 +58,45 @@ class DatabaseSeeder extends Seeder $teacher->user()->save($user); }); - $grades->each(function ($grade) use ($subjects, $teachers, $scores){ - $grade->subjects()->sync($subjects); - $grade->teachers()->sync($teachers); + $teacher = Teacher::factory()->create(); + $teacher->user()->save(User::factory()->create(['email' => 'teacher@mail'])); + $teacher->grades()->attach($grades->pluck('id')); - $students = Student::factory(10)->create([ + $student = Student::factory()->create(['grade_id' => $grades->first()->id]); + $student->user()->save(User::factory()->create(['email' => 'student@mail'])); + + $grade = $student->grade; + + $lessons = collect(); + $subjects->each(function ($item) use ($lessons, $teacher, $student, $grade) { + $teacher->subjects()->attach($item); + $grade->subjects()->attach($item); + + $lessons->push(Lesson::factory(5)->create([ + 'description' => 'Выполнение задания №3 на 87 стр. учебника', + 'grade_id' => $student->grade_id, + 'subject_id' => $item->id, + 'teacher_id' => $teacher->id, + ])); + }); + + + $grades->each(function ($grade) use ($subjects, $teachers, $scores){ + Student::factory(30)->create([ 'grade_id' => $grade->id, ])->each(function ($student) use ($scores) { $user = User::factory()->create(); $student->user()->save($user); }); - - $lessons = Lesson::factory(30)->create([ - 'grade_id' => $grade->id, - 'subject_id' => $grade->subjects->random()->id, - 'teacher_id' => $grade->teachers->random()->id, - ]); - - $students->each(function ($student) use ($lessons, $scores) { - $lessons->each(function ($lesson) use ($student, $scores) { - $student->lessons() - ->syncWithoutDetaching([$lesson->id => ['score' => $scores[array_rand($scores)]]]); - }); - }); }); - $subjects->each(function ($subject) use ($teachers) { - $subject->teachers()->sync($teachers->random(2)); + $grade->students->each(function ($student) use ($grade, $scores) { + $grade->lessons->each(function ($lesson) use ($student, $scores) { + $student->lessons() + ->syncWithoutDetaching([ + $lesson->id => ['score' => $scores[array_rand($scores)]] + ]); + }); }); } } diff --git a/resources/views/grade-lesson/show.blade.php b/resources/views/grade-lesson/show.blade.php index ed44ce5..0cc3889 100644 --- a/resources/views/grade-lesson/show.blade.php +++ b/resources/views/grade-lesson/show.blade.php @@ -19,10 +19,12 @@
Описание: {{ $lesson->description }}
- + @can('update', $lesson) + + @endcan diff --git a/resources/views/layouts/navigation.blade.php b/resources/views/layouts/navigation.blade.php index 306dfd6..678f1be 100644 --- a/resources/views/layouts/navigation.blade.php +++ b/resources/views/layouts/navigation.blade.php @@ -11,29 +11,43 @@ + @if(\Illuminate\Support\Facades\Auth::user()->userable_type != \App\Models\Student::class) + @endif + @if(\Illuminate\Support\Facades\Auth::user()->userable_type != \App\Models\Student::class) + @endif + @if(\Illuminate\Support\Facades\Auth::user()->userable_type != \App\Models\Teacher::class) + @endif + + @if(\Illuminate\Support\Facades\Auth::user()->userable_type == \App\Models\Student::class) + + @endif @@ -41,7 +55,7 @@ - - + + + + @can('update', $subject) + + + + @endcan + @can('delete', $subject) + +
+ @csrf + @method('DELETE') + +
+ + @endcan @endforeach @@ -55,7 +64,9 @@ @endif diff --git a/resources/views/teachers/index.blade.php b/resources/views/teachers/index.blade.php index 49f6abb..927aa8f 100644 --- a/resources/views/teachers/index.blade.php +++ b/resources/views/teachers/index.blade.php @@ -31,21 +31,30 @@ - -
- @csrf - @method('DELETE') - -
- + @can('update', $teacher) + + + + @endcan + @can('delete', $teacher) + +
+ @csrf + @method('DELETE') + +
+ + @endcan @endforeach @@ -54,9 +63,11 @@

Учителя отсутствуют

@endif - + @can('create', Teacher::class) + + @endcan diff --git a/routes/web.php b/routes/web.php index 6c38224..65d291c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,6 +2,7 @@ use App\Http\Controllers\ProfileController; use App\Http\Middleware\AdminAction; +use App\Http\Middleware\StudentAction; use App\Http\Middleware\TeacherAction; use Illuminate\Support\Facades\Route; use App\Http\Controllers\GradeController; @@ -47,9 +48,12 @@ Route::middleware('auth')->group(function () { Route::get('grades/{grade}/subjects/{subject}/journal', [GradeSubjectController::class, 'journal'])->name('grades.subjects.journal'); }); - Route::get('export-pdf', [SubjectController::class, 'exportToPDF'])->name('export-pdf'); - - Route::get('student-scores', [StudentController::class, 'scores'])->name('student-scores'); + Route::middleware([StudentAction::class])->group(function () { + Route::get('export-pdf', [SubjectController::class, 'exportToPDF'])->name('export-pdf'); + 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'); + }); }); require __DIR__.'/auth.php'; -- 2.25.1