Compare commits

..

3 Commits

Author SHA1 Message Date
aslan 432b3d0c5d Merge pull request 'new-calculator' (#43) from new-calculator into main
Tests & Lint & Deploy to Railway / build (2.6.6, 20.x, 8.3) (push) Failing after 3m37s Details
Tests & Lint & Deploy to Railway / deploy (push) Has been skipped Details
Reviewed-on: http://gitea.mkgtu.ru/aslan/applicant-site/pulls/43
2024-04-03 15:22:03 +03:00
aslan 5547d00565 fix logic new calculator 2024-04-03 15:21:10 +03:00
aslan 0e65ddaed0 add new calculator 2024-04-03 14:46:35 +03:00
3 changed files with 425 additions and 100 deletions

View File

@ -4,12 +4,11 @@ namespace App\Http\Controllers\Api;
use App\Enums\ExaminationTypeEnum;
use App\Http\Controllers\Controller;
use App\Models\Department;
use App\Models\Direction;
use App\Models\EntranceExamination;
use App\Models\Faculty;
use App\Services\DirectonHtmlBuilder;
use App\Services\DirectonHtmlBuilderForCalculator;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\URL;
class CalculatorController extends Controller
{
@ -34,7 +33,7 @@ class CalculatorController extends Controller
return $carry;
}, []);
$result = collect($filteredDirectionIds)
$directionIds = collect($filteredDirectionIds)
->filter(function ($subjectTypes) use ($calcultatorSubjects) {
$requiredSubjects = $subjectTypes[1];
return array_reduce($requiredSubjects, function ($acc, $requiredSubjects) use ($calcultatorSubjects) {
@ -51,97 +50,157 @@ class CalculatorController extends Controller
return $optionalSubjectsInCalculator->count() !== 0;
}
return true;
})->map(fn($subjectTypes, $directionId) => $directionId);
$directions = Direction::whereIn('id', $result)->get();
})
->map(fn($subjectTypes, $directionId) => $directionId);
$directions = Direction::whereIn('id', $directionIds)->get();
// dd($directionIds);
$dataToGenerateHTML = $this->getDirectionsToModals($directionIds);
// dd($dataToGenerateHTML);
$generateHtml = function ($acc, $direction) {
$department = Department::find($direction->department_id);
$faculty = Faculty::find($department->faculty_id);
// phpcs:disable
$fon_3 = URL::to('img/front-page/bakalavr-special/fon3_blok.png');
$builder = new DirectonHtmlBuilderForCalculator($direction);
$offCanvasModal = $builder->getHTML();
// dd($offCanvasModal);
return "{$acc} <tr class=\"border-bottom border-white my-3\">
<td class='w-25 '>
<a class=\"hover2 \" 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\" 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>
<div class=\"display-5 \" > {$direction->name} </div>
</div>
<div class=\"mt-4\">
<p style=\"text-align: justify;\">{$direction->description}</p>
</div>
</div>
<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>
</div>
</div>
</div>
<div class=\"offcanvas-body mt-2\" style=\"font-family: Geologica-ExtraLight\">
</div>
</div>
</div>
</div>
</div>
</td>
<td class=\"text-end\"> {$direction->cost_paid_place}</td>
<td class=\"text-end\"> {$direction->period} </td>
<a class=\"hover2 \" type=\"button\" data-bs-toggle=\"offcanvas\" data-bs-target=\"#calc-{$direction['id']}\" aria-controls=\"offcanvasScrolling\" role=\"button\">{$direction['name']}</a>
{$offCanvasModal}
</td>
<td class=\"text-end\"> 123</td>
<td class=\"text-end\"> 456 </td>
</tr>";
};
// phpcs:enable
$html = $directions->reduce($generateHtml, '');
$html = collect($dataToGenerateHTML)->reduce($generateHtml, '');
return response()->json(['html' => $html]);
}
public function getDirectionsToModals($directionIds)
{
//phpcs:disable
$directionsGroups = Direction::with(['department'])
->leftJoin('direction_direction_profile', 'directions.id', '=', 'direction_direction_profile.direction_id')
->leftJoin('direction_profiles', 'direction_direction_profile.direction_profile_id', '=', 'direction_profiles.id')
->leftJoin('departments', 'directions.department_id', '=', 'departments.id')
->leftJoin('faculties', 'departments.faculty_id', '=', 'faculties.id')
->leftJoin('education_levels', 'directions.education_level_id', '=', 'education_levels.id')
->leftJoin('education_forms', 'directions.education_form_id', '=', 'education_forms.id')
->leftJoin('entrance_examinations', 'entrance_examinations.direction_id', '=', 'directions.id')
->leftJoin('educational_institutions', 'faculties.educational_institution_id', '=', 'educational_institutions.id')
->leftJoin('examination_types', 'entrance_examinations.examination_type_id', '=', 'examination_types.id')
->leftJoin('subject_types', 'entrance_examinations.subject_type_id', '=', 'subject_types.id')
->leftJoin('subjects', 'entrance_examinations.subject_id', '=', 'subjects.id')
->select([
'directions.id as direction_id',
'directions.code as direction_code',
'directions.name as direction_name',
'directions.description as direction_description',
'directions.budget_places as direction_budget_places',
'directions.paid_places as direction_paid_places',
'directions.cost_paid_place as direction_cost_paid_place',
'directions.period as direction_period',
'education_levels.name as education_level_name',
'education_forms.name as education_form_name',
'faculties.id as faculty_id',
'faculties.name as faculty_name',
'faculties.description as faculty_description',
'educational_institutions.id as educational_institution_id',
'educational_institutions.name as educational_institution_name',
'direction_profiles.id as direction_profile_id',
'entrance_examinations.scores as entrance_examination_score',
'examination_types.name as examination_type_name',
'subject_types.name as subject_type_name',
'subjects.name as subject_name',
'direction_profiles.name as direction_profile_name',
])
->whereIn('directions.id', $directionIds)
->get()->toArray();
//phpcs:enable
$branches = [];
$directionsGroupWithOutBranch = array_reduce($directionsGroups, function ($acc, $direction) use (&$branches) {
if ($direction['educational_institution_id'] == 3) {
$branches[] = $direction;
}
$acc[] = $direction;
return $acc;
}, []);
$groupedDirections = collect($directionsGroupWithOutBranch)
->reduce(function ($carry, $item) use ($branches) {
[
'direction_id' => $directionId,
'direction_name' => $directionName,
'direction_code' => $directionCode,
'educational_institution_id' => $educational_institution_id,
'educational_institution_name' => $educationalInstitutionName,
'faculty_id' => $facultyId,
'faculty_name' => $facultyName,
'faculty_description' => $facultyDescription,
'education_level_name' => $educationLevelName,
'education_form_name' => $educationFormName,
'entrance_examination_score' => $entranceExaminationScore,
'examination_type_name' => $examinationTypeName,
'subject_type_name' => $subjectTypeName,
'subject_name' => $subjectName,
'direction_profile_name' => $directionProfileName,
'direction_budget_places' => $directionBudgetPlaces,
'direction_paid_places' => $directionPaidPlaces,
'direction_cost_paid_place' => $directionCostPaidPlace,
'direction_period' => $directionPeriod,
'direction_description' => $directionDescription,
] = $item;
// $carry[$facultyName]['id'] = $facultyId;
// $carry[$facultyName]['name'] = $facultyName;
// $carry[$facultyName]['description'] = $facultyDescription;
$carry[$directionName]['name'] = $directionName;
$carry[$directionName]['id'] = $directionId;
$carry[$directionName]['code'] = $directionCode;
$carry[$directionName]['education_level'] = $educationLevelName;
$carry[$directionName]['education_form'][] = $educationFormName;
$carry[$directionName]['education_form'] = array_unique(
$carry[$directionName]['education_form']
);
$carry[$directionName]['entrance_examinations']
[$examinationTypeName][$subjectTypeName][$subjectName] = $entranceExaminationScore;
$carry[$directionName]['budget_places']
[$educationalInstitutionName][$directionProfileName][$educationFormName] = $directionBudgetPlaces;
$carry[$directionName]['paid_places']
[$educationalInstitutionName][$directionProfileName][$educationFormName] = $directionPaidPlaces;
/*$carry[$facultyName]['directions'][$directionName]
['paid_places'][$educationFormName] = $directionPaidPlaces;*/
$carry[$directionName]
['cost_paid_place'][$educationFormName] = $directionCostPaidPlace;
$carry[$directionName]['period'][$educationFormName] = $directionPeriod;
$carry[$directionName]['description'] = $directionDescription;
foreach ($branches as $branch) {
[
'direction_name' => $directionNameBranch,
'educational_institution_name' => $educationalInstitutionNameBranch,
'direction_profile_name' => $directionProfileNameBranch,
'education_form_name' => $educationFormNameBranch,
'direction_budget_places' => $directionBudgetPlacesBranch
] = $branch;
if ($directionNameBranch === $directionName) {
$carry[$directionName]['budget_places']
[$educationalInstitutionNameBranch][$directionProfileNameBranch]
[$educationFormNameBranch] = $directionBudgetPlacesBranch;
}
}
return $carry;
}, []);
return $groupedDirections;
}
}

