forked from aslan/applicant-site
prodV1 #2
|
@ -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();
|
||||||
|
|
Loading…
Reference in New Issue