add duplication at Direction

This commit is contained in:
aslan 2024-03-04 09:53:33 +03:00
parent 86597ad075
commit 435ad06dca
7 changed files with 64 additions and 11 deletions

View File

@ -0,0 +1,10 @@
<?php
namespace App\Enums;
enum ExaminationTypeEnum: int
{
case Ege = 1;
case Spo = 2;
case Magistracy = 3;
}

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers\admin\Catalog;
use App\Enums\ExaminationTypeEnum;
use App\Http\Controllers\Controller;
use App\Http\Requests\admin\Catalog\StoreDirectionRequest;
use App\Http\Requests\admin\Catalog\UpdateDirectionRequest;
@ -98,18 +99,18 @@ class DirectionController extends Controller
$ege = $direction
->entranceExaminations
->where('examination_type_id', '=', '1')
->where('examination_type_id', '=', ExaminationTypeEnum::Ege->value)
->sortBy('position')
->pluck('scores', 'subject_id');
$spo = $direction
->entranceExaminations->where('examination_type_id', '=', '2')
->entranceExaminations->where('examination_type_id', '=', ExaminationTypeEnum::Spo->value)
->sortBy('position')
->pluck('scores', 'subject_id');
$magistracy = $direction
->entranceExaminations
->where('examination_type_id', '=', '3')
->where('examination_type_id', '=', ExaminationTypeEnum::Magistracy->value)
->sortBy('position')
->pluck('scores', 'subject_id');
@ -203,10 +204,45 @@ class DirectionController extends Controller
if ($direction->entranceExaminations()->exists()) {
return back();
}
if ($direction->places()->exists()) {
return back();
}
$direction->directionProfiles()->detach();
$direction->delete();
return redirect()->route('directions.index');
}
public function duplication(Direction $direction): RedirectResponse
{
$now = now()->toAtomString();
$newDirection = new Direction();
$newDirection->name = $direction->name;
$newDirection->full_name = "{$direction->code} {$direction->name}";
$newDirection->description = $direction->description;
$newDirection->position = $direction->position;
$newDirection->slug = "{$direction->slug} {$now}";
$newDirection->code = $direction->code;
$newDirection->education_level_id = $direction->education_level_id;
$newDirection->education_form_id = $direction->education_form_id;
$newDirection->department_id = $direction->department_id;
$newDirection->budget_places = $direction->budget_places;
$newDirection->quota = $direction->quota;
$newDirection->paid_places = $direction->paid_places;
$newDirection->cost_paid_place = $direction->cost_paid_place;
$newDirection->period = $direction->period;
$newDirection->save();
foreach ($direction->entranceExaminations as $entranceExamination) {
$newEntranceExamination = new EntranceExamination();
$newEntranceExamination->examination_type_id = $entranceExamination->examination_type_id;
$newEntranceExamination->direction_id = $newDirection->id;
$newEntranceExamination->subject_id = $entranceExamination->subject_id;
$newEntranceExamination->scores = $entranceExamination->scores;
$newEntranceExamination->position = $entranceExamination->position;
$newEntranceExamination->subject_type_id = $entranceExamination->subject_type_id;
$newEntranceExamination->save();
}
$newDirection->directionProfiles()->attach($direction->directionProfiles);
return redirect()->route('directions.index');
}
}

View File

@ -18,7 +18,7 @@ class StoreDirectionRequest extends FormRequest
'name' => 'required|string|max:255',
'description' => 'string',
'slug' => 'required|string|max:255|unique:directions,slug',
'code' => 'required|string|max:255|unique:directions,code',
'code' => 'required|string|max:255',
'education_level_id' => 'required|int|numeric|max:1000',
'education_form_id' => 'required|int|numeric|max:1000',
'department_id' => 'required|numeric|int|max:1000',

View File

@ -19,7 +19,7 @@ class UpdateDirectionRequest extends FormRequest
'name' => 'required|string|max:255',
'description' => 'string',
'slug' => "required|string|max:255|unique:directions,slug,{$this->direction->id}",
'code' => "required|string|max:255|unique:directions,code,{$this->direction->id}",
'code' => "required|string|max:255",
'education_level_id' => 'required|int|numeric|max:1000',
'education_form_id' => 'required|int|numeric|max:1000',
'department_id' => 'required|numeric|int|max:1000',

View File

@ -2,6 +2,7 @@
namespace Database\Seeders;
use App\Enums\ExaminationTypeEnum;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
@ -14,19 +15,19 @@ class ExaminationTypeSeeder extends Seeder
[
'name' => 'ЕГЭ',
'description' => 'Unified State Examination',
'position' => '1',
'position' => ExaminationTypeEnum::Ege->value,
'slug' => 'USE',
],
[
'name' => 'СПО',
'description' => 'secondary vocational education',
'position' => '2',
'position' => ExaminationTypeEnum::Spo->value,
'slug' => 'SVE',
],
[
'name' => 'магитсратура',
'description' => 'type magistracy',
'position' => '3',
'position' => ExaminationTypeEnum::Magistracy->value,
'slug' => 'MAG',
],
]);

View File

@ -32,6 +32,9 @@
<td>
<a href="{{ route("directions.edit", $direction) }}"
class="btn btn-secondary">редактировать</a>
<a rel="nofollow" data-method="post"
href="{{ route('directions.duplication', $direction->id) }}"
class="btn btn-warning">Дублировать</a>
<a rel="nofollow" data-method="delete" data-confirm="Вы действительно хотите удалить?"
href="{{ route('directions.destroy', $direction) }}"
class="btn btn-danger">удалить</a>

View File

@ -32,6 +32,9 @@ Route::middleware(['auth', 'verified'])->prefix('admin')->group(function () {
Route::resource('/directions', DirectionController::class)
->scoped(['direction' => 'slug']);
Route::post('/directions.duplication/{direction}', [DirectionController::class, 'duplication'])
->name('directions.duplication');
Route::resource('/departments', DepartmentController::class)
->scoped(['department' => 'slug']);
Route::resource('/faculties', FacultyController::class)