prodV1 #2

Open
RomanGolienko wants to merge 309 commits from prodV1 into main
11 changed files with 183 additions and 59 deletions
Showing only changes of commit 64ad13f96f - Show all commits

View File

@ -3,6 +3,7 @@
namespace App\Helpers; namespace App\Helpers;
use App\Models\Direction; use App\Models\Direction;
use App\Models\DirectionProfile;
use App\Models\Faculty; use App\Models\Faculty;
use App\Models\EducationalInstitution; use App\Models\EducationalInstitution;
@ -25,4 +26,10 @@ class PositionHelper
$maxPosition = EducationalInstitution::max('position'); $maxPosition = EducationalInstitution::max('position');
return $maxPosition >= 254 ? 255 : $maxPosition + 1; return $maxPosition >= 254 ? 255 : $maxPosition + 1;
} }
public static function directionProfiles()
{
$maxPosition = DirectionProfile::max('position');
return $maxPosition >= 254 ? 255 : $maxPosition + 1;
}
} }

View File

@ -9,6 +9,9 @@ use App\Models\Direction;
use App\Models\DirectionProfile; use App\Models\DirectionProfile;
use Illuminate\Contracts\View\View; use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
class DirectionProfileController extends Controller class DirectionProfileController extends Controller
{ {
@ -28,13 +31,27 @@ class DirectionProfileController extends Controller
{ {
$validated = $request->validated(); $validated = $request->validated();
if ($validated['slug'] === null) {
$transliterationSlug = Str::slug($validated['name']);
$randomNumber = random_int(100, 999);
$slug = "{$transliterationSlug}-{$randomNumber}";
} else {
$slug = $validated['slug'];
}
$directionProfile = new DirectionProfile(); $directionProfile = new DirectionProfile();
$directionProfile->name = $validated['name']; $directionProfile->name = $validated['name'];
$directionProfile->description = $validated['description']; $directionProfile->description = $validated['description'];
$directionProfile->slug = $validated['slug']; $directionProfile->slug = $slug;
$directionProfile->position = $validated['position']; $directionProfile->position = $validated['position'];
$directionProfile->save(); $directionProfile->save();
Log::channel('app')
->info(
'CREATE профиль подготовки {directionProfile} - user {user}',
['user' => Auth::user()->name, 'directionProfile' => $directionProfile->name, 'data' => $validated]
);
return redirect()->route('direction_profiles.index'); return redirect()->route('direction_profiles.index');
} }
@ -55,6 +72,7 @@ class DirectionProfileController extends Controller
public function update(UpdateDirectionProfileRequest $request, DirectionProfile $directionProfile): RedirectResponse public function update(UpdateDirectionProfileRequest $request, DirectionProfile $directionProfile): RedirectResponse
{ {
$validated = $request->validated(); $validated = $request->validated();
$oldData = $directionProfile->toArray();
$directionProfile->name = $validated['name']; $directionProfile->name = $validated['name'];
$directionProfile->description = $validated['description']; $directionProfile->description = $validated['description'];
@ -62,14 +80,43 @@ class DirectionProfileController extends Controller
$directionProfile->position = $validated['position']; $directionProfile->position = $validated['position'];
$directionProfile->save(); $directionProfile->save();
Log::channel('app')
->warning(
'UPDATE профиль подготовки {directionProfile} - user {user}',
[
'user' => Auth::user()->name,
'directionProfile' => $directionProfile->name,
'oldData' => $oldData,
'newData' => $validated
]
);
return redirect()->route('direction_profiles.index'); return redirect()->route('direction_profiles.index');
} }
public function destroy(DirectionProfile $directionProfile): RedirectResponse public function destroy(DirectionProfile $directionProfile): RedirectResponse
{ {
if ($directionProfile->direction()->exists()) { if ($directionProfile->direction()->exists()) {
Log::channel('app')
->error(
'NOT DELETE профиль подготовки {directionProfile} - user {user}',
[
'user' => Auth::user()->name,
'directionProfile' => $directionProfile->name,
'data' => $directionProfile->toArray(),
]
);
return back(); return back();
} }
Log::channel('app')
->critical(
'DELETE профиль подготовки {directionProfile} - user {user}',
[
'user' => Auth::user()->name,
'directionProfile' => $directionProfile->name,
'data' => $directionProfile->toArray(),
]
);
$directionProfile->delete(); $directionProfile->delete();
return redirect()->route('direction_profiles.index'); return redirect()->route('direction_profiles.index');
} }

View File

@ -81,7 +81,7 @@ class FacultyController extends Controller
$faculty->educational_institution_id = $validated['educational_institution_id']; $faculty->educational_institution_id = $validated['educational_institution_id'];
Log::channel('app') Log::channel('app')
->info( ->warning(
'UPDATE факультет {faculty} - user {user}', 'UPDATE факультет {faculty} - user {user}',
[ [
'user' => Auth::user()->name, 'user' => Auth::user()->name,
@ -97,15 +97,27 @@ class FacultyController extends Controller
public function destroy(Faculty $faculty): RedirectResponse public function destroy(Faculty $faculty): RedirectResponse
{ {
Log::channel('app')
->info(
'DELETE факультет {faculty} - user {user}',
['user' => Auth::user()->name, 'faculty' => $faculty->name, 'data' => $faculty->toArray()]
);
if ($faculty->departments()->exists()) { if ($faculty->departments()->exists()) {
Log::channel('app')
->critical(
'NOT DELETE факультет {faculty} - user {user}',
[
'user' => Auth::user()->name,
'faculty' => $faculty->name,
'data' => $faculty->toArray(),
]
);
return back(); return back();
} }
Log::channel('app')
->critical(
'DELETE факультет {faculty} - user {user}',
[
'user' => Auth::user()->name,
'faculty' => $faculty->name,
'data' => $faculty->toArray(),
]
);
$faculty->delete(); $faculty->delete();
return redirect()->route('faculties.index'); return redirect()->route('faculties.index');
} }

View File

@ -15,9 +15,26 @@ class StoreDirectionProfileRequest extends FormRequest
{ {
return [ return [
'name' => 'required|string|max:255|unique:direction_profiles,name', 'name' => 'required|string|max:255|unique:direction_profiles,name',
'description' => 'string', 'description' => 'nullable|string',
'slug' => 'required|string|max:255|unique:direction_profiles,slug', 'slug' => 'nullable|string|max:255|unique:direction_profiles,slug',
'position' => 'required|int|numeric|max:255', 'position' => 'required|int|numeric|max:255',
]; ];
} }
public function messages(): array
{
return [
'position.required' => 'Поле позиция обязательно.',
'position.int' => 'Позиция должно быть целым числом.',
'position.numeric' => 'Позиция должно быть числом.',
'position.max' => 'Позиция не должен быть больше :max',
'name.required' => 'Поле название обязательно.',
'name.string' => 'Поле название должен быть строкой.',
'name.max' => 'Поле название не должен превышать :max символов.',
'name.unique' => 'Название уже занят.',
'description.string' => 'Поле описание должен быть строкой.',
'slug.string' => 'Поле URL должен быть строкой.',
'slug.max' => 'Поле URL не должен превышать :max символов.',
];
}
} }

View File

@ -14,10 +14,27 @@ class UpdateDirectionProfileRequest extends FormRequest
public function rules(): array public function rules(): array
{ {
return [ return [
'name' => "required|string|max:255|unique:direction_profiles,name,{$this->direction_profile->id}", 'name' => ['required', 'string', 'max:255', "unique:direction_profiles,name,{$this->direction_profile->id}",],
'description' => 'string', 'description' => 'nullable|string',
'slug' => "required|string|max:255|unique:direction_profiles,slug,{$this->direction_profile->id}", 'slug' => ['required', 'string', 'max:255', "unique:direction_profiles,slug,{$this->direction_profile->id}",],
'position' => 'required|int|numeric|max:255', 'position' => 'required|int|numeric|max:255',
]; ];
} }
public function messages(): array
{
return [
'position.required' => 'Поле позиция обязательно.',
'position.int' => 'Позиция должно быть целым числом.',
'position.numeric' => 'Позиция должно быть числом.',
'position.max' => 'Позиция не должен быть больше :max',
'name.required' => 'Поле название обязательно.',
'name.string' => 'Поле название должен быть строкой.',
'name.max' => 'Поле название не должен превышать :max символов.',
'name.unique' => 'Название уже занят.',
'description.string' => 'Поле описание должен быть строкой.',
'slug.string' => 'Поле URL должен быть строкой.',
'slug.max' => 'Поле URL не должен превышать :max символов.',
];
}
} }

View File

@ -16,7 +16,7 @@ class UpdateFacultyRequest extends FormRequest
return [ return [
'position' => 'required|int|numeric|max:255', 'position' => 'required|int|numeric|max:255',
'name' => ['required', 'string', 'max:255', "unique:faculties,name,{$this->faculty->id}",], 'name' => ['required', 'string', 'max:255', "unique:faculties,name,{$this->faculty->id}",],
'description' => 'string', 'description' => 'nullable|string',
'slug' => ['required', 'string', 'max:255', "unique:faculties,slug,{$this->faculty->id}",], 'slug' => ['required', 'string', 'max:255', "unique:faculties,slug,{$this->faculty->id}",],
'educational_institution_id' => 'required|int|numeric|max:1000', 'educational_institution_id' => 'required|int|numeric|max:1000',
]; ];

View File

@ -40,4 +40,10 @@ return [
'description' => 'Поле "Описание" может быть пустым для отображения на сайте', 'description' => 'Поле "Описание" может быть пустым для отображения на сайте',
'slug' => 'Поле "URL" нужно для отображения в браузере' 'slug' => 'Поле "URL" нужно для отображения в браузере'
], ],
'direction_profiles' => [
'position' => 'Поле "Позиция" нужно для упорядочивания отображения на сайте',
'name' => 'Поле "Название" должно быть уникальным для отображения на сайте',
'description' => 'Поле "Описание" может быть пустым для отображения на сайте',
'slug' => 'Поле "URL" нужно для отображения в браузере'
]
]; ];

