forked from aslan/applicant-site
prodV1 #2
|
@ -3,28 +3,21 @@
|
|||
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) {
|
||||
|
@ -32,7 +25,23 @@ class CalculatorController extends Controller
|
|||
})
|
||||
->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} <tr class=\"\">
|
||||
<td id=\"faculty\"> {$faculty->name} </td>
|
||||
<td> {$direction->name} </td>
|
||||
<td class=\"text-end\"> {$direction->period} </td>
|
||||
</tr>";
|
||||
};
|
||||
|
||||
$html = $directions->reduce($generateHtml, '');
|
||||
|
||||
return response()->json(['html' => $html]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -494,7 +494,7 @@
|
|||
</div>
|
||||
<script>window.onload = function() {
|
||||
$(".calcul input").click(function(){
|
||||
var selected = []; let predmets='';
|
||||
let selected = []; let predmets='';
|
||||
$('.calcul input:checked').each(function() {
|
||||
selected.push($(this).val());
|
||||
predmets += $(this).val()+',';
|
||||
|
@ -502,9 +502,10 @@
|
|||
console.log(selected);
|
||||
|
||||
$(".calcul_rez").html('<tr><td>обрабатываем</td></tr>');
|
||||
$.ajax({ url: "json.php", dataType: 'json', cache:false,type: "POST",data: 'ajx=get_napr&format=html&predmets='+selected,
|
||||
$.ajax({ url: "{{ route('calculator') }}", dataType: 'json', cache:false,type: "POST",data: 'ajx=get_napr&format=html&predmets='+JSON.stringify(selected),
|
||||
success: function(data) {
|
||||
$(".calcul_rez").html(data.html);
|
||||
console.log(data);
|
||||
}});
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue