Permalink
Browse files

MDL-30873 quiz: display an overall grade for preview users.

Also, don't display an overall grade unless there is at least one finished attempt.
  • Loading branch information...
1 parent 929c26c commit ed82e0379824d70e20d47461e4490eac988e4be7 @timhunt timhunt committed Dec 22, 2011
Showing with 11 additions and 2 deletions.
  1. +11 −2 mod/quiz/view.php
View
@@ -94,7 +94,16 @@
$numattempts = count($attempts);
// Work out the final grade, checking whether it was overridden in the gradebook.
-$mygrade = quiz_get_best_grade($quiz, $USER->id);
+if (!$canpreview) {
+ $mygrade = quiz_get_best_grade($quiz, $USER->id);
+} else if ($lastfinishedattempt) {
+ // Users who can preview the quiz don't get a proper grade, so work out a
+ // plausible value to display instead, so the page looks right.
+ $mygrade = quiz_rescale_grade($lastfinishedattempt->sumgrades, $quiz, false);
+} else {
+ $mygrade = null;
+}
+
$mygradeoverridden = false;
$gradebookfeedback = '';
@@ -137,7 +146,7 @@
$viewobj->gradecolumn = $someoptions->marks >= question_display_options::MARK_AND_MAX &&
quiz_has_grades($quiz);
$viewobj->markcolumn = $viewobj->gradecolumn && ($quiz->grade != $quiz->sumgrades);
- $viewobj->overallstats = $alloptions->marks >= question_display_options::MARK_AND_MAX;
+ $viewobj->overallstats = $lastfinishedattempt && $alloptions->marks >= question_display_options::MARK_AND_MAX;
$viewobj->feedbackcolumn = quiz_has_feedback($quiz) && $alloptions->overallfeedback;
} else {

0 comments on commit ed82e03

Please sign in to comment.