Skip to content

🐛 Fix quiz total marks calculation when question order is random - #2983

Merged
shewa12 merged 6 commits into
devfrom
fix-random-quiz-total-marks
Sep 1, 2026
Merged

🐛 Fix quiz total marks calculation when question order is random#2983
shewa12 merged 6 commits into
devfrom
fix-random-quiz-total-marks

Conversation

@b-l-i-n-d

@b-l-i-n-d b-l-i-n-d commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator
  • Replaces multiple PHP usort/array_slice loops with a single SQL query in Quiz::get_quiz_total_marks()
  • Returns 0 immediately when random order is active and a question limit creates a true random subset (COUNT > max_questions)
  • Returns the full SUM for random order when all questions are shown (no limit, or limit ≥ pool size)
  • Deterministic orders (asc, desc, sorting) use a single subquery with an allowlisted ORDER BY clause and LIMIT
  • No-limit case (max_questions <= 0) uses a plain SUM query with no subquery or LIMIT
  • ORDER BY clause is built from a fixed PHP allowlist — no user input reaches the SQL string

@b-l-i-n-d b-l-i-n-d self-assigned this Aug 27, 2026
@b-l-i-n-d
b-l-i-n-d requested a review from shewa12 August 27, 2026 10:24
@b-l-i-n-d b-l-i-n-d added 4.0.7 Tutor v4.0.7 bug Something isn't working labels Aug 27, 2026
@shewa12
shewa12 merged commit f1b3da6 into dev Sep 1, 2026
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4.0.7 Tutor v4.0.7 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants