Roman_applicant-site/app/Http/Controllers/Api/CalculatorController.php

147 lines
9.5 KiB
PHP
Raw Normal View History

2024-03-07 13:58:54 +03:00
<?php
namespace App\Http\Controllers\Api;
use App\Enums\ExaminationTypeEnum;
2024-03-07 13:58:54 +03:00
use App\Http\Controllers\Controller;
2024-03-07 15:09:01 +03:00
use App\Models\Department;
2024-03-07 13:58:54 +03:00
use App\Models\Direction;
use App\Models\EntranceExamination;
2024-03-07 15:09:01 +03:00
use App\Models\Faculty;
2024-03-07 13:58:54 +03:00
use Illuminate\Http\Request;
2024-03-14 13:11:18 +03:00
use Illuminate\Support\Facades\URL;
2024-03-07 13:58:54 +03:00
class CalculatorController extends Controller
{
public function findDirectionFromSubjects(Request $request)
{
2024-03-07 15:09:01 +03:00
$getJSON = $request->input()['predmets'];
$calcultatorSubjects = json_decode($getJSON);
2024-03-07 15:09:01 +03:00
$filteredDirectionIds = EntranceExamination::all()
->select("direction_id", "subject_id", "subject_type_id", "examination_type_id")
->where('examination_type_id', '=', ExaminationTypeEnum::Ege->value)
->reduce(function (array $carry, $examine) {
[
'direction_id' => $direction_id,
'subject_id' => $subject_id,
'subject_type_id' => $subject_type_id
] = $examine;
$carry[$direction_id][$subject_type_id][] = $subject_id;
$carry[$direction_id][$subject_type_id] = array_unique($carry[$direction_id][$subject_type_id]);
return $carry;
}, []);
$result = collect($filteredDirectionIds)
->filter(function ($subjectTypes) use ($calcultatorSubjects) {
$requiredSubjects = $subjectTypes[1];
return array_reduce($requiredSubjects, function ($acc, $requiredSubjects) use ($calcultatorSubjects) {
if (!in_array($requiredSubjects, $calcultatorSubjects)) {
return false;
}
return $acc;
}, true);
})
->filter(function ($subjectTypes) use ($calcultatorSubjects) {
if (array_key_exists(2, $subjectTypes)) {
$optionalSubjectsInCalculator = collect($subjectTypes[2])
->filter(fn($optionalSubject) => in_array($optionalSubject, $calcultatorSubjects));
return $optionalSubjectsInCalculator->count() !== 0;
}
return true;
})->map(fn($subjectTypes, $directionId) => $directionId);
$directions = Direction::whereIn('id', $result)->get();
2024-03-07 15:09:01 +03:00
$generateHtml = function ($acc, $direction) {
$department = Department::find($direction->department_id);
$faculty = Faculty::find($department->faculty_id);
// phpcs:disable
2024-03-14 13:11:18 +03:00
$fon_3 = URL::to('img/front-page/bakalavr-special/fon3_blok.png');
2024-03-07 15:09:01 +03:00
return "{$acc} <tr class=\"\">
2024-03-12 12:47:12 +03:00
<td id=\"faculty\"> {$faculty->name} </td>
<td>
<a class=\" border border-white rounded-3 p-2 hover1\" type=\"button\" data-bs-toggle=\"offcanvas\" data-bs-target=\"#offcanvasScrolling-{$direction->id}{$direction->id }\" aria-controls=\"offcanvasScrolling\" role=\"button\">{$direction->name}</a>
2024-03-14 13:11:18 +03:00
<div class=\"offcanvas offcanvas-bottom\" data-bs-scroll=\"true\" data-bs-backdrop=\"false\" tabindex=\"-1\" id=\"offcanvasScrolling-{$direction->id }{$direction->id}\" aria-labelledby=\"offcanvasScrollingLabel-{$direction->id}{$direction->id}\" style=\"height: 100%; font-family: Geologica-Medium; overflow-y: auto ; background-image: url({$fon_3}); color: #004329\">
<div class=\"mx-5 \">
<div class=\"col-12 d-flex justify-content-end mt-4\">
<button type=\"button\" class=\"btn-close text-reset\" data-bs-dismiss=\"offcanvas\" aria-label=\"Close\">
</button>
</div>
<div class='row'>
<div class='col-md-6 col-12 d-block'>
<div class=\"\">
<div class=\"display-6 \" style=\"font-family: Geologica-Light\"> {$direction->code} </div>
2024-03-15 16:09:19 +03:00
<div class=\"display-5 \" > {$direction->name} </div>
2024-03-12 12:47:12 +03:00
</div>
2024-03-14 13:11:18 +03:00
<div class=\"mt-4\">
<p style=\"text-align: justify;\">{$direction->description}</p>
</div>
2024-03-12 12:47:12 +03:00
</div>
2024-03-14 13:11:18 +03:00
<div class='col-md-6 col-12 d-flex justify-content-center align-items-center'>
<div class=\"p-3 px-5 border-success fs-4\" style='border-radius: 50px; border: 2px solid;'>
<div > Уровень образования:
<strong>{$direction->educationLevel->name} </strong>
</div>
<hr class='d-block d-md-none'><br>
<div > Форма обучения:
<strong>{$direction->educationForm->name} </strong>
</div>
<hr class='d-block d-md-none'><br>
<div > Бюджетные места:
<strong >{$direction->budget_places} </strong>
</div>
<hr class='d-block d-md-none'><br>
<div > Квота:
<strong >{$direction->quota} </strong>
</div>
<hr class='d-block d-md-none'><br>
<div > Места на контракт:
<strong >{$direction->paid_places} </strong>
</div>
<hr class='d-block d-md-none'><br>
<div > Стоимость платного обучения:
<strong >{$direction->cost_paid_place} </strong>
</div>
<hr class='d-block d-md-none'><br>
<div > Период обучения (в годах):
<strong>{$direction->period} </span>
</div>
2024-03-12 12:47:12 +03:00
</div>
</div>
2024-03-14 13:11:18 +03:00
</div>
2024-03-12 12:47:12 +03:00
<div class=\"offcanvas-body mt-2\" style=\"font-family: Geologica-ExtraLight\">
2024-03-14 13:11:18 +03:00
2024-03-12 12:47:12 +03:00
</div>
</div>
2024-03-14 13:11:18 +03:00
</div>
2024-03-12 12:47:12 +03:00
2024-03-14 13:11:18 +03:00
</div>
2024-03-12 12:47:12 +03:00
</div>
</td>
<td class=\"text-end\"> {$direction->period} </td>
</tr>";
2024-03-07 15:09:01 +03:00
};
// phpcs:enable
2024-03-07 15:09:01 +03:00
$html = $directions->reduce($generateHtml, '');
return response()->json(['html' => $html]);
2024-03-07 13:58:54 +03:00
}
}