Fix curriculum grounding for Grade 10: replace calculus fallback with authentic Systems of Equations questions and add self-healing guard
This commit is contained in:
@@ -423,6 +423,29 @@ class VideoController
|
||||
|
||||
$lessonId = (int)$lesson['id'];
|
||||
|
||||
// Self-Healing Curriculum Guard: Purge any obsolete/mismatched calculus questions
|
||||
// for non-calculus lessons (e.g. Grade 10 Systems of Equations)
|
||||
$isCalculusLesson = (str_contains($lesson['title'], 'اشتقاق') || str_contains($lesson['title'], 'تفاضل'));
|
||||
if (!$isCalculusLesson) {
|
||||
try {
|
||||
$mismatched = Database::selectOne(
|
||||
"SELECT q.id FROM questions q
|
||||
JOIN exams e ON q.exam_id = e.id
|
||||
WHERE e.lesson_id = ? AND (q.question_text LIKE '%مشتق%' OR q.question_text LIKE '%f\'(x)%')
|
||||
LIMIT 1",
|
||||
[$lessonId]
|
||||
);
|
||||
if ($mismatched) {
|
||||
$badExams = Database::select("SELECT id FROM exams WHERE lesson_id = ? AND scope = 'in_video_checkpoint'", [$lessonId]);
|
||||
foreach ($badExams as $be) {
|
||||
Database::query("DELETE FROM exams WHERE id = ?", [$be['id']]);
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
error_log("Curriculum self-healing notice: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// If lesson has no checkpoints or missing questions, generate them autonomously
|
||||
$existingCount = Database::selectOne("SELECT COUNT(*) as cnt FROM exams WHERE lesson_id = ? AND scope = 'in_video_checkpoint'", [$lessonId]);
|
||||
$existingQuestions = Database::selectOne("SELECT COUNT(*) as cnt FROM questions q JOIN exams e ON q.exam_id = e.id WHERE e.lesson_id = ?", [$lessonId]);
|
||||
|
||||
Reference in New Issue
Block a user