fix: Align exams creator_type enum to ai_adaptive and add fault-tolerant checkpoint generation
This commit is contained in:
@@ -48,52 +48,56 @@ class AiVideoAnalyzerService
|
|||||||
// 3. Save Socratic Checkpoints into exams, questions, question_options
|
// 3. Save Socratic Checkpoints into exams, questions, question_options
|
||||||
if (!empty($analysisResult['socratic_checkpoints'])) {
|
if (!empty($analysisResult['socratic_checkpoints'])) {
|
||||||
foreach ($analysisResult['socratic_checkpoints'] as $cp) {
|
foreach ($analysisResult['socratic_checkpoints'] as $cp) {
|
||||||
$examUuid = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
|
try {
|
||||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff),
|
$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, 0xffff),
|
||||||
mt_rand(0, 0x3fff) | 0x8000,
|
mt_rand(0, 0x0fff) | 0x4000,
|
||||||
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
|
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]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1287,7 +1287,8 @@ class TeacherPortal
|
|||||||
alert('❌ ' + (data.message || 'فشل رفع الفيديو'));
|
alert('❌ ' + (data.message || 'فشل رفع الفيديو'));
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert('❌ خطأ في معالجة استجابة السيرفر');
|
console.error('Response:', xhr.responseText);
|
||||||
|
alert('❌ خطأ في معالجة استجابة السيرفر:\n' + (xhr.responseText ? xhr.responseText.substring(0, 250) : 'استجابة فارغة'));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user