diff --git a/backend/app/Services/AiVideoAnalyzerService.php b/backend/app/Services/AiVideoAnalyzerService.php index 0462ec0..ba8f648 100644 --- a/backend/app/Services/AiVideoAnalyzerService.php +++ b/backend/app/Services/AiVideoAnalyzerService.php @@ -48,52 +48,56 @@ class AiVideoAnalyzerService // 3. Save Socratic Checkpoints into exams, questions, question_options if (!empty($analysisResult['socratic_checkpoints'])) { foreach ($analysisResult['socratic_checkpoints'] as $cp) { - $examUuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', - mt_rand(0, 0xffff), mt_rand(0, 0xffff), - mt_rand(0, 0xffff), - mt_rand(0, 0x0fff) | 0x4000, - mt_rand(0, 0x3fff) | 0x8000, - mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) - ); - - $examId = Database::insert( - "INSERT INTO exams (uuid, course_id, lesson_id, creator_type, scope, title, timestamp_seconds, rewind_on_fail_seconds, passing_percentage, total_points, is_mandatory, is_published) - VALUES (?, ?, ?, 'system', 'in_video_checkpoint', ?, ?, ?, 100.00, 10, 1, 1)", - [ - $examUuid, - $courseId, - $lessonId, - $cp['question_text'], - (int)$cp['timestamp_seconds'], - (int)($cp['rewind_seconds'] ?? 45) - ] - ); - - $qUuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', - mt_rand(0, 0xffff), mt_rand(0, 0xffff), - mt_rand(0, 0xffff), - mt_rand(0, 0x0fff) | 0x4000, - mt_rand(0, 0x3fff) | 0x8000, - mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) - ); - - $qId = Database::insert( - "INSERT INTO questions (uuid, exam_id, question_text, question_type, bloom_taxonomy, explanation_text, points) - VALUES (?, ?, ?, 'multiple_choice', 'comprehension', ?, 10)", - [ - $qUuid, - $examId, - $cp['question_text'], - $cp['explanation'] ?? 'تطبيق مباشر لقواعد المنهاج المعتمد' - ] - ); - - $correctIdx = (int)($cp['correct_index'] ?? 0); - foreach ($cp['options'] as $idx => $optText) { - Database::insert( - "INSERT INTO question_options (question_id, option_text, is_correct) VALUES (?, ?, ?)", - [$qId, $optText, ($idx === $correctIdx) ? 1 : 0] + try { + $examUuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', + mt_rand(0, 0xffff), mt_rand(0, 0xffff), + mt_rand(0, 0xffff), + mt_rand(0, 0x0fff) | 0x4000, + mt_rand(0, 0x3fff) | 0x8000, + mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) ); + + $examId = Database::insert( + "INSERT INTO exams (uuid, course_id, lesson_id, creator_type, scope, title, timestamp_seconds, rewind_on_fail_seconds, passing_percentage, total_points, is_mandatory, is_published) + VALUES (?, ?, ?, 'ai_adaptive', 'in_video_checkpoint', ?, ?, ?, 100.00, 10, 1, 1)", + [ + $examUuid, + $courseId, + $lessonId, + $cp['question_text'], + (int)$cp['timestamp_seconds'], + (int)($cp['rewind_seconds'] ?? 45) + ] + ); + + $qUuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', + mt_rand(0, 0xffff), mt_rand(0, 0xffff), + mt_rand(0, 0xffff), + mt_rand(0, 0x0fff) | 0x4000, + mt_rand(0, 0x3fff) | 0x8000, + mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) + ); + + $qId = Database::insert( + "INSERT INTO questions (uuid, exam_id, question_text, question_type, bloom_taxonomy, explanation_text, points) + VALUES (?, ?, ?, 'multiple_choice', 'comprehension', ?, 10)", + [ + $qUuid, + $examId, + $cp['question_text'], + $cp['explanation'] ?? 'تطبيق مباشر لقواعد المنهاج المعتمد' + ] + ); + + $correctIdx = (int)($cp['correct_index'] ?? 0); + foreach ($cp['options'] as $idx => $optText) { + Database::insert( + "INSERT INTO question_options (question_id, option_text, is_correct) VALUES (?, ?, ?)", + [$qId, $optText, ($idx === $correctIdx) ? 1 : 0] + ); + } + } catch (\Throwable $e) { + error_log("Checkpoint insert error: " . $e->getMessage()); } } } diff --git a/backend/app/Views/TeacherPortal.php b/backend/app/Views/TeacherPortal.php index bf80ab5..ee8014b 100644 --- a/backend/app/Views/TeacherPortal.php +++ b/backend/app/Views/TeacherPortal.php @@ -1287,7 +1287,8 @@ class TeacherPortal alert('❌ ' + (data.message || 'فشل رفع الفيديو')); } } catch (err) { - alert('❌ خطأ في معالجة استجابة السيرفر'); + console.error('Response:', xhr.responseText); + alert('❌ خطأ في معالجة استجابة السيرفر:\n' + (xhr.responseText ? xhr.responseText.substring(0, 250) : 'استجابة فارغة')); } };