forked from aslan/applicant-site
fix calculator
This commit is contained in:
parent
5d7863a655
commit
d0abc35a07
|
@ -3,36 +3,45 @@
|
||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
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 Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use function _PHPStan_cc8d35ffb\React\Promise\map;
|
|
||||||
|
|
||||||
class CalculatorController extends Controller
|
class CalculatorController extends Controller
|
||||||
{
|
{
|
||||||
public function findDirectionFromSubjects(Request $request)
|
public function findDirectionFromSubjects(Request $request)
|
||||||
{
|
{
|
||||||
$getsSubjects = $request->input();
|
$getJSON = $request->input()['predmets'];
|
||||||
|
$getsSubjects = json_decode($getJSON);
|
||||||
$countUserSubjects = count($getsSubjects);
|
$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();
|
$filteredDirectionIds = EntranceExamination::all()
|
||||||
// dd($entranceExamination);
|
|
||||||
// $directions = Direction::all();
|
|
||||||
$findIds = EntranceExamination::all()
|
|
||||||
->select("direction_id", "subject_id")
|
->select("direction_id", "subject_id")
|
||||||
->groupBy('direction_id')
|
->groupBy('direction_id')
|
||||||
->map(function ($direction) {
|
->map(function ($direction) {
|
||||||
return $direction->map(fn($item) => $item['subject_id']);
|
return $direction->map(fn($item) => $item['subject_id']);
|
||||||
})
|
})
|
||||||
->filter(fn ($direction) => count($direction) <= $countUserSubjects)
|
->filter(fn($direction) => count($direction) <= $countUserSubjects)
|
||||||
->keys();
|
->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>
|
</div>
|
||||||
<script>window.onload = function() {
|
<script>window.onload = function() {
|
||||||
$(".calcul input").click(function(){
|
$(".calcul input").click(function(){
|
||||||
var 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()+',';
|
||||||
|
@ -502,9 +502,10 @@
|
||||||
console.log(selected);
|
console.log(selected);
|
||||||
|
|
||||||
$(".calcul_rez").html('<tr><td>обрабатываем</td></tr>');
|
$(".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) {
|
success: function(data) {
|
||||||
$(".calcul_rez").html(data.html);
|
$(".calcul_rez").html(data.html);
|
||||||
|
console.log(data);
|
||||||
}});
|
}});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue