gradesExist($qid, $slot)) { return json_encode(['status' => 'error', 'message' => 'Grades already exist in the database.']); } var_dump('AJAX'); $question_attempts = $quizQuery->get_question_attempts($qid, $slot); $referenceAnswer = $quizQuery->get_reference_answer($qid); $maxmark = (float)$question_attempts->current()->maxmark; $data = prepare_api_data($quizQuery, $question_attempts, $referenceAnswer); $studentData = $data['studentData']; $inputNames = array_column($studentData, 'inputName'); var_dump('Entering AJAX function...'); error_log('Before fetching question attempts'); // API вызов для получения оценок try { $apiendpoint = get_config('local_asystgrade', 'apiendpoint') ?: 'http://flask:5000/api/autograde'; $httpClient = new \local_asystgrade\api\http_client(); $apiClient = \local_asystgrade\api\client::getInstance($apiendpoint, $httpClient); $response = $apiClient->send_data([ 'referenceAnswer' => $data['referenceAnswer'], 'studentAnswers' => array_column($studentData, 'studentAnswer') ]); $grades = json_decode($response, true); error_log('After fetching question attempts'); } catch (Exception $e) { return json_encode(['status' => 'error', 'message' => 'API Error: ' . $e->getMessage()]); } // Возвращаем JSON с оценками и другими данными return json_encode([ 'status' => 'success', 'grades' => $grades, 'inputNames' => $inputNames, 'maxmark' => $maxmark ]); } }