fix new logic to calculator with required and optional subjects
Tests & Lint & Deploy to Railway / build (2.6.6, 20.x, 8.3) (push) Failing after 1m37s Details
Tests & Lint & Deploy to Railway / deploy (push) Has been skipped Details

This commit is contained in:
aslan 2024-03-18 11:36:14 +03:00
parent 68ccbf2910
commit 8a94e7a750
1 changed files with 8 additions and 7 deletions

View File

@ -17,7 +17,6 @@ class CalculatorController extends Controller
{ {
$getJSON = $request->input()['predmets']; $getJSON = $request->input()['predmets'];
$calcultatorSubjects = json_decode($getJSON); $calcultatorSubjects = json_decode($getJSON);
$countUserSubjects = count($calcultatorSubjects);
$filteredDirectionIds = EntranceExamination::all() $filteredDirectionIds = EntranceExamination::all()
->select("direction_id", "subject_id", "subject_type_id", "examination_type_id") ->select("direction_id", "subject_id", "subject_type_id", "examination_type_id")
@ -37,18 +36,20 @@ class CalculatorController extends Controller
}, []); }, []);
$result = collect($filteredDirectionIds) $result = collect($filteredDirectionIds)
->filter(function ($subjectTypes) use ($calcultatorSubjects) { ->filter(function ($subjectTypes) use ($calcultatorSubjects) {
$requiredSbjects = $subjectTypes[1]; $requiredSubjects = $subjectTypes[1];
return array_reduce($requiredSbjects, function ($acc, $requiredSbject) use ($calcultatorSubjects) { return array_reduce($requiredSubjects, function ($acc, $requiredSubjects) use ($calcultatorSubjects) {
if (!in_array($requiredSbject, $calcultatorSubjects)) { if (!in_array($requiredSubjects, $calcultatorSubjects)) {
return false; return false;
} }
return $acc; return $acc;
}, true); }, true);
}) })
->filter(function ($subjectTypes) use ($calcultatorSubjects) { ->filter(function ($subjectTypes) use ($calcultatorSubjects) {
if(array_key_exists(2, $subjectTypes)) {
$optionalSubjectsInCalculator = collect($subjectTypes[2]) $optionalSubjectsInCalculator = collect($subjectTypes[2])
->filter(fn($optionalSubject) => in_array($optionalSubject, $calcultatorSubjects)); ->filter(fn($optionalSubject) => in_array($optionalSubject, $calcultatorSubjects));
return $optionalSubjectsInCalculator->count() !== 0; return $optionalSubjectsInCalculator->count() !== 0;
}
})->map(fn($subjectTypes, $directionId) => $directionId); })->map(fn($subjectTypes, $directionId) => $directionId);
$directions = Direction::whereIn('id', $result)->get(); $directions = Direction::whereIn('id', $result)->get();