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

100 lines
7.0 KiB
PHP
Raw Normal View History

2024-03-07 13:58:54 +03:00
<?php
namespace App\Http\Controllers\Api;
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;
class CalculatorController extends Controller
{
public function findDirectionFromSubjects(Request $request)
{
2024-03-07 15:09:01 +03:00
$getJSON = $request->input()['predmets'];
$getsSubjects = json_decode($getJSON);
2024-03-07 13:58:54 +03:00
$countUserSubjects = count($getsSubjects);
2024-03-07 15:09:01 +03:00
$filteredDirectionIds = EntranceExamination::all()
2024-03-07 13:58:54 +03:00
->select("direction_id", "subject_id")
->groupBy('direction_id')
->map(function ($direction) {
return $direction->map(fn($item) => $item['subject_id']);
})
->filter(fn($direction) => count($direction) <= $countUserSubjects)->keys();
2024-03-07 15:09:01 +03:00
$directions = Direction::whereIn('id', $filteredDirectionIds)->get();
$generateHtml = function ($acc, $direction) {
$department = Department::find($direction->department_id);
$faculty = Faculty::find($department->faculty_id);
// phpcs:disable
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>
<div class=\"offcanvas offcanvas-bottom text-dark\" 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 ;\">
<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-xl-3 col-12\">
<div class=\"display-5 \" style=\"font-family: Geologica-Light\"> {$direction->code} </div>
<div class=\"display-5 \" > {$direction->name}</div>
</div>
</div>
<div class=\"row\">
<div class=\"col-xl-3 col-12\">
<br>
<br>
<div> Уровень образования: <span style=\"font-family: Geologica-Light\">{$direction->educationLevel->name} </span> </div>
<div> Форма обучения: <span style=\"font-family: Geologica-Light\">{$direction->educationForm->name} </span></div>
</div>
<div class=\"col-xl-3 col-12\">
<br>
<br>
<div> Бюджетные места: <span style=\"font-family: Geologica-Light\">{$direction->budget_places} </span> </div>
<div> Квота: <span style=\"font-family: Geologica-Light\">{$direction->quota} </span></div>
</div>
<div class=\"col-xl-3 col-12\">
<br>
<br>
<div> Места на контракт: <span style=\"font-family: Geologica-Light\">{$direction->paid_places} </span> </div>
<div> Стоимость платного обучения: <span style=\"font-family: Geologica-Light\">{$direction->cost_paid_place} </span></div>
</div>
<div class=\"col-xl-3 col-12\">
<br>
<br>
<div> Период обучения (в годах): <span style=\"font-family: Geologica-Light\">{$direction->period} </span> </div>
</div>
</div>
<div class=\"offcanvas-body mt-2\" style=\"font-family: Geologica-ExtraLight\">
<p style=\"text-align: justify;\">{$direction->description}</p>
</div>
</div>
</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
}
}