View File

@ -1,59 +1,68 @@
@php use App\Helpers\PositionHelper; @endphp
@extends('layouts.admin_layout') @extends('layouts.admin_layout')
@section('content') @section('content')
@auth() @auth()
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<h1 class=""> Создать Профиль Подготовки</h1> <h1 class=""> Создать Профиль Подготовки</h1>
{{ Form::open(['url' => route('direction_profiles.store'), 'method' => 'POST', 'class' => '']) }} {{ Form::open(['url' => route('direction_profiles.store'), 'method' => 'POST', 'class' => 'needs-validation', 'novalidate']) }}
<div class="col"> <div class="col">
<div class="mt-3"> <div class="mt-3">
{{ Form::label('name', 'Название') }} {{ Form::label('position', 'Позиция', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.position')]) }}
<span class="text-danger">*</span>
</div> </div>
<div class="mt-1"> <div class="mt-1">
{{ Form::text('name', '', ['class' => 'form-control']) }} {{ Form::text('position', PositionHelper::faculty(), ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.position'), 'required']) }}
<div class="invalid-feedback">
Поле "Позиция" обязательно!
</div>
</div> </div>
<div> <div>
@if ($errors->any())
{{ $errors->first('position') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('name', 'Название', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.name')]) }}
<span class="text-danger">*</span>
</div>
<div class="mt-1">
{{ Form::text('name', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.name'), 'required']) }}
<div class="invalid-feedback">
Поле "Название" обязательно!
</div>
</div>
<div class="text-danger">
@if ($errors->any()) @if ($errors->any())
{{ $errors->first('name') }} {{ $errors->first('name') }}
@endif @endif
</div> </div>
<div class="mt-3"> <div class="mt-3">
{{ Form::label('description', 'Описание') }} {{ Form::label('description', 'Описание', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.description')]) }}
</div> </div>
<div class="mt-1"> <div class="mt-1">
{{ Form::text('description', '', ['class' => 'form-control']) }} {{ Form::text('description', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.description')]) }}
</div> </div>
<div> <div class="text-danger">
@if ($errors->any()) @if ($errors->any())
{{ $errors->first('description') }} {{ $errors->first('description') }}
@endif @endif
</div> </div>
<div class="mt-3"> <div class="mt-3">
{{ Form::label('slug', 'URL') }} {{ Form::label('slug', 'URL', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.slug')]) }}
</div> </div>
<div class="mt-1"> <div class="mt-1">
{{ Form::text('slug', '', ['class' => 'form-control']) }} {{ Form::text('slug', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.slug')]) }}
</div> </div>
<div> <div class="text-danger">
@if ($errors->any()) @if ($errors->any())
{{ $errors->first('slug') }} {{ $errors->first('slug') }}
@endif @endif
</div> </div>
<div class="mt-3">
{{ Form::label('position', 'Позиция') }}
</div>
<div class="mt-1">
{{ Form::text('position', '', ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('position') }}
@endif
</div>
<div class="mt-3"> <div class="mt-3">
{{ Form::submit('Создать', ['class' => 'btn btn-primary']) }} {{ Form::submit('Создать', ['class' => 'btn btn-primary']) }}
</div> </div>

View File

@ -4,56 +4,65 @@
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<h1 class="">Изменить Профиль Подготовки</h1> <h1 class="">Изменить Профиль Подготовки</h1>
{{ Form::open(['url' => route('direction_profiles.update', $directionProfile), 'method' => 'PATCH', 'class' => '']) }} {{ Form::open(['url' => route('direction_profiles.update', $directionProfile), 'method' => 'PATCH', 'class' => 'needs-validation', 'novalidate']) }}
<div class="col"> <div class="col">
<div class="mt-3"> <div class="mt-3">
{{ Form::label('name', 'Название') }} {{ Form::label('position', 'Позиция', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.position')]) }}
<span class="text-danger">*</span>
</div> </div>
<div class="mt-1"> <div class="mt-1">
{{ Form::text('name', $directionProfile->name, ['class' => 'form-control']) }} {{ Form::text('position', $directionProfile->position, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.position'), 'required']) }}
<div class="invalid-feedback">
Поле "Позиция" обязательно!
</div> </div>
<div> </div>
<div class="text-danger">
@if ($errors->any())
{{ $errors->first('position') }}
@endif
</div>
<div class="mt-3">
{{ Form::label('name', 'Название', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.name')]) }}
<span class="text-danger">*</span>
</div>
<div class="mt-1">
{{ Form::text('name', $directionProfile->name, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.name'), 'required']) }}
<div class="invalid-feedback">
Поле "Название" обязательно!
</div>
</div>
<div class="text-danger">
@if ($errors->any()) @if ($errors->any())
{{ $errors->first('name') }} {{ $errors->first('name') }}
@endif @endif
</div> </div>
<div class="mt-3"> <div class="mt-3">
{{ Form::label('description', 'Описание') }} {{ Form::label('description', 'Описание', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.description')]) }}
</div> </div>
<div class="mt-1"> <div class="mt-1">
{{ Form::text('description', $directionProfile->description, ['class' => 'form-control']) }} {{ Form::text('description', $directionProfile->description, ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.description')]) }}
</div> </div>
<div> <div class="text-danger">
@if ($errors->any()) @if ($errors->any())
{{ $errors->first('description') }} {{ $errors->first('description') }}
@endif @endif
</div> </div>
<div class="mt-3"> <div class="mt-3">
{{ Form::label('slug', 'URL') }} {{ Form::label('slug', 'URL', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.slug')]) }}
</div> </div>
<div class="mt-1"> <div class="mt-1">
{{ Form::text('slug', $directionProfile->slug, ['class' => 'form-control']) }} {{ Form::text('slug', $directionProfile->slug, ['class' => 'form-control','data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.direction_profiles.slug')]) }}
</div> </div>
<div> <div class="text-danger">
@if ($errors->any()) @if ($errors->any())
{{ $errors->first('slug') }} {{ $errors->first('slug') }}
@endif @endif
</div> </div>
<div class="mt-3">
{{ Form::label('position', 'Позиция') }}
</div>
<div class="mt-1">
{{ Form::text('position', $directionProfile->position, ['class' => 'form-control']) }}
</div>
<div>
@if ($errors->any())
{{ $errors->first('position') }}
@endif
</div>
<div class="mt-3"> <div class="mt-3">
{{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }} {{ Form::submit('Изменить', ['class' => 'btn btn-primary']) }}
</div> </div>

View File

@ -54,7 +54,7 @@
{{ Form::label('slug', 'URL', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.educational_institutions.slug')]) }} {{ Form::label('slug', 'URL', ['data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.educational_institutions.slug')]) }}
</div> </div>
<div class="mt-1"> <div class="mt-1">
{{ Form::text('slug', '', ['class' => 'form-control']) }} {{ Form::text('slug', '', ['class' => 'form-control', 'data-bs-toggle' => "tooltip", 'data-bs-title' => __('tooltips.educational_institutions.slug')]) }}
</div> </div>
<div class="text-danger"> <div class="text-danger">
@if ($errors->any()) @if ($errors->any())