From 422a5872c9b44ac824c51719e745641651a3718f Mon Sep 17 00:00:00 2001 From: aslan Date: Wed, 28 Feb 2024 15:05:41 +0300 Subject: [PATCH] add entrance Examination to store Direction --- .../admin/Catalog/DirectionController.php | 58 ++++- .../admin/Catalog/StoreDirectionRequest.php | 11 +- .../admin/Catalog/UpdateDirectionRequest.php | 6 +- app/Models/Direction.php | 1 + database/factories/DirectionFactory.php | 7 +- ...4_02_09_114155_create_directions_table.php | 1 + database/seeders/DirectionSeeder.php | 3 + .../admin/catalog/direction/create.blade.php | 203 +++++++++++++----- .../admin/catalog/direction/edit.blade.php | 14 +- .../admin/catalog/direction/script.blade.php | 86 ++++++++ 10 files changed, 322 insertions(+), 68 deletions(-) create mode 100644 resources/views/admin/catalog/direction/script.blade.php diff --git a/app/Http/Controllers/admin/Catalog/DirectionController.php b/app/Http/Controllers/admin/Catalog/DirectionController.php index 969add8..be3584d 100644 --- a/app/Http/Controllers/admin/Catalog/DirectionController.php +++ b/app/Http/Controllers/admin/Catalog/DirectionController.php @@ -9,7 +9,11 @@ use App\Models\Department; use App\Models\Direction; use App\Models\EducationForm; use App\Models\EducationLevel; +use App\Models\EntranceExamination; +use App\Models\ExaminationType; use App\Models\Faculty; +use App\Models\Subject; +use App\Models\SubjectType; use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\View; use Illuminate\Foundation\Application; @@ -28,15 +32,19 @@ class DirectionController extends Controller $levels = EducationLevel::pluck('name', 'id'); $forms = EducationForm::pluck('name', 'id'); $departments = Department::pluck('name', 'id'); - return view('admin.catalog.direction.create', compact('departments', 'levels', 'forms')); + $examination_types = ExaminationType::pluck('name', 'id'); + $subjects = Subject::pluck('name', 'id'); + $subjectTypes = SubjectType::pluck('name', 'id'); + return view('admin.catalog.direction.create', + compact('departments', 'levels', 'forms', 'examination_types', 'subjectTypes', 'subjects')); } public function store(StoreDirectionRequest $request): RedirectResponse { $validated = $request->validated(); - $direction = new Direction(); $direction->name = $validated['name']; + $direction->full_name = "{$validated['code']} {$validated['name']}"; $direction->description = $validated['description']; $direction->position = $validated['position']; $direction->slug = $validated['slug']; @@ -46,6 +54,19 @@ class DirectionController extends Controller $direction->department_id = $validated['department_id']; $direction->save(); + if(array_key_exists('entrance-examination', $validated)) { + foreach ($validated['entrance-examination'] as $data) { + $entranceExamination = new EntranceExamination(); + $entranceExamination->examination_type_id = $data['examination_type_id']; + $entranceExamination->direction_id = $direction->id; + $entranceExamination->subject_id = $data['subject_id']; + $entranceExamination->scores = $data['scores']; + $entranceExamination->position = $data['position']; + $entranceExamination->subject_type_id = $data['subject_type_id']; + $entranceExamination->save(); + } + } + return redirect()->route('directions.index'); } @@ -55,17 +76,38 @@ class DirectionController extends Controller $faculty = Faculty::find($department->faculty->id); $educationalInstitution = $faculty->educationalInstitution; - $ege = $direction->entranceExaminations->where('examination_type_id', '=', '1')->pluck('scores', 'subject_id'); - $spo = $direction->entranceExaminations->where('examination_type_id', '=', '2')->pluck('scores', 'subject_id'); + $ege = $direction + ->entranceExaminations + ->where('examination_type_id', '=', '1') + ->sortBy('position') + ->pluck('scores', 'subject_id'); + + $spo = $direction + ->entranceExaminations->where('examination_type_id', '=', '2') + ->sortBy('position') + ->pluck('scores', 'subject_id'); + $magistracy = $direction ->entranceExaminations ->where('examination_type_id', '=', '3') ->pluck('scores', 'subject_id'); - $budget = $direction->places->where('place_type_id', '=', '1')->pluck('amount', 'education_form_id'); - $paid = $direction->places->where('place_type_id', '=', '2')->pluck('amount', 'education_form_id'); + $budget = $direction + ->places + ->where('place_type_id', '=', '1') + ->sortBy('position') + ->pluck('amount', 'education_form_id'); - $costs = $direction->costs->pluck('cost', 'education_form_id'); + $paid = $direction + ->places + ->where('place_type_id', '=', '2') + ->sortBy('position') + ->pluck('amount', 'education_form_id'); + + $costs = $direction + ->costs + ->sortBy('position') + ->pluck('cost', 'education_form_id'); return view( 'admin.catalog.direction.show', @@ -96,8 +138,8 @@ class DirectionController extends Controller { $validated = $request->validated(); - $direction = new Direction(); $direction->name = $validated['name']; + $direction->full_name = "{$validated['code']} {$validated['name']}"; $direction->description = $validated['description']; $direction->position = $validated['position']; $direction->slug = $validated['slug']; diff --git a/app/Http/Requests/admin/Catalog/StoreDirectionRequest.php b/app/Http/Requests/admin/Catalog/StoreDirectionRequest.php index b78c4e5..27d05a4 100644 --- a/app/Http/Requests/admin/Catalog/StoreDirectionRequest.php +++ b/app/Http/Requests/admin/Catalog/StoreDirectionRequest.php @@ -15,13 +15,18 @@ class StoreDirectionRequest extends FormRequest { return [ 'position' => 'required|int|numeric|max:255', - 'name' => 'required|string|max:255|unique:directions,name', + 'name' => 'required|string|max:255', 'description' => 'string', 'slug' => 'required|string|max:255|unique:directions,slug', - 'code' => 'required|string|max:255', + 'code' => 'required|string|max:255|unique:directions,code', 'education_level_id' => 'required|int|numeric|max:1000', 'education_form_id' => 'required|int|numeric|max:1000', - 'department_id' => 'required|numeric|int|max:1000' + 'department_id' => 'required|numeric|int|max:1000', + 'entrance-examination.*.examination_type_id' => 'required|numeric|int|max:1000', + 'entrance-examination.*.subject_id' => 'required|numeric|int|max:1000', + 'entrance-examination.*.subject_type_id' => 'required|numeric|int|max:1000', + 'entrance-examination.*.scores' => 'required|numeric|int|max:1000', + 'entrance-examination.*.position' => 'required|numeric|int|max:1000', ]; } } diff --git a/app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php b/app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php index d9e862b..ad6d87f 100644 --- a/app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php +++ b/app/Http/Requests/admin/Catalog/UpdateDirectionRequest.php @@ -24,14 +24,14 @@ class UpdateDirectionRequest extends FormRequest 'max:255', "unique:directions,slug,{$this->direction->id}", ], - 'code' => 'required|string|max:255', + 'name' => 'required|string|max:255', 'education_level_id' => 'required|int|numeric|max:1000', 'education_form_id' => 'required|int|numeric|max:1000', - 'name' => [ + 'code' => [ 'required', 'string', 'max:255', - "unique:directions,name,{$this->direction->id}", + "unique:directions,code,{$this->direction->id}", ], ]; } diff --git a/app/Models/Direction.php b/app/Models/Direction.php index 082638e..7ece0d1 100644 --- a/app/Models/Direction.php +++ b/app/Models/Direction.php @@ -14,6 +14,7 @@ class Direction extends Model protected $fillable = [ 'id', 'name', + 'full_name', 'description', 'position', 'slug', diff --git a/database/factories/DirectionFactory.php b/database/factories/DirectionFactory.php index a66584a..57ad9c5 100644 --- a/database/factories/DirectionFactory.php +++ b/database/factories/DirectionFactory.php @@ -8,11 +8,14 @@ class DirectionFactory extends Factory { public function definition(): array { + $name = fake()->name(); + $code = fake()->text(10); return [ - 'name' => fake()->name(), + 'name' => $name, + 'full_name' => "{$code} {$name}", 'description' => fake()->text(), 'slug' => fake()->slug(), - 'code' => fake()->text(50), + 'code' => $code, 'position' => fake()->randomDigit(), 'department_id' => 1, 'education_level_id' => 1, diff --git a/database/migrations/2024_02_09_114155_create_directions_table.php b/database/migrations/2024_02_09_114155_create_directions_table.php index 63d2318..6e2cc3c 100644 --- a/database/migrations/2024_02_09_114155_create_directions_table.php +++ b/database/migrations/2024_02_09_114155_create_directions_table.php @@ -11,6 +11,7 @@ return new class extends Migration Schema::create('directions', function (Blueprint $table) { $table->id(); $table->string('name'); + $table->string('full_name'); $table->text('description')->nullable(); $table->string('code'); $table->integer('position'); diff --git a/database/seeders/DirectionSeeder.php b/database/seeders/DirectionSeeder.php index 7938a5a..b2bf20e 100644 --- a/database/seeders/DirectionSeeder.php +++ b/database/seeders/DirectionSeeder.php @@ -13,6 +13,7 @@ class DirectionSeeder extends Seeder DB::table('directions')->insert([ [ 'name' => 'Юриспруденция', + 'full_name' => '40.03.01 Юриспруденция', 'description' => 'Юриспруденция', 'slug' => 'jurisprudence', 'code' => '40.03.01', @@ -23,6 +24,7 @@ class DirectionSeeder extends Seeder ], [ 'name' => 'фармация', + 'full_name' => '33.05.01 фармация', 'description' => 'фармация', 'slug' => 'pharmacy', 'code' => '33.05.01', @@ -33,6 +35,7 @@ class DirectionSeeder extends Seeder ], [ 'name' => 'строительство', + 'full_name' => '08.04.01 строительство', 'description' => 'строительство', 'slug' => 'construction', 'code' => '08.04.01', diff --git a/resources/views/admin/catalog/direction/create.blade.php b/resources/views/admin/catalog/direction/create.blade.php index e14aa6c..cebd615 100644 --- a/resources/views/admin/catalog/direction/create.blade.php +++ b/resources/views/admin/catalog/direction/create.blade.php @@ -1,46 +1,74 @@ @extends('layouts.admin_layout') @section('content') @auth() +

Создать Направление

+ {{ Form::open(['url' => route('directions.store'), 'method' => 'POST', 'class' => '']) }}
-

Создать Направление

- {{ Form::open(['url' => route('directions.store'), 'method' => 'POST', 'class' => '']) }} +
+ {{ Form::label('position', 'Позиция') }} +
+
+ {{ Form::number('position', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('position') }} + @endif +
+
+
+
+ {{ Form::label('code', 'Код') }} +
+
+ {{ Form::text('code', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('code') }} + @endif +
+
+
+
+ {{ Form::label('slug', 'URL') }} +
+
+ {{ Form::text('slug', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('slug') }} + @endif +
+
+ +
+ {{ Form::label('name', 'Название') }} +
+
+ {{ Form::text('name', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('name') }} + @endif +
+ +
+ {{ Form::label('description', 'Описание') }} +
+
+ {{ Form::text('description', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('description') }} + @endif +
+
-
- {{ Form::label('position', 'Позиция') }} -
-
- {{ Form::text('position', '', ['class' => 'form-control']) }} -
-
- @if ($errors->any()) - {{ $errors->first('position') }} - @endif -
- -
- {{ Form::label('code', 'Название') }} -
-
- {{ Form::text('code', '', ['class' => 'form-control']) }} -
-
- @if ($errors->any()) - {{ $errors->first('code') }} - @endif -
- -
- {{ Form::label('description', 'Описание') }} -
-
- {{ Form::text('description', '', ['class' => 'form-control']) }} -
-
- @if ($errors->any()) - {{ $errors->first('description') }} - @endif -
{{ Form::label('department_id', 'Кафедра') }}
@@ -52,7 +80,8 @@ {{ $errors->first('department_id') }} @endif
- +
+
{{ Form::label('education_level_id', 'Увовень образования') }}
@@ -64,9 +93,10 @@ {{ $errors->first('education_level_id') }} @endif
- +
+
- {{ Form::label('education_form_id', 'Увовень образования') }} + {{ Form::label('education_form_id', 'Форма образования') }}
{{ Form::select('education_form_id', $forms, null, ['class' => 'form-select']) }} @@ -76,24 +106,95 @@ {{ $errors->first('education_form_id') }} @endif
+
+ -
- {{ Form::label('slug', 'URL') }} + +

Добавить вступительные испытания

+ +
+
+
+
+ {{ Form::label('entrance-examination[0][examination_type_id]', 'Тип экзамена') }} +
+
+ {{ Form::select('entrance-examination[0][examination_type_id]', $examination_types, null, ['class' => 'form-select']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('entrance-examination[0][examination_type_id]') }} + @endif +
-
- {{ Form::text('slug', '', ['class' => 'form-control']) }} +
+
+ {{ Form::label('entrance-examination[0][subject_id]', 'Предмет') }} +
+
+ {{ Form::select('entrance-examination[0][subject_id]', $subjects, null, ['class' => 'form-select']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('entrance-examination[0][subject_id]') }} + @endif +
-
- @if ($errors->any()) - {{ $errors->first('slug') }} - @endif +
+
+ {{ Form::label('entrance-examination[0][subject_type_id]', 'Тип предмета') }} +
+
+ {{ Form::select('entrance-examination[0][subject_type_id]', $subjectTypes, null, ['class' => 'form-select']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('entrance-examination[0][subject_type_id]') }} + @endif +
-
- {{ Form::submit('Создать', ['class' => 'btn btn-primary']) }} +
+
+ {{ Form::label('entrance-examination[0][scores]', 'Кол-во баллов') }} +
+
+ {{ Form::text('entrance-examination[0][scores]', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('entrance-examination[0][scores]') }} + @endif +
+
+
+
+ {{ Form::label('entrance-examination[0][position]', 'Позиция') }} +
+
+ {{ Form::text('entrance-examination[0][position]', '', ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('entrance-examination[0][position]') }} + @endif +
+
+
+
+ {{ Form::label('btn', 'Действия') }} +
+
- {{ Form::close() }}
+
+ {{ Form::submit('Создать Направление', ['class' => 'btn btn-primary']) }} +
+ {{ Form::close() }}
+ @include('admin.catalog.direction.script') @endauth @endsection + + diff --git a/resources/views/admin/catalog/direction/edit.blade.php b/resources/views/admin/catalog/direction/edit.blade.php index 53fd77c..9715b23 100644 --- a/resources/views/admin/catalog/direction/edit.blade.php +++ b/resources/views/admin/catalog/direction/edit.blade.php @@ -5,7 +5,7 @@

Изменить направление

- {{ Form::open(['url' => route('departments.update', $direction), 'method' => 'PATCH', 'class' => '']) }} + {{ Form::open(['url' => route('directions.update', $direction), 'method' => 'PATCH', 'class' => '']) }}
{{ Form::label('position', 'Позиция') }} @@ -19,6 +19,18 @@ @endif
+
+ {{ Form::label('code', 'Код') }} +
+
+ {{ Form::text('code', $direction->code, ['class' => 'form-control']) }} +
+
+ @if ($errors->any()) + {{ $errors->first('code') }} + @endif +
+
{{ Form::label('name', 'Название') }}
diff --git a/resources/views/admin/catalog/direction/script.blade.php b/resources/views/admin/catalog/direction/script.blade.php new file mode 100644 index 0000000..960b1aa --- /dev/null +++ b/resources/views/admin/catalog/direction/script.blade.php @@ -0,0 +1,86 @@ +