From 4e2d8bec4bb0fac1d680520ed4a151c9fe31cfe7 Mon Sep 17 00:00:00 2001 From: aslan Date: Wed, 13 Mar 2024 10:26:59 +0300 Subject: [PATCH] add bootstrap validation and Logging for Entrance Examination --- app/Helpers/PositionHelper.php | 7 ++ .../EntranceExaminationController.php | 29 +++++++ .../StoreEntranceExaminationRequest.php | 32 +++++++- .../UpdateEntranceExaminationRequest.php | 32 +++++++- lang/ru/tooltips.php | 1 + .../entrance_examination/create.blade.php | 82 ++++++++++++------- .../entrance_examination/edit.blade.php | 61 ++++++++------ 7 files changed, 187 insertions(+), 57 deletions(-) diff --git a/app/Helpers/PositionHelper.php b/app/Helpers/PositionHelper.php index 906f875..a0654c9 100644 --- a/app/Helpers/PositionHelper.php +++ b/app/Helpers/PositionHelper.php @@ -4,6 +4,7 @@ namespace App\Helpers; use App\Models\Direction; use App\Models\DirectionProfile; +use App\Models\EntranceExamination; use App\Models\ExaminationType; use App\Models\Faculty; use App\Models\EducationalInstitution; @@ -53,4 +54,10 @@ class PositionHelper $maxPosition = ExaminationType::max('position'); return $maxPosition >= 254 ? 255 : $maxPosition + 1; } + + public static function entranceExamination() + { + $maxPosition = EntranceExamination::max('position'); + return $maxPosition >= 254 ? 255 : $maxPosition + 1; + } } diff --git a/app/Http/Controllers/admin/Catalog/Direction/EntranceExaminationController.php b/app/Http/Controllers/admin/Catalog/Direction/EntranceExaminationController.php index 2cc0e29..d68c127 100644 --- a/app/Http/Controllers/admin/Catalog/Direction/EntranceExaminationController.php +++ b/app/Http/Controllers/admin/Catalog/Direction/EntranceExaminationController.php @@ -12,6 +12,8 @@ use App\Models\Subject; use App\Models\SubjectType; use Illuminate\Contracts\View\View; use Illuminate\Http\RedirectResponse; +use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Log; class EntranceExaminationController extends Controller { @@ -51,6 +53,12 @@ class EntranceExaminationController extends Controller $entranceExamination->subject_type_id = $validated['subject_type_id']; $entranceExamination->save(); + Log::channel('app') + ->info( + 'CREATE вступ. испытания {entranceExamination} - user {user}', + ['user' => Auth::user()->name, 'entranceExamination' => $entranceExamination->name, 'data' => $validated] + ); + return redirect()->route('entrance_examinations.index'); } @@ -85,6 +93,7 @@ class EntranceExaminationController extends Controller EntranceExamination $entranceExamination ): RedirectResponse { $validated = $request->validated(); + $oldData = $entranceExamination->toArray(); $entranceExamination->examination_type_id = $validated['examination_type_id']; $entranceExamination->direction_id = $validated['direction_id']; @@ -92,6 +101,17 @@ class EntranceExaminationController extends Controller $entranceExamination->scores = $validated['scores']; $entranceExamination->position = $validated['position']; $entranceExamination->subject_type_id = $validated['subject_type_id']; + + Log::channel('app') + ->warning( + 'UPDATE вступ. испытания {entranceExamination} - user {user}', + [ + 'user' => Auth::user()->name, + 'entranceExamination' => $entranceExamination->name, + 'oldData' => $oldData, + 'newData' => $validated + ] + ); $entranceExamination->save(); return redirect()->route('entrance_examinations.index'); @@ -99,6 +119,15 @@ class EntranceExaminationController extends Controller public function destroy(EntranceExamination $entranceExamination): RedirectResponse { + Log::channel('app') + ->critical( + 'DELETE вступ. испытания {entranceExamination} - user {user}', + [ + 'user' => Auth::user()->name, + 'entranceExamination' => $entranceExamination->name, + 'data' => $entranceExamination->toArray(), + ] + ); $entranceExamination->delete(); return redirect()->route('entrance_examinations.index'); } diff --git a/app/Http/Requests/admin/Catalog/Direction/StoreEntranceExaminationRequest.php b/app/Http/Requests/admin/Catalog/Direction/StoreEntranceExaminationRequest.php index f4e535d..87d31a3 100644 --- a/app/Http/Requests/admin/Catalog/Direction/StoreEntranceExaminationRequest.php +++ b/app/Http/Requests/admin/Catalog/Direction/StoreEntranceExaminationRequest.php @@ -18,8 +18,38 @@ class StoreEntranceExaminationRequest extends FormRequest 'examination_type_id' => 'required|numeric|int|max:1000', 'subject_id' => 'required|numeric|int|max:1000', 'subject_type_id' => 'required|numeric|int|max:1000', - 'scores' => 'required|numeric|int|max:1000', + 'scores' => 'required|numeric|int|max:100', 'position' => 'required|numeric|int|max:1000', ]; } + + public function messages(): array + { + return [ + 'position.required' => 'Поле позиция обязательно.', + 'position.int' => 'Позиция должно быть целым числом.', + 'position.numeric' => 'Позиция должно быть числом.', + 'position.max' => 'Позиция не должен быть больше :max', + 'direction_id.required' => 'Поле позиция обязательно.', + 'direction_id.int' => 'Позиция должно быть целым числом.', + 'direction_id.numeric' => 'Позиция должно быть числом.', + 'direction_id.max' => 'Позиция не должен быть больше :max', + 'examination_type_id.required' => 'Поле позиция обязательно.', + 'examination_type_id.int' => 'Позиция должно быть целым числом.', + 'examination_type_id.numeric' => 'Позиция должно быть числом.', + 'examination_type_id.max' => 'Позиция не должен быть больше :max', + 'subject_id.required' => 'Поле позиция обязательно.', + 'subject_id.int' => 'Позиция должно быть целым числом.', + 'subject_id.numeric' => 'Позиция должно быть числом.', + 'subject_id.max' => 'Позиция не должен быть больше :max', + 'subject_type_id.required' => 'Поле позиция обязательно.', + 'subject_type_id.int' => 'Позиция должно быть целым числом.', + 'subject_type_id.numeric' => 'Позиция должно быть числом.', + 'subject_type_id.max' => 'Позиция не должен быть больше :max', + 'scores.required' => 'Поле позиция обязательно.', + 'scores.int' => 'Позиция должно быть целым числом.', + 'scores.numeric' => 'Позиция должно быть числом.', + 'scores.max' => 'Позиция не должен быть больше :max', + ]; + } } diff --git a/app/Http/Requests/admin/Catalog/Direction/UpdateEntranceExaminationRequest.php b/app/Http/Requests/admin/Catalog/Direction/UpdateEntranceExaminationRequest.php index 883f336..4c46a9d 100644 --- a/app/Http/Requests/admin/Catalog/Direction/UpdateEntranceExaminationRequest.php +++ b/app/Http/Requests/admin/Catalog/Direction/UpdateEntranceExaminationRequest.php @@ -18,8 +18,38 @@ class UpdateEntranceExaminationRequest extends FormRequest 'examination_type_id' => 'required|numeric|int|max:1000', 'subject_id' => 'required|numeric|int|max:1000', 'subject_type_id' => 'required|numeric|int|max:1000', - 'scores' => 'required|numeric|int|max:1000', + 'scores' => 'required|numeric|int|max:100', 'position' => 'required|numeric|int|max:1000', ]; } + + public function messages(): array + { + return [ + 'position.required' => 'Поле позиция обязательно.', + 'position.int' => 'Позиция должно быть целым числом.', + 'position.numeric' => 'Позиция должно быть числом.', + 'position.max' => 'Позиция не должен быть больше :max', + 'direction_id.required' => 'Поле позиция обязательно.', + 'direction_id.int' => 'Позиция должно быть целым числом.', + 'direction_id.numeric' => 'Позиция должно быть числом.', + 'direction_id.max' => 'Позиция не должен быть больше :max', + 'examination_type_id.required' => 'Поле позиция обязательно.', + 'examination_type_id.int' => 'Позиция должно быть целым числом.', + 'examination_type_id.numeric' => 'Позиция должно быть числом.', + 'examination_type_id.max' => 'Позиция не должен быть больше :max', + 'subject_id.required' => 'Поле позиция обязательно.', + 'subject_id.int' => 'Позиция должно быть целым числом.', + 'subject_id.numeric' => 'Позиция должно быть числом.', + 'subject_id.max' => 'Позиция не должен быть больше :max', + 'subject_type_id.required' => 'Поле позиция обязательно.', + 'subject_type_id.int' => 'Позиция должно быть целым числом.', + 'subject_type_id.numeric' => 'Позиция должно быть числом.', + 'subject_type_id.max' => 'Позиция не должен быть больше :max', + 'scores.required' => 'Поле позиция обязательно.', + 'scores.int' => 'Позиция должно быть целым числом.', + 'scores.numeric' => 'Позиция должно быть числом.', + 'scores.max' => 'Позиция не должен быть больше :max', + ]; + } } diff --git a/lang/ru/tooltips.php b/lang/ru/tooltips.php index 6c2baba..a0ebaaf 100644 --- a/lang/ru/tooltips.php +++ b/lang/ru/tooltips.php @@ -33,6 +33,7 @@ return [ 'subject_type_id' => 'Поле "Тип Предмета" указывает на привязку вступительного испытания к типу предмету', 'scores' => 'Поле "Кол-во баллов" указывает на привязку вступительного испытания к Кол-ву баллов', 'position' => 'Поле "Позиция" нужно для упорядочивания отображения на сайте', + 'direction_id' => 'Поле "Направление подготовки" указывает на привязку вступительного испытания к направлению подготовки', ], 'educational_institutions' => [ 'position' => 'Поле "Позиция" нужно для упорядочивания отображения на сайте', diff --git a/resources/views/admin/catalog/direction/entrance_examination/create.blade.php b/resources/views/admin/catalog/direction/entrance_examination/create.blade.php index 8165235..9a3b95d 100644 --- a/resources/views/admin/catalog/direction/entrance_examination/create.blade.php +++ b/resources/views/admin/catalog/direction/entrance_examination/create.blade.php @@ -1,54 +1,88 @@ +@php use App\Helpers\PositionHelper; @endphp @extends('layouts.admin_layout') @section('content') @auth()

Создать вступительный экзамен

- {{ Form::open(['url' => route('entrance_examinations.store'), 'method' => 'POST', 'class' => '']) }} + {{ Form::open(['url' => route('entrance_examinations.store'), 'method' => 'POST', 'class' => 'needs-validation', 'novalidate']) }}
+
- {{ Form::label('direction_id', 'Направление подготовки') }} + {{ Form::label('position', 'Позиция', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.direction_id')]) }} + *
- {{ Form::select('direction_id', $directions, null, ['class' => 'form-select']) }} + {{ Form::text('position', PositionHelper::entranceExamination(), ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.direction_id'), 'required']) }} +
+ Поле "Позиция" обязательно! +
-
+
+ @if ($errors->any()) + {{ $errors->first('position') }} + @endif +
+ +
+ {{ Form::label('direction_id', 'Направление подготовки', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.direction_id')]) }} + * +
+
+ {{ Form::select('direction_id', $directions, null, ['class' => 'form-select', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.direction_id'), 'required']) }} +
+ Поле "Направление подготовки" обязательно! +
+
+
@if ($errors->any()) {{ $errors->first('direction_id') }} @endif
- {{ Form::label('examination_type_id', 'Тип экзамена') }} + {{ Form::label('examination_type_id', 'Тип экзамена', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.examination_type_id')]) }} + *
- {{ Form::select('examination_type_id', $examination_types, null, ['class' => 'form-select']) }} + {{ Form::select('examination_type_id', $examination_types, null, ['class' => 'form-select', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.examination_type_id'), 'required']) }} +
+ Поле "Тип экзамена" обязательно! +
-
+
@if ($errors->any()) {{ $errors->first('examination_type_id') }} @endif
- {{ Form::label('subject_id', 'Предмет') }} + {{ Form::label('subject_id', 'Предмет', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.subject_id')]) }} + *
- {{ Form::select('subject_id', $subjects, null, ['class' => 'form-select']) }} + {{ Form::select('subject_id', $subjects, null, ['class' => 'form-select', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.subject_id'), 'required']) }} +
+ Поле "Предмет" обязательно! +
-
+
@if ($errors->any()) {{ $errors->first('subject_id') }} @endif
- {{ Form::label('subject_type_id', 'Тип предмета') }} + {{ Form::label('subject_type_id', 'Тип предмета', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.subject_type_id')]) }} + *
- {{ Form::select('subject_type_id', $subjectTypes, null, ['class' => 'form-select']) }} + {{ Form::select('subject_type_id', $subjectTypes, null, ['class' => 'form-select', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.subject_id'), 'required']) }} +
+ Поле "Тип предмета" обязательно! +
-
+
@if ($errors->any()) {{ $errors->first('subject_type_id') }} @endif @@ -56,29 +90,21 @@
- {{ Form::label('scores', 'Кол-во баллов') }} + {{ Form::label('scores', 'Кол-во баллов', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.subject_type_id')]) }} + *
- {{ Form::text('scores', '', ['class' => 'form-control']) }} + {{ Form::number('scores', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.subject_id'), 'required']) }} +
+ Поле "Кол-во баллов" обязательно! +
-
+
@if ($errors->any()) {{ $errors->first('scores') }} @endif
-
- {{ Form::label('position', 'Позиция') }} -
-
- {{ Form::text('position', '', ['class' => 'form-control']) }} -
-
- @if ($errors->any()) - {{ $errors->first('position') }} - @endif -
-
{{ Form::submit('Создать', ['class' => 'btn btn-primary']) }}
diff --git a/resources/views/admin/catalog/direction/entrance_examination/edit.blade.php b/resources/views/admin/catalog/direction/entrance_examination/edit.blade.php index fb2c11b..3a191bb 100644 --- a/resources/views/admin/catalog/direction/entrance_examination/edit.blade.php +++ b/resources/views/admin/catalog/direction/entrance_examination/edit.blade.php @@ -6,49 +6,67 @@

Изменить вступительный экзамен

{{ Form::open(['url' => route('entrance_examinations.update', $entranceExamination), 'method' => 'PATCH', 'class' => '']) }}
+
- {{ Form::label('direction_id', 'Направление подготовки') }} + {{ Form::label('position', 'Позиция', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.position')]) }} + *
- {{ Form::select('direction_id', $directions, $entranceExamination->direction->id, ['class' => 'form-select']) }} + {{ Form::text('position', $entranceExamination->position, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.position'), 'required']) }}
-
+
+ @if ($errors->any()) + {{ $errors->first('position') }} + @endif +
+ +
+ {{ Form::label('direction_id', 'Направление подготовки', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.direction_id')]) }} + * +
+
+ {{ Form::select('direction_id', $directions, $entranceExamination->direction->id, ['class' => 'form-select', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.direction_id'), 'required']) }} +
+
@if ($errors->any()) {{ $errors->first('direction_id') }} @endif
- {{ Form::label('examination_type_id', 'Тип экзамена') }} + {{ Form::label('examination_type_id', 'Тип экзамена', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.examination_type_id')]) }} + *
- {{ Form::select('examination_type_id', $examination_types, $entranceExamination->examinationType->id, ['class' => 'form-select']) }} + {{ Form::select('examination_type_id', $examination_types, $entranceExamination->examinationType->id, ['class' => 'form-select', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.examination_type_id'), 'required']) }}
-
+
@if ($errors->any()) {{ $errors->first('examination_type_id') }} @endif
- {{ Form::label('subject_id', 'Предмет') }} + {{ Form::label('subject_id', 'Предмет', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.subject_id')]) }} + *
- {{ Form::select('subject_id', $subjects, $entranceExamination->subject->id, ['class' => 'form-select']) }} + {{ Form::select('subject_id', $subjects, $entranceExamination->subject->id, ['class' => 'form-select', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.subject_id'), 'required']) }}
-
+
@if ($errors->any()) {{ $errors->first('subject_id') }} @endif
- {{ Form::label('subject_type_id', 'Тип предмета') }} + {{ Form::label('subject_type_id', 'Тип предмета', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.subject_type_id')]) }} + *
- {{ Form::select('subject_type_id', $subjectTypes, $entranceExamination->subjectType->id, ['class' => 'form-select']) }} + {{ Form::select('subject_type_id', $subjectTypes, $entranceExamination->subjectType->id, ['class' => 'form-select', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.subject_type_id'), 'required']) }}
-
+
@if ($errors->any()) {{ $errors->first('subject_type_id') }} @endif @@ -56,29 +74,18 @@
- {{ Form::label('scores', 'Кол-во баллов') }} + {{ Form::label('scores', 'Кол-во баллов', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.scores')]) }} + *
- {{ Form::text('scores', $entranceExamination->scores, ['class' => 'form-control']) }} + {{ Form::text('scores', $entranceExamination->scores, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.entrance-examination.scores'), 'required']) }}
-
+
@if ($errors->any()) {{ $errors->first('scores') }} @endif
-
- {{ Form::label('position', 'Позиция') }} -
-
- {{ Form::text('position', $entranceExamination->position, ['class' => 'form-control']) }} -
-
- @if ($errors->any()) - {{ $errors->first('position') }} - @endif -
-
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}