fix new logic to calculator with required and optional subjects

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