From 0e65ddaed0ee30a67144e40e81390f5ab20d9bd9 Mon Sep 17 00:00:00 2001 From: aslan Date: Wed, 3 Apr 2024 14:46:35 +0300 Subject: [PATCH] add new calculator --- .../Controllers/Api/CalculatorController.php | 228 +++++++++------ app/Http/Controllers/admin/PageController.php | 18 +- .../DirectonHtmlBuilderForCalculator.php | 276 ++++++++++++++++++ 3 files changed, 420 insertions(+), 102 deletions(-) create mode 100644 app/Services/DirectonHtmlBuilderForCalculator.php diff --git a/app/Http/Controllers/Api/CalculatorController.php b/app/Http/Controllers/Api/CalculatorController.php index 23c8963..9d850b9 100644 --- a/app/Http/Controllers/Api/CalculatorController.php +++ b/app/Http/Controllers/Api/CalculatorController.php @@ -8,6 +8,8 @@ use App\Models\Department; use App\Models\Direction; use App\Models\EntranceExamination; use App\Models\Faculty; +use App\Models\Subject; +use App\Services\DirectonHtmlBuilder; use Illuminate\Http\Request; use Illuminate\Support\Facades\URL; @@ -34,7 +36,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 +53,147 @@ 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'); - return "{$acc} - - - id}{$direction->id }\" aria-controls=\"offcanvasScrolling\" role=\"button\">{$direction->name} -
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\"> - - -
-
- -
- -
- -
- -
-
{$direction->code}
-
{$direction->name}
-
-
-

{$direction->description}

-
- -
- - -
- -
-
Уровень образования: - {$direction->educationLevel->name} -
-

-
Форма обучения: - {$direction->educationForm->name} -
-

-
Бюджетные места: - {$direction->budget_places} -
-

-
Квота: - {$direction->quota} -
-

-
Места на контракт: - {$direction->paid_places} -
-

-
Стоимость платного обучения: - {$direction->cost_paid_place} -
-

-
Период обучения (в годах): - {$direction->period} -
-
-
-
- -
- - - -
-
-
- - - - - {$direction->cost_paid_place} - {$direction->period} - - "; + $builder = new DirectonHtmlBuilder($direction); + $offCanvasModal = $builder->getHTML(); + return "{$acc} $offCanvasModal"; }; - // 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; + } } diff --git a/app/Http/Controllers/admin/PageController.php b/app/Http/Controllers/admin/PageController.php index 899c6f9..c1f2af1 100644 --- a/app/Http/Controllers/admin/PageController.php +++ b/app/Http/Controllers/admin/PageController.php @@ -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) { diff --git a/app/Services/DirectonHtmlBuilderForCalculator.php b/app/Services/DirectonHtmlBuilderForCalculator.php new file mode 100644 index 0000000..5d21f4b --- /dev/null +++ b/app/Services/DirectonHtmlBuilderForCalculator.php @@ -0,0 +1,276 @@ +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 = '
'; + foreach ($direction['period'] as $key => $el) { + $period .= '' . $key . ' - ' . '' . $el . '
' ; + } + + + //dd($direction); + + $paid_cost = '
+ Стоимость обучения +
+
+
'; + foreach ($direction['cost_paid_place'] as $key => $el) { + $paid_cost .= '' . $key . ' - ' . '' . $el . '
' ; + } + $paid_cost .= '
'; + + + + + $EGE = '
+ ЕГЭ +
+
+
'; + foreach ($direction['entrance_examinations']['ЕГЭ']['Обязательные'] as $key => $el) { + $EGE .= '' . $key . ' - ' . '' . $el . '
' ; + } + $EGE .= '
'; + + $po_viboru = '
+ Предметы по выбору +
+
+
'; + if (array_key_exists('Предметы по выбору', $direction['entrance_examinations']['ЕГЭ'])) { + foreach ($direction['entrance_examinations']['ЕГЭ']['Предметы по выбору'] as $key => $el) { + $po_viboru .= '' . $key . ' - ' . '' . $el . '
' ; + } + $po_viboru .= '
'; + } else { + $po_viboru = ''; + } + + + $SPO = '
+ СПО +
+
+
'; + if (array_key_exists('СПО', $direction['entrance_examinations'])) { + foreach ($direction['entrance_examinations']['СПО']['Обязательные'] as $key => $el) { + $SPO .= '' . $key . ' - ' . '' . $el . '
' ; + } + $SPO .= '
'; + } 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 .= " {$forms} - " . " {$budget_places}
"; + } + $tmp = str_replace(' ', '', $profile_name); + $tmp = str_replace(',', '', $tmp); + $mgtu .= "
+
+

+ +

+
+
+ $profile_content +
+
+
+
" ; + } + } +// 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 .= " {$forms} - " . " {$budget_places}
"; + } + $tmp = str_replace(' ', '', $profile_name); + $tmp = str_replace(',', '', $tmp); + $filial .= "
+
+

+ +

+
+
+ $profile_content +
+
+
+
" ; + } + } else { + $filial = '
Этой специальности нет в филиалле
'; + } + $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 .= " {$forms} - " . " {$paid_places}
"; + } + $tmp = str_replace(' ', '', $profile_name); + $tmp = str_replace(',', '', $tmp); + $paid_places_content .= "
+
+

+ +

+
+
+ $profile_content +
+
+
+
" ; + } + } + + + return "
+ + +
+
+ +
+
+
+
+
{$direction['code']}
+
{$direction['name']}
+
+
+
+ + | + + +
+
+
+
+
+

{$direction['description']}

+
+
+
+ +
+
+
Уровень образования: + {$direction['education_level']} +
+
Форма обучения: + {$education_form} +
+
Период обучения (в годах): + $period +
+
+
+
+
+ Места для обучения:
+
+
+
+
+

Бюджет

+ +
{$mgtu}
+
+ + +
+

Коммерция

+
$paid_places_content
+ +
+
+ + +
+
+
+
+
+
+
+ Проходные баллы: +
+ $EGE $po_viboru $SPO +
+ + +
+
+
+
+ $paid_cost +
+
+
+
+
+ "; + } + // phpcs:enable +}