forked from aslan/applicant-site
add new logic to calculator with required and optional subjects
This commit is contained in:
parent
c13f5f38c2
commit
08bc93ad2d
|
@ -4,9 +4,9 @@ on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
pull_request:
|
# pull_request:
|
||||||
branches:
|
# branches:
|
||||||
- main
|
# - main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|
|
@ -7,6 +7,7 @@ use App\Models\Department;
|
||||||
use App\Models\Direction;
|
use App\Models\Direction;
|
||||||
use App\Models\EntranceExamination;
|
use App\Models\EntranceExamination;
|
||||||
use App\Models\Faculty;
|
use App\Models\Faculty;
|
||||||
|
use App\Models\SubjectType;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\URL;
|
use Illuminate\Support\Facades\URL;
|
||||||
|
|
||||||
|
@ -15,18 +16,34 @@ class CalculatorController extends Controller
|
||||||
public function findDirectionFromSubjects(Request $request)
|
public function findDirectionFromSubjects(Request $request)
|
||||||
{
|
{
|
||||||
$getJSON = $request->input()['predmets'];
|
$getJSON = $request->input()['predmets'];
|
||||||
$getsSubjects = json_decode($getJSON);
|
$calcultatorSubjects = json_decode($getJSON);
|
||||||
$countUserSubjects = count($getsSubjects);
|
$countUserSubjects = count($calcultatorSubjects);
|
||||||
|
|
||||||
$filteredDirectionIds = EntranceExamination::all()
|
$filteredDirectionIds = EntranceExamination::all()
|
||||||
->select("direction_id", "subject_id")
|
->select("direction_id", "subject_id", "subject_type_id")
|
||||||
->groupBy('direction_id')
|
->reduce(function (array $carry, $examine) {
|
||||||
->map(function ($direction) {
|
|
||||||
return $direction->map(fn($item) => $item['subject_id']);
|
|
||||||
})
|
|
||||||
->filter(fn($direction) => count($direction) <= $countUserSubjects)->keys();
|
|
||||||
|
|
||||||
$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) {
|
$generateHtml = function ($acc, $direction) {
|
||||||
|
|
|
@ -22,12 +22,6 @@ class PageController extends Controller
|
||||||
|
|
||||||
public function directions()
|
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();
|
$faculties = Faculty::all();
|
||||||
$subjects = EntranceExamination::all()
|
$subjects = EntranceExamination::all()
|
||||||
->select('subject_id', 'subject_type_id', 'examination_type_id')
|
->select('subject_id', 'subject_type_id', 'examination_type_id')
|
||||||
|
@ -38,21 +32,6 @@ class PageController extends Controller
|
||||||
$carry[$id] = $value;
|
$carry[$id] = $value;
|
||||||
return $carry;
|
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'));
|
return view('new-design.bakalavr-special', compact('faculties', 'subjects'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -495,7 +495,7 @@
|
||||||
$('.text-remove').remove();
|
$('.text-remove').remove();
|
||||||
let selected = []; let predmets='';
|
let selected = []; let predmets='';
|
||||||
$('.calcul input:checked').each(function() {
|
$('.calcul input:checked').each(function() {
|
||||||
selected.push($(this).val());
|
selected.push(+$(this).val());
|
||||||
predmets += $(this).val()+',';
|
predmets += $(this).val()+',';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue