From d0abc35a076c7f14d2ef7bfa53200f4001941dbf Mon Sep 17 00:00:00 2001 From: aslan Date: Thu, 7 Mar 2024 15:09:01 +0300 Subject: [PATCH] fix calculator --- .../Controllers/Api/CalculatorController.php | 39 ++++++++++++------- .../new-design/bakalavr-special.blade.php | 5 ++- 2 files changed, 27 insertions(+), 17 deletions(-) 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} + {$faculty->name} + {$direction->name} + {$direction->period} +"; + }; + + $html = $directions->reduce($generateHtml, ''); + + return response()->json(['html' => $html]); } } diff --git a/resources/views/new-design/bakalavr-special.blade.php b/resources/views/new-design/bakalavr-special.blade.php index c2230b3..21ec61c 100644 --- a/resources/views/new-design/bakalavr-special.blade.php +++ b/resources/views/new-design/bakalavr-special.blade.php @@ -494,7 +494,7 @@