Add quiz support: parse *_quiz_solved.txt files, take and grade quizzes

Scanner indexes quiz files found next to videos ([&] questions, "- "
options, "-- Correct" markers; _notsolved twins ignored). Quizzes appear
in the folder content list interleaved with videos by filename order.
New api/quiz.php serves questions without answers and grades attempts
server-side; per-user best/last score and attempts stored in
quiz_progress. Folder/course progress now aggregates videos + quizzes
with partial credit for partial scores.
This commit is contained in:
Harwinder Sekhon
2026-07-11 11:24:37 -04:00
parent 13856e35bc
commit c6a970880c
7 changed files with 467 additions and 28 deletions
+35
View File
@@ -41,6 +41,41 @@ CREATE TABLE IF NOT EXISTS videos (
INDEX idx_videos_folder (folder_id)
) ENGINE=InnoDB;
-- One row per "*_quiz_solved.txt" file found next to the videos.
-- Questions/options are parsed from the file on demand; only the count is
-- cached here for progress math.
CREATE TABLE IF NOT EXISTS quizzes (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
folder_id INT UNSIGNED NOT NULL,
name VARCHAR(255) NOT NULL, -- filename without the _quiz_solved.txt suffix
filename VARCHAR(255) NOT NULL,
path VARCHAR(700) NOT NULL UNIQUE,
num_questions INT UNSIGNED NOT NULL DEFAULT 0,
sort_order INT UNSIGNED NOT NULL DEFAULT 0,
is_missing TINYINT(1) NOT NULL DEFAULT 0,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT fk_quizzes_folder FOREIGN KEY (folder_id)
REFERENCES folders(id) ON DELETE CASCADE,
INDEX idx_quizzes_folder (folder_id)
) ENGINE=InnoDB;
-- Per-user quiz results. completed = every question answered correctly
-- in a single attempt (sticky).
CREATE TABLE IF NOT EXISTS quiz_progress (
user_id INT UNSIGNED NOT NULL,
quiz_id INT UNSIGNED NOT NULL,
best_score INT UNSIGNED NOT NULL DEFAULT 0,
last_score INT UNSIGNED NOT NULL DEFAULT 0,
total_questions INT UNSIGNED NOT NULL DEFAULT 0,
attempts INT UNSIGNED NOT NULL DEFAULT 0,
completed TINYINT(1) NOT NULL DEFAULT 0,
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (user_id, quiz_id),
CONSTRAINT fk_qp_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
CONSTRAINT fk_qp_quiz FOREIGN KEY (quiz_id) REFERENCES quizzes(id) ON DELETE CASCADE
) ENGINE=InnoDB;
-- Per-user playback state: resume position + completion flag.
CREATE TABLE IF NOT EXISTS video_progress (
user_id INT UNSIGNED NOT NULL,