View File

@ -47,26 +47,16 @@ class PageController extends Controller
'directions.name',
"educational_institutions.name as educational_institution_name"
]);
//phpcs:disable
$directionsGroups = Direction::with(['department'])
->leftJoin('direction_direction_profile', 'directions.id', '=', 'direction_direction_profile.direction_id')
->leftJoin(
'direction_profiles',
'direction_direction_profile.direction_profile_id',
'=',
'direction_profiles.id'
)
->leftJoin('direction_profiles','direction_direction_profile.direction_profile_id','=','direction_profiles.id')
->leftJoin('departments', 'directions.department_id', '=', 'departments.id')
->leftJoin('faculties', 'departments.faculty_id', '=', 'faculties.id')
->leftJoin('education_levels', 'directions.education_level_id', '=', 'education_levels.id')
->leftJoin('education_forms', 'directions.education_form_id', '=', 'education_forms.id')
->leftJoin('entrance_examinations', 'entrance_examinations.direction_id', '=', 'directions.id')
->leftJoin(
'educational_institutions',
'faculties.educational_institution_id',
'=',
'educational_institutions.id'
)
->leftJoin('educational_institutions','faculties.educational_institution_id','=','educational_institutions.id')
->leftJoin('examination_types', 'entrance_examinations.examination_type_id', '=', 'examination_types.id')
->leftJoin('subject_types', 'entrance_examinations.subject_type_id', '=', 'subject_types.id')
->leftJoin('subjects', 'entrance_examinations.subject_id', '=', 'subjects.id')
@ -94,7 +84,7 @@ class PageController extends Controller
'direction_profiles.name as direction_profile_name',
)
->get()->toArray();
//phpcs:enable
$branches = [];
$directionsGroupWithOutBranch = array_reduce($directionsGroups, function ($acc, $direction) use (&$branches) {

View File

@ -0,0 +1,276 @@
<?php
namespace App\Services;
use Illuminate\Support\Facades\URL;
// phpcs:disable
class DirectonHtmlBuilderForCalculator
{
private array $direction;
public function __construct($direction)
{
$this->direction = $direction;
}
public function getHTML()
{
$direction = $this->direction;
$fon_3 = URL::to('img/front-page/bakalavr-special/fon3_blok.png');
$green_circle = URL::to('img/front-page/green-circle.png');
$education_form = '';
foreach ($direction['education_form'] as $el) {
$education_form .= $el . ', ';
}
$education_form = substr($education_form, 0, -2);
$period = '<br>';
foreach ($direction['period'] as $key => $el) {
$period .= '<span style="font-family: Geologica-ExtraLight">' . $key . '</span> - ' . '<strong>' . $el . '</strong><br>' ;
}
//dd($direction);
$paid_cost = '<div class="col-auto ">
<strong class="fs-3"> Стоимость обучения </strong>
<br>
<br>
<div class="fs-4 text-start">';
foreach ($direction['cost_paid_place'] as $key => $el) {
$paid_cost .= '<span style="font-family: Geologica-ExtraLight">' . $key . '</span> - ' . '<strong>' . $el . '</strong><br>' ;
}
$paid_cost .= '</div></div>';
$EGE = '<div class="col-auto ">
<strong> ЕГЭ </strong>
<br>
<br>
<div class=" d-inline-block p-2 text-start">';
foreach ($direction['entrance_examinations']['ЕГЭ']['Обязательные'] as $key => $el) {
$EGE .= '<span style="font-family: Geologica-ExtraLight">' . $key . '</span> - ' . '<strong>' . $el . '</strong><br>' ;
}
$EGE .= '</div></div>';
$po_viboru = '<div class="col-auto ">
<strong> Предметы по выбору </strong>
<br>
<br>
<div class=" d-inline-block p-2 text-start">';
if (array_key_exists('Предметы по выбору', $direction['entrance_examinations']['ЕГЭ'])) {
foreach ($direction['entrance_examinations']['ЕГЭ']['Предметы по выбору'] as $key => $el) {
$po_viboru .= '<span style="font-family: Geologica-ExtraLight">' . $key . '</span> - ' . '<strong>' . $el . '</strong><br>' ;
}
$po_viboru .= '</div></div>';
} else {
$po_viboru = '';
}
$SPO = '<div class="col-auto ">
<strong> СПО </strong>
<br>
<br>
<div class=" d-inline-block p-2 text-start">';
if (array_key_exists('СПО', $direction['entrance_examinations'])) {
foreach ($direction['entrance_examinations']['СПО']['Обязательные'] as $key => $el) {
$SPO .= '<span style="font-family: Geologica-ExtraLight">' . $key . '</span> - ' . '<strong>' . $el . '</strong><br>' ;
}
$SPO .= '</div></div>';
} else {
$SPO = '';
}
$mgtu = '';
if (array_key_exists('МГТУ', $direction['budget_places'])) {
foreach ($direction['budget_places']['МГТУ'] as $profile_name => $profile) {
$profile_content = '';
foreach ($profile as $forms => $budget_places) {
$profile_content .= "<strong> {$forms} </strong> - " . "<span style=\'font-family: Geologica-ExtraLight\'> {$budget_places} </span><br>";
}
$tmp = str_replace(' ', '', $profile_name);
$tmp = str_replace(',', '', $tmp);
$mgtu .= "<div class=\"accordion\" id=\"accordionExample\">
<div class=\"accordion-item\">
<h2 class=\"accordion-header\">
<button class=\"accordion-button\" type=\"button\" data-bs-toggle=\"collapse\" data-bs-target=\"#collapse-{$tmp}\" aria-expanded=\"true\" aria-controls=\"collapse-{$tmp}\">
$profile_name
</button>
</h2>
<div id=\"collapse-{$tmp}\" class=\"accordion-collapse collapse show\" data-bs-parent=\"#accordionExample\">
<div class=\"accordion-body\">
$profile_content
</div>
</div>
</div>
</div>" ;
}
}
// if($direction['name'] == 'Нефтегазовое дело') {
// dd($direction);
// };
// dd($direction);
$filial = '';
if (array_key_exists('Филиал МГТУ (пос. Яблоновский)', $direction['budget_places'])) {
foreach ($direction['budget_places']['Филиал МГТУ (пос. Яблоновский)'] as $profile_name => $profile) {
$profile_content = '';
foreach ($profile as $forms => $budget_places) {
$profile_content .= "<strong> {$forms} </strong> - " . "<span style=\'font-family: Geologica-ExtraLight\'> {$budget_places} </span><br>";
}
$tmp = str_replace(' ', '', $profile_name);
$tmp = str_replace(',', '', $tmp);
$filial .= "<div class=\"accordion \" id=\"accordionExample\">
<div class=\"accordion-item\">
<h2 class=\"accordion-header\">
<button class=\"accordion-button\" type=\"button\" data-bs-toggle=\"collapse\" data-bs-target=\"#collapse-{$tmp}\" aria-expanded=\"true\" aria-controls=\"collapse-{$tmp}\">
$profile_name
</button>
</h2>
<div id=\"collapse-{$tmp}\" class=\"accordion-collapse collapse show\" data-bs-parent=\"#accordionExample\">
<div class=\"accordion-body\">
$profile_content
</div>
</div>
</div>
</div>" ;
}
} else {
$filial = '<div class="w-100 h-100 d-flex justify-content-center align-items-center" >Этой специальности нет в филиалле</div>';
}
$paid_places_content = '';
foreach ($direction['paid_places'] as $institution) {
foreach ($institution as $profile_name => $profile) {
$profile_content = '';
foreach ($profile as $forms => $paid_places) {
$profile_content .= "<strong> {$forms} </strong> - " . "<span style=\'font-family: Geologica-ExtraLight\'> {$paid_places} </span><br>";
}
$tmp = str_replace(' ', '', $profile_name);
$tmp = str_replace(',', '', $tmp);
$paid_places_content .= "<div class=\"accordion \" id=\"accordionExample\">
<div class=\"accordion-item\">
<h2 class=\"accordion-header\">
<button class=\"accordion-button\" type=\"button\" data-bs-toggle=\"collapse\" data-bs-target=\"#collapse-{$tmp}{$tmp}\" aria-expanded=\"true\" aria-controls=\"collapse-{$tmp}{$tmp}\">
$profile_name
</button>
</h2>
<div id=\"collapse-{$tmp}{$tmp}\" class=\"accordion-collapse collapse show\" data-bs-parent=\"#accordionExample\">
<div class=\"accordion-body\">
$profile_content
</div>
</div>
</div>
</div>" ;
}
}
return "<div class=\"offcanvas offcanvas-bottom\" data-bs-scroll=\"true\" data-bs-backdrop=\"false\" tabindex=\"-1\" id=\"calc-{$direction['id'] }\" aria-labelledby=\"Labelcalc-{$direction['id']}\" style=\"height: 100%; font-family: Geologica-Medium; overflow-y: auto ; background-image: url({$fon_3}); color: #004329\">
<div class=\"mx-5 pb-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-11 d-block'>
<div class='col ms-4'>
<div class=\"display-5 \" style=\"font-family: Geologica-Light\"> {$direction['code']} </div>
<div class=\"display-5 \" > {$direction['name']}</div>
</div>
<div class='col d-flex justify-content-end'>
<div class=\"fs-5 mb-3 \" style=\"font-family: Geologica-Light\">
<button type='button' class='button_chng_instit hover2 btn btn-outline-success' data-institut='mgtu' data-id='{$direction['id']}'>
<img style='width: 8px; height: auto;' id = 'id_mgtu_{$direction['id']}' src='img/front-page/green-circle.png'>
МГТУ
</button> |
<button type='button' class='button_chng_instit hover2 btn btn-outline-success' data-institut='filial' data-id='{$direction['id']}'>
<img style='display: none; width: 8px; height: auto;' id = 'id_filial_{$direction['id']}' src='img/front-page/green-circle.png'> Филиал МГТУ (пос. Яблоновский)
</button>
</div>
</div>
</div>
<hr class='col-11 '>
<div class=\"mt-4\">
<p style=\"text-align: justify;\">{$direction['description']}</p>
</div>
</div>
<div class='row'>
<div class='col-12 col-lg-4 h-100 '>
<div class=\"p-3 px-5 border-success fs-5 h-100 \" style='border-radius: 20px; border: 2px solid;'>
<div > Уровень образования:
<strong>{$direction['education_level']} </strong>
</div>
<div > Форма обучения:
<strong> {$education_form} </strong>
</div>
<div > Период обучения (в годах):
$period
</div>
</div>
</div>
<div class='col-12 col-lg-8 col-xl-7 '>
<div class=\"p-3 px-5 border-success fs-5 h-100\" style='border-radius: 20px; border: 2px solid;'>
<strong class='d-flex justify-content-center fs-3'>Места для обучения:</strong><br>
<div class='content_budget'>
<br>
<div class='row'>
<div class='col'>
<p class='text-center'> Бюджет</p>
<div id='content_budget_filial_{$direction['id']}' style='display: none;' >{$filial}</div>
<div id='content_budget_mgtu_{$direction['id']}' >{$mgtu}</div>
</div>
<div class='col'>
<p class='text-center'> Коммерция</p>
<div> $paid_places_content </div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class='row mt-3'>
<div class='col-12 col-lg-9 '>
<div class=\"p-3 px-5 border-success fs-5 h-100\" style='border-radius: 20px; border: 2px solid;'>
<strong class='fs-3'> Проходные баллы:</strong>
<div class='row mt-3'>
$EGE $po_viboru $SPO
</div>
</div>
</div>
<div class='col-12 col-lg-3 col-xl-2 '>
<div class=\"p-3 border-success fs-5 h-100 col\" style='border-radius: 20px; border: 2px solid;'>
$paid_cost
</div>
</div>
</div>
</div>
</div>
</div>";
}
// phpcs:enable
}