2024-02-10 11:23:38 +03:00
|
|
|
<?php
|
|
|
|
|
2024-02-12 10:58:48 +03:00
|
|
|
namespace App\Http\Controllers\admin\Catalog;
|
2024-02-10 11:23:38 +03:00
|
|
|
|
2024-03-04 09:53:33 +03:00
|
|
|
use App\Enums\ExaminationTypeEnum;
|
2024-02-10 11:23:38 +03:00
|
|
|
use App\Http\Controllers\Controller;
|
2024-02-12 10:58:48 +03:00
|
|
|
use App\Http\Requests\admin\Catalog\StoreDirectionRequest;
|
|
|
|
use App\Http\Requests\admin\Catalog\UpdateDirectionRequest;
|
2024-02-10 11:23:38 +03:00
|
|
|
use App\Models\Department;
|
|
|
|
use App\Models\Direction;
|
2024-02-29 18:00:50 +03:00
|
|
|
use App\Models\DirectionProfile;
|
2024-02-15 09:58:01 +03:00
|
|
|
use App\Models\EducationForm;
|
2024-02-14 16:16:44 +03:00
|
|
|
use App\Models\EducationLevel;
|
2024-02-28 15:05:41 +03:00
|
|
|
use App\Models\EntranceExamination;
|
|
|
|
use App\Models\ExaminationType;
|
2024-02-12 11:25:00 +03:00
|
|
|
use App\Models\Faculty;
|
2024-02-28 15:05:41 +03:00
|
|
|
use App\Models\Subject;
|
|
|
|
use App\Models\SubjectType;
|
2024-02-10 11:23:38 +03:00
|
|
|
use Illuminate\Contracts\View\Factory;
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
|
|
use Illuminate\Foundation\Application;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
|
|
|
|
class DirectionController extends Controller
|
|
|
|
{
|
|
|
|
public function index(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
|
|
|
{
|
|
|
|
$directions = Direction::all();
|
2024-02-12 10:58:48 +03:00
|
|
|
return view('admin.catalog.direction.index', compact('directions'));
|
2024-02-10 11:23:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function create(): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
|
|
|
{
|
2024-02-14 16:16:44 +03:00
|
|
|
$levels = EducationLevel::pluck('name', 'id');
|
2024-02-15 09:58:01 +03:00
|
|
|
$forms = EducationForm::pluck('name', 'id');
|
2024-02-10 11:23:38 +03:00
|
|
|
$departments = Department::pluck('name', 'id');
|
2024-02-28 15:05:41 +03:00
|
|
|
$examination_types = ExaminationType::pluck('name', 'id');
|
|
|
|
$subjects = Subject::pluck('name', 'id');
|
|
|
|
$subjectTypes = SubjectType::pluck('name', 'id');
|
2024-02-29 18:00:50 +03:00
|
|
|
$directionProfiles = DirectionProfile::pluck('name', 'id');
|
2024-02-28 15:05:41 +03:00
|
|
|
return view('admin.catalog.direction.create',
|
2024-02-29 18:00:50 +03:00
|
|
|
compact(
|
|
|
|
'departments',
|
|
|
|
'levels',
|
|
|
|
'forms',
|
|
|
|
'examination_types',
|
|
|
|
'subjectTypes',
|
|
|
|
'subjects',
|
|
|
|
'directionProfiles',
|
|
|
|
)
|
|
|
|
);
|
2024-02-10 11:23:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function store(StoreDirectionRequest $request): RedirectResponse
|
|
|
|
{
|
2024-02-29 18:00:50 +03:00
|
|
|
|
2024-02-10 11:23:38 +03:00
|
|
|
$validated = $request->validated();
|
|
|
|
$direction = new Direction();
|
|
|
|
$direction->name = $validated['name'];
|
2024-02-28 15:05:41 +03:00
|
|
|
$direction->full_name = "{$validated['code']} {$validated['name']}";
|
2024-02-10 11:23:38 +03:00
|
|
|
$direction->description = $validated['description'];
|
|
|
|
$direction->position = $validated['position'];
|
|
|
|
$direction->slug = $validated['slug'];
|
2024-02-14 16:16:44 +03:00
|
|
|
$direction->code = $validated['code'];
|
|
|
|
$direction->education_level_id = $validated['education_level_id'];
|
2024-02-15 09:58:01 +03:00
|
|
|
$direction->education_form_id = $validated['education_form_id'];
|
2024-02-10 11:23:38 +03:00
|
|
|
$direction->department_id = $validated['department_id'];
|
2024-02-29 18:00:50 +03:00
|
|
|
$direction->budget_places = $validated['budget_places'];
|
|
|
|
$direction->quota = $validated['quota'];
|
|
|
|
$direction->paid_places = $validated['paid_places'];
|
|
|
|
$direction->cost_paid_place = $validated['cost_paid_place'];
|
|
|
|
$direction->period = $validated['period'];
|
2024-02-10 11:23:38 +03:00
|
|
|
$direction->save();
|
|
|
|
|
2024-02-29 18:00:50 +03:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (array_key_exists('direction_profiles', $validated)) {
|
|
|
|
$direction->directionProfiles()->attach($validated['direction_profiles']);
|
2024-02-28 15:05:41 +03:00
|
|
|
}
|
|
|
|
|
2024-02-10 11:23:38 +03:00
|
|
|
return redirect()->route('directions.index');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function show(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
|
|
|
{
|
2024-02-12 11:25:00 +03:00
|
|
|
$department = $direction->department;
|
|
|
|
$faculty = Faculty::find($department->faculty->id);
|
|
|
|
$educationalInstitution = $faculty->educationalInstitution;
|
2024-02-26 14:20:16 +03:00
|
|
|
|
2024-02-28 15:05:41 +03:00
|
|
|
$ege = $direction
|
|
|
|
->entranceExaminations
|
2024-03-04 09:53:33 +03:00
|
|
|
->where('examination_type_id', '=', ExaminationTypeEnum::Ege->value)
|
2024-02-28 15:05:41 +03:00
|
|
|
->sortBy('position')
|
|
|
|
->pluck('scores', 'subject_id');
|
|
|
|
|
|
|
|
$spo = $direction
|
2024-03-04 09:53:33 +03:00
|
|
|
->entranceExaminations->where('examination_type_id', '=', ExaminationTypeEnum::Spo->value)
|
2024-02-28 15:05:41 +03:00
|
|
|
->sortBy('position')
|
|
|
|
->pluck('scores', 'subject_id');
|
|
|
|
|
2024-02-26 14:20:16 +03:00
|
|
|
$magistracy = $direction
|
|
|
|
->entranceExaminations
|
2024-03-04 09:53:33 +03:00
|
|
|
->where('examination_type_id', '=', ExaminationTypeEnum::Magistracy->value)
|
2024-03-04 08:56:42 +03:00
|
|
|
->sortBy('position')
|
2024-02-26 14:20:16 +03:00
|
|
|
->pluck('scores', 'subject_id');
|
|
|
|
|
2024-02-12 11:25:00 +03:00
|
|
|
return view(
|
|
|
|
'admin.catalog.direction.show',
|
|
|
|
compact(
|
|
|
|
'direction',
|
|
|
|
'educationalInstitution',
|
|
|
|
'faculty',
|
|
|
|
'department',
|
2024-02-26 14:20:16 +03:00
|
|
|
'ege',
|
|
|
|
'spo',
|
|
|
|
'magistracy',
|
2024-02-12 11:25:00 +03:00
|
|
|
)
|
|
|
|
);
|
2024-02-10 11:23:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function edit(Direction $direction): View|Application|Factory|\Illuminate\Contracts\Foundation\Application
|
|
|
|
{
|
2024-02-14 16:16:44 +03:00
|
|
|
$levels = EducationLevel::pluck('name', 'id');
|
2024-02-15 09:58:01 +03:00
|
|
|
$forms = EducationForm::pluck('name', 'id');
|
2024-02-29 18:00:50 +03:00
|
|
|
$departments = Department::pluck('name', 'id');
|
|
|
|
$examination_types = ExaminationType::pluck('name', 'id');
|
|
|
|
$subjects = Subject::pluck('name', 'id');
|
|
|
|
$subjectTypes = SubjectType::pluck('name', 'id');
|
|
|
|
$directionProfiles = DirectionProfile::pluck('name', 'id');
|
|
|
|
return view('admin.catalog.direction.edit',
|
|
|
|
compact(
|
|
|
|
'direction',
|
|
|
|
'departments',
|
|
|
|
'levels',
|
|
|
|
'forms',
|
|
|
|
'examination_types',
|
|
|
|
'subjectTypes',
|
|
|
|
'subjects',
|
|
|
|
'directionProfiles',
|
|
|
|
)
|
|
|
|
);
|
2024-02-10 11:23:38 +03:00
|
|
|
}
|
|
|
|
|
2024-02-12 10:58:48 +03:00
|
|
|
public function update(UpdateDirectionRequest $request, Direction $direction): RedirectResponse
|
2024-02-10 11:23:38 +03:00
|
|
|
{
|
|
|
|
$validated = $request->validated();
|
|
|
|
$direction->name = $validated['name'];
|
2024-02-28 15:05:41 +03:00
|
|
|
$direction->full_name = "{$validated['code']} {$validated['name']}";
|
2024-02-10 11:23:38 +03:00
|
|
|
$direction->description = $validated['description'];
|
|
|
|
$direction->position = $validated['position'];
|
2024-02-12 10:58:48 +03:00
|
|
|
$direction->slug = $validated['slug'];
|
2024-02-14 16:16:44 +03:00
|
|
|
$direction->code = $validated['code'];
|
|
|
|
$direction->education_level_id = $validated['education_level_id'];
|
2024-02-15 09:58:01 +03:00
|
|
|
$direction->education_form_id = $validated['education_form_id'];
|
2024-02-10 11:23:38 +03:00
|
|
|
$direction->department_id = $validated['department_id'];
|
2024-03-04 08:56:42 +03:00
|
|
|
$direction->budget_places = $validated['budget_places'];
|
|
|
|
$direction->quota = $validated['quota'];
|
|
|
|
$direction->paid_places = $validated['paid_places'];
|
|
|
|
$direction->cost_paid_place = $validated['cost_paid_place'];
|
|
|
|
$direction->period = $validated['period'];
|
2024-02-10 11:23:38 +03:00
|
|
|
$direction->save();
|
|
|
|
|
2024-03-04 08:56:42 +03:00
|
|
|
if (array_key_exists('entrance-examination', $validated)) {
|
|
|
|
foreach ($validated['entrance-examination'] as $id => $data) {
|
|
|
|
$entranceExamination = EntranceExamination::firstOrNew(['id' => $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->examination_type_id = $data['examination_type_id'];
|
|
|
|
$entranceExamination->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// dd($validated);
|
|
|
|
if (array_key_exists('delete', $validated)) {
|
|
|
|
foreach ($validated['delete'] as $id => $value) {
|
|
|
|
$entranceExamination = EntranceExamination::firstOrNew(['id' => $id]);
|
|
|
|
$entranceExamination->delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (array_key_exists('direction_profiles', $validated)) {
|
|
|
|
$direction->directionProfiles()->sync($validated['direction_profiles']);
|
|
|
|
}
|
|
|
|
|
2024-02-10 11:23:38 +03:00
|
|
|
return redirect()->route('directions.index');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function destroy(Direction $direction): RedirectResponse
|
|
|
|
{
|
2024-02-19 10:51:20 +03:00
|
|
|
if ($direction->entranceExaminations()->exists()) {
|
|
|
|
return back();
|
|
|
|
}
|
2024-03-04 09:53:33 +03:00
|
|
|
$direction->directionProfiles()->detach();
|
2024-02-10 11:23:38 +03:00
|
|
|
$direction->delete();
|
|
|
|
return redirect()->route('directions.index');
|
|
|
|
}
|
2024-03-04 09:53:33 +03:00
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
2024-02-10 11:23:38 +03:00
|
|
|
}
|