The quiz system now has a complete workflow: Creation → Storage → Display → Playback → Scoring
Flow: Quiz Manager creates quiz → Questions stored → Published to users
Files Modified:
app/controllers/QuizmanagerController.php-save()method accepts JSON payloadapp/models/quiz.php-createQuiz()andaddQuestion()methodspublic/assets/js/quizcreate.js- Frontend question builder
What happens:
- Quiz manager fills in title, difficulty, duration, description
- Manager adds 1-20 questions with 4 options each
- Manager selects one correct answer per question
- On publish, frontend sends JSON to
/quizmanager/save - Backend creates quiz record and stores all questions + options
Tables Used:
quizzes- Main quiz metadataid,title,description,difficulty_level,duration,status,total_questions,manager_id,created_at
quiz_questions- Questions for each quizid,quiz_id,question_text,question_order
quiz_options- Answer options for each questionid,question_id,option_letter,option_text,is_correct
Flow: Users see published quizzes → Can filter, search, save for later
Files:
app/views/users/quiz.php- Displays quiz listpublic/assets/js/quiz.js- Quiz listing and filtering logicapp/controllers/UserdashboardController.php-quiz()method
What happens:
- User navigates to Quizzes section
- Backend calls
quiz->getQuizzesForUser()which queries active quizzes - Returns: Quiz title, difficulty, question count, duration, reward amount, user's previous score (if any)
- Frontend renders quiz cards with Start/Retake buttons
- User can save quiz for later or start immediately
Flow: User starts quiz → Questions displayed one per screen → Submit answers
Files:
app/views/users/take_quiz.php- Quiz interfacepublic/assets/js/take_quiz.js- Question rendering and answer trackingapp/controllers/UserdashboardController.php-takeQuiz()andsubmitQuiz()methods
What happens:
- User clicks "Start Quiz"
- Backend calls
quiz->startAttempt()- creates attempt record - Quiz questions loaded and displayed one per screen
- User selects option for each question
- Navigation between questions (Previous/Next)
- Submit button appears on last question
- User submits all answers
Flow: Submit answers → Calculate score → Award badge & reward → Show results
Process:
- Backend receives answers via POST to
/userdashboard/submitQuiz - Compare user answers against correct answers in database
- Calculate percentage score
- Check if score >= 70 (passing threshold)
- If passed: Award badge and Buckx reward
- Return results to frontend
- Display score, correct/incorrect count, earned badge
POST /quizmanager/save- Save quiz (requires JSON payload with questions)GET /quizmanager/getQuizzes- Get manager's quizzes (JSON response)GET /quizmanager- Dashboard viewGET /quizmanager/create- Create form
GET /userdashboard/quiz- List available quizzesGET /userdashboard/takeQuiz/{id}- Start quizPOST /userdashboard/submitQuiz- Submit answersPOST /userdashboard/toggleSaveQuiz- Save/unsave quiz
Quiz Manager
↓
[quizcreate.js] builds quiz JSON
↓
POST /quizmanager/save with JSON
↓
QuizmanagerController->save()
↓
quiz->createQuiz() + addQuestion()
↓
INSERT INTO quizzes, quiz_questions, quiz_options
↓
Quiz stored with status='active'
↓
↓
User Dashboard
↓
GET /userdashboard/quiz
↓
UserdashboardController->quiz()
↓
quiz->getQuizzesForUser()
↓
SELECT * FROM quizzes WHERE status='active'
↓
[quiz.js] renders quiz cards
↓
User clicks "Start Quiz"
↓
GET /userdashboard/takeQuiz/{id}
↓
quiz->startAttempt() creates attempt record
↓
[take_quiz.js] loads questions
↓
quiz->getQuizQuestions() fetches all questions + options
↓
User answers all questions
↓
POST /userdashboard/submitQuiz with answers
↓
UserdashboardController->submitQuiz()
↓
Compare answers vs quiz_options.is_correct
↓
Calculate score and award if passed
↓
quiz->completeAttempt()
↓
UPDATE user_quiz_attempts with score, passed status
↓
Return results to [take_quiz.js]
↓
Display score, badge earned, Buckx reward
-
Field Name Alignment
- Controller now sends
questionfield (nottext) - Mapped to
question_textin database - Mapped
correctAnswer→correctin frontend
- Controller now sends
-
Question Storage
- Fixed
addQuestion()to properly store 4 options with correct answer - Proper index mapping (0=A, 1=B, 2=C, 3=D)
- Fixed
-
Quiz Manager Dashboard
- Now fetches real quizzes from
quiz->getAllQuizzesForManager() - Displays actual quiz data instead of mock data
- Added
getQuizzes()endpoint for JSON response
- Now fetches real quizzes from
-
Answer Submission
- Properly normalizes answers format
- Compares selected_answer index against database is_correct flag
- Calculates percentage score
- Awards badges and Buckx based on difficulty level
To test the complete system:
-
Login as Quiz Manager
- Go to Quiz Manager Dashboard
- Click "Create New Quiz"
-
Create a Quiz
- Enter title: "JavaScript Basics"
- Select difficulty: "Beginner"
- Set duration: 30 minutes
- Add description: "Test your JavaScript knowledge"
-
Add Questions
- Click "Add Question"
- Question: "What is the correct way to declare a variable in JavaScript?"
- Options:
- A: var x = 5;
- B: variable x = 5;
- C: v x = 5;
- D: declare x = 5;
- Correct answer: A
- Add at least 3-5 questions
-
Publish Quiz
- Click "Publish Quiz"
- Confirm the action
- Should redirect to dashboard with success message
-
Login as Regular User
- Go to Dashboard
- Click "Quizzes" section
- You should see the published quiz
-
Take Quiz
- Click "Start Quiz"
- Answer all questions
- Click "Submit Quiz"
- View results with score and badge (if passed)
✅ Quiz saved to database with all questions ✅ Quiz appears in user's quiz list ✅ User can start and complete quiz ✅ Score calculated correctly (out of 100%) ✅ Badge awarded if score >= 70% ✅ Buckx reward credited (10 for Beginner, 20 for Intermediate, 30 for Expert) ✅ Quiz attempt saved for retakes ✅ Previous scores visible to user