2024-03-07 13:58:54 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
2024-03-18 11:21:48 +03:00
|
|
|
use App\Enums\ExaminationTypeEnum;
|
2024-03-07 13:58:54 +03:00
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Models\Direction;
|
|
|
|
use App\Models\EntranceExamination;
|
2024-04-03 14:46:35 +03:00
|
|
|
use App\Services\DirectonHtmlBuilder;
|
2024-04-03 15:21:10 +03:00
|
|
|
use App\Services\DirectonHtmlBuilderForCalculator;
|
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'];
|
2024-03-15 16:55:58 +03:00
|
|
|
$calcultatorSubjects = json_decode($getJSON);
|
2024-03-07 15:09:01 +03:00
|
|
|
|
|
|
|
$filteredDirectionIds = EntranceExamination::all()
|
2024-03-18 11:21:48 +03:00
|
|
|
->select("direction_id", "subject_id", "subject_type_id", "examination_type_id")
|
|
|
|
->where('examination_type_id', '=', ExaminationTypeEnum::Ege->value)
|
2024-03-15 16:55:58 +03:00
|
|
|
->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;
|
|
|
|
}, []);
|
2024-04-03 14:46:35 +03:00
|
|
|
$directionIds = collect($filteredDirectionIds)
|
2024-03-18 09:43:58 +03:00
|
|
|
->filter(function ($subjectTypes) use ($calcultatorSubjects) {
|
2024-03-18 11:36:14 +03:00
|
|
|
$requiredSubjects = $subjectTypes[1];
|
|
|
|
return array_reduce($requiredSubjects, function ($acc, $requiredSubjects) use ($calcultatorSubjects) {
|
|
|
|
if (!in_array($requiredSubjects, $calcultatorSubjects)) {
|
2024-03-18 09:43:58 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return $acc;
|
|
|
|
}, true);
|
|
|
|
})
|
2024-03-15 16:55:58 +03:00
|
|
|
->filter(function ($subjectTypes) use ($calcultatorSubjects) {
|
2024-03-18 11:56:03 +03:00
|
|
|
if (array_key_exists(2, $subjectTypes)) {
|
2024-03-18 11:36:14 +03:00
|
|
|
$optionalSubjectsInCalculator = collect($subjectTypes[2])
|
|
|
|
->filter(fn($optionalSubject) => in_array($optionalSubject, $calcultatorSubjects));
|
|
|
|
return $optionalSubjectsInCalculator->count() !== 0;
|
|
|
|
}
|
2024-03-18 11:55:25 +03:00
|
|
|
return true;
|
2024-04-03 14:46:35 +03:00
|
|
|
})
|
|
|
|
->map(fn($subjectTypes, $directionId) => $directionId);
|
2024-03-07 15:09:01 +03:00
|
|
|
|
2024-04-03 14:46:35 +03:00
|
|
|
$directions = Direction::whereIn('id', $directionIds)->get();
|
|
|
|
// dd($directionIds);
|
|
|
|
$dataToGenerateHTML = $this->getDirectionsToModals($directionIds);
|
|
|
|
// dd($dataToGenerateHTML);
|
2024-03-07 15:09:01 +03:00
|
|
|
$generateHtml = function ($acc, $direction) {
|
2024-04-03 15:21:10 +03:00
|
|
|
$builder = new DirectonHtmlBuilderForCalculator($direction);
|
2024-04-03 14:46:35 +03:00
|
|
|
$offCanvasModal = $builder->getHTML();
|
2024-04-03 15:21:10 +03:00
|
|
|
// 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=\"#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>";
|
2024-03-07 15:09:01 +03:00
|
|
|
};
|
2024-04-03 14:46:35 +03:00
|
|
|
$html = collect($dataToGenerateHTML)->reduce($generateHtml, '');
|
2024-03-07 15:09:01 +03:00
|
|
|
|
|
|
|
return response()->json(['html' => $html]);
|
2024-03-07 13:58:54 +03:00
|
|
|
}
|
2024-04-03 14:46:35 +03:00
|
|
|
|
|
|
|
public function getDirectionsToModals($directionIds)
|
|
|
|
{
|
|
|
|
//phpcs:disable
|
|
|
|
$directionsGroups = Direction::with(['department'])
|
|
|
|
->leftJoin('direction_direction_profile', 'directions.id', '=', 'direction_direction_profile.direction_id')
|
2024-04-03 15:21:10 +03:00
|
|
|
->leftJoin('direction_profiles', 'direction_direction_profile.direction_profile_id', '=', 'direction_profiles.id')
|
2024-04-03 14:46:35 +03:00
|
|
|
->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')
|
2024-04-03 15:21:10 +03:00
|
|
|
->leftJoin('educational_institutions', 'faculties.educational_institution_id', '=', 'educational_institutions.id')
|
2024-04-03 14:46:35 +03:00
|
|
|
->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;
|
2024-04-03 15:21:10 +03:00
|
|
|
$carry[$directionName]['name'] = $directionName;
|
|
|
|
$carry[$directionName]['id'] = $directionId;
|
|
|
|
$carry[$directionName]['code'] = $directionCode;
|
|
|
|
$carry[$directionName]['education_level'] = $educationLevelName;
|
2024-04-03 14:46:35 +03:00
|
|
|
$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;
|
|
|
|
}
|
2024-03-07 13:58:54 +03:00
|
|
|
}
|