Compare commits

...

2 Commits

Author SHA1 Message Date
aslan d0a9dcae2b lint fix
Tests & Lint & Deploy to Railway / build (2.6.6, 20.x, 8.3) (push) Failing after 2m24s Details
Tests & Lint & Deploy to Railway / deploy (push) Has been skipped Details
2024-03-04 09:54:14 +03:00
aslan 435ad06dca add duplication at Direction 2024-03-04 09:53:33 +03:00
7 changed files with 68 additions and 13 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; namespace App\Http\Controllers\admin\Catalog;
use App\Enums\ExaminationTypeEnum;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Http\Requests\admin\Catalog\StoreDirectionRequest; use App\Http\Requests\admin\Catalog\StoreDirectionRequest;
use App\Http\Requests\admin\Catalog\UpdateDirectionRequest; use App\Http\Requests\admin\Catalog\UpdateDirectionRequest;
@ -37,7 +38,8 @@ class DirectionController extends Controller
$subjects = Subject::pluck('name', 'id'); $subjects = Subject::pluck('name', 'id');
$subjectTypes = SubjectType::pluck('name', 'id'); $subjectTypes = SubjectType::pluck('name', 'id');
$directionProfiles = DirectionProfile::pluck('name', 'id'); $directionProfiles = DirectionProfile::pluck('name', 'id');
return view('admin.catalog.direction.create', return view(
'admin.catalog.direction.create',
compact( compact(
'departments', 'departments',
'levels', 'levels',
@ -98,18 +100,18 @@ class DirectionController extends Controller
$ege = $direction $ege = $direction
->entranceExaminations ->entranceExaminations
->where('examination_type_id', '=', '1') ->where('examination_type_id', '=', ExaminationTypeEnum::Ege->value)
->sortBy('position') ->sortBy('position')
->pluck('scores', 'subject_id'); ->pluck('scores', 'subject_id');
$spo = $direction $spo = $direction
->entranceExaminations->where('examination_type_id', '=', '2') ->entranceExaminations->where('examination_type_id', '=', ExaminationTypeEnum::Spo->value)
->sortBy('position') ->sortBy('position')
->pluck('scores', 'subject_id'); ->pluck('scores', 'subject_id');
$magistracy = $direction $magistracy = $direction
->entranceExaminations ->entranceExaminations
->where('examination_type_id', '=', '3') ->where('examination_type_id', '=', ExaminationTypeEnum::Magistracy->value)
->sortBy('position') ->sortBy('position')
->pluck('scores', 'subject_id'); ->pluck('scores', 'subject_id');
@ -136,7 +138,8 @@ class DirectionController extends Controller
$subjects = Subject::pluck('name', 'id'); $subjects = Subject::pluck('name', 'id');
$subjectTypes = SubjectType::pluck('name', 'id'); $subjectTypes = SubjectType::pluck('name', 'id');
$directionProfiles = DirectionProfile::pluck('name', 'id'); $directionProfiles = DirectionProfile::pluck('name', 'id');
return view('admin.catalog.direction.edit', return view(
'admin.catalog.direction.edit',
compact( compact(
'direction', 'direction',
'departments', 'departments',
@ -203,10 +206,45 @@ class DirectionController extends Controller
if ($direction->entranceExaminations()->exists()) { if ($direction->entranceExaminations()->exists()) {
return back(); return back();
} }
if ($direction->places()->exists()) { $direction->directionProfiles()->detach();
return back();
}
$direction->delete(); $direction->delete();
return redirect()->route('directions.index'); 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', 'name' => 'required|string|max:255',
'description' => 'string', 'description' => 'string',
'slug' => 'required|string|max:255|unique:directions,slug', '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_level_id' => 'required|int|numeric|max:1000',
'education_form_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',

View File

@ -19,7 +19,7 @@ class UpdateDirectionRequest extends FormRequest
'name' => 'required|string|max:255', 'name' => 'required|string|max:255',
'description' => 'string', 'description' => 'string',
'slug' => "required|string|max:255|unique:directions,slug,{$this->direction->id}", '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_level_id' => 'required|int|numeric|max:1000',
'education_form_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',

View File

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

View File

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

View File

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