diff --git a/app/Http/Controllers/Api/CalculatorController.php b/app/Http/Controllers/Api/CalculatorController.php index 0843879..6ff35ce 100644 --- a/app/Http/Controllers/Api/CalculatorController.php +++ b/app/Http/Controllers/Api/CalculatorController.php @@ -3,36 +3,45 @@ namespace App\Http\Controllers\Api; use App\Http\Controllers\Controller; +use App\Models\Department; use App\Models\Direction; use App\Models\EntranceExamination; +use App\Models\Faculty; use Illuminate\Http\Request; -use function _PHPStan_cc8d35ffb\React\Promise\map; class CalculatorController extends Controller { public function findDirectionFromSubjects(Request $request) { - $getsSubjects = $request->input(); + $getJSON = $request->input()['predmets']; + $getsSubjects = json_decode($getJSON); $countUserSubjects = count($getsSubjects); -// $entranceExamination = EntranceExamination::all() -// ->whereIn('subject_id', $result) -// ->where('subject_type_id','=',1) -// ->select('subject_id','direction_id') -// ->whereIn('subject_id', $result) -// ->groupBy('direction_id') -// ->toArray(); -// dd($entranceExamination); -// $directions = Direction::all(); - $findIds = EntranceExamination::all() + $filteredDirectionIds = EntranceExamination::all() ->select("direction_id", "subject_id") ->groupBy('direction_id') ->map(function ($direction) { return $direction->map(fn($item) => $item['subject_id']); }) - ->filter(fn ($direction) => count($direction) <= $countUserSubjects) + ->filter(fn($direction) => count($direction) <= $countUserSubjects) ->keys(); - $directions = Direction::whereIn('id', $findIds)->get(); - return response()->json($directions); + + $directions = Direction::whereIn('id', $filteredDirectionIds)->get(); + + + $generateHtml = function ($acc, $direction) { + $department = Department::find($direction->department_id); + $faculty = Faculty::find($department->faculty_id); + + return "{$acc}