forked from aslan/applicant-site
fix new logic to calculator with required and optional subjects
This commit is contained in:
parent
68ccbf2910
commit
8a94e7a750
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue