diff --git a/.gitea/workflows/php.yml b/.gitea/workflows/php.yml index eecd9a7..7602d6e 100644 --- a/.gitea/workflows/php.yml +++ b/.gitea/workflows/php.yml @@ -4,9 +4,9 @@ on: push: branches: - main - pull_request: - branches: - - main +# pull_request: +# branches: +# - main jobs: build: diff --git a/app/Http/Controllers/Api/CalculatorController.php b/app/Http/Controllers/Api/CalculatorController.php index f66ac75..951c95f 100644 --- a/app/Http/Controllers/Api/CalculatorController.php +++ b/app/Http/Controllers/Api/CalculatorController.php @@ -7,6 +7,7 @@ use App\Models\Department; use App\Models\Direction; use App\Models\EntranceExamination; use App\Models\Faculty; +use App\Models\SubjectType; use Illuminate\Http\Request; use Illuminate\Support\Facades\URL; @@ -15,18 +16,34 @@ class CalculatorController extends Controller public function findDirectionFromSubjects(Request $request) { $getJSON = $request->input()['predmets']; - $getsSubjects = json_decode($getJSON); - $countUserSubjects = count($getsSubjects); + $calcultatorSubjects = json_decode($getJSON); + $countUserSubjects = count($calcultatorSubjects); $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)->keys(); + ->select("direction_id", "subject_id", "subject_type_id") + ->reduce(function (array $carry, $examine) { - $directions = Direction::whereIn('id', $filteredDirectionIds)->get(); + [ + 'direction_id' => $direction_id, + 'subject_id' => $subject_id, + 'subject_type_id' => $subject_type_id + ] = $examine; + + $carry[$direction_id][$subject_type_id][] = $subject_id; + $carry[$direction_id][$subject_type_id] = array_unique($carry[$direction_id][$subject_type_id]); + + return $carry; + }, []); + $result = collect($filteredDirectionIds) + ->filter(fn ($subjectTypes) => !array_diff($subjectTypes[1], $calcultatorSubjects)) + ->filter(function ($subjectTypes) use ($calcultatorSubjects) { + $optionalSubjectsInCalculator = collect($subjectTypes[2]) + ->filter(fn ($optionalSubject) => in_array($optionalSubject, $calcultatorSubjects)); + return $optionalSubjectsInCalculator->count() !== 0; + })->map(fn ($subjectTypes, $directionId) => $directionId) + ; +// dd($result); + $directions = Direction::whereIn('id', $result)->get(); $generateHtml = function ($acc, $direction) { diff --git a/app/Http/Controllers/admin/PageController.php b/app/Http/Controllers/admin/PageController.php index bce45de..656ffcd 100644 --- a/app/Http/Controllers/admin/PageController.php +++ b/app/Http/Controllers/admin/PageController.php @@ -22,12 +22,6 @@ class PageController extends Controller public function directions() { -// $directions = DB::table('faculties') -// ->join('departments', 'faculties.id', '=', 'departments.faculty_id') -// ->join('directions', 'departments.id', '=', 'directions.department_id') -// ->select('faculties.name as faculties.name', 'directions.name', 'directions.id') -// ->groupBy('faculties.name') -// ->get(); $faculties = Faculty::all(); $subjects = EntranceExamination::all() ->select('subject_id', 'subject_type_id', 'examination_type_id') @@ -38,21 +32,6 @@ class PageController extends Controller $carry[$id] = $value; return $carry; }); -// $subjects = EntranceExamination::pluck('name', 'id'); -// $infBez = $faculties->find(FacultyEnum::InfBez->value); -// $query = `select faculties.name, directions.name, directions.id -//FROM faculties -//join departments on faculties.id = departments.faculty_id -//join directions on departments.id = directions.department_id`; -// $directions = DB::($query); -// foreach ($faculties as $faculty) { -// foreach ($faculty->departments as $department) { -// foreach ($department->directions as $direction) { -// -// } -// } -// -// } return view('new-design.bakalavr-special', compact('faculties', 'subjects')); } diff --git a/resources/views/new-design/bakalavr-special.blade.php b/resources/views/new-design/bakalavr-special.blade.php index 28475bb..98c42bb 100644 --- a/resources/views/new-design/bakalavr-special.blade.php +++ b/resources/views/new-design/bakalavr-special.blade.php @@ -495,7 +495,7 @@ $('.text-remove').remove(); let selected = []; let predmets=''; $('.calcul input:checked').each(function() { - selected.push($(this).val()); + selected.push(+$(this).val()); predmets += $(this).val()+','; });