Skip to content

Commit

Permalink
MDL-26505 rounding problem in quiz_save_best_grade.
Browse files Browse the repository at this point in the history
Note I cheated and slipped in a fix for another instance of MDL-21811 too, since I noticed it at the same time.
  • Loading branch information
timhunt committed Feb 18, 2011
1 parent 0af9124 commit 49b2521
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mod/quiz/index.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
$feedback = ''; $feedback = '';
if ($quiz->grade && !is_null($bestgrade)) { if ($quiz->grade && !is_null($bestgrade)) {
if ($alloptions->scores) { if ($alloptions->scores) {
$grade = "$bestgrade / $quiz->grade"; $grade = round($bestgrade, $quiz->decimalpoints) . ' / ' . $quiz->grade;
} }
if ($alloptions->overallfeedback) { if ($alloptions->overallfeedback) {
$feedback = quiz_feedback_for_grade($bestgrade, $quiz->id); $feedback = quiz_feedback_for_grade($bestgrade, $quiz->id);
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/lib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function quiz_get_best_grade($quiz, $userid) {


// Need to detect errors/no result, without catching 0 scores. // Need to detect errors/no result, without catching 0 scores.
if (is_numeric($grade)) { if (is_numeric($grade)) {
return round($grade, $quiz->decimalpoints); return $grade + 0;
} else { } else {
return NULL; return NULL;
} }
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/locallib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ function quiz_save_best_grade($quiz, $userid = null) {


// Calculate the best grade // Calculate the best grade
$bestgrade = quiz_calculate_best_grade($quiz, $attempts); $bestgrade = quiz_calculate_best_grade($quiz, $attempts);
$bestgrade = quiz_rescale_grade($bestgrade, $quiz); $bestgrade = quiz_rescale_grade($bestgrade, $quiz, false);


// Save the best grade in the database // Save the best grade in the database
if ($grade = get_record('quiz_grades', 'quiz', $quiz->id, 'userid', $userid)) { if ($grade = get_record('quiz_grades', 'quiz', $quiz->id, 'userid', $userid)) {
Expand Down
6 changes: 3 additions & 3 deletions mod/quiz/view.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@
} }


// Ouside the if because we may be showing feedback but not grades. // Ouside the if because we may be showing feedback but not grades.
$attemptgrade = quiz_rescale_grade($attempt->sumgrades, $quiz); $attemptgrade = quiz_rescale_grade($attempt->sumgrades, $quiz, false);


if ($gradecolumn) { if ($gradecolumn) {
if ($attemptoptions->scores && $attempt->timefinish > 0) { if ($attemptoptions->scores && $attempt->timefinish > 0) {
$formattedgrade = $attemptgrade; $formattedgrade = round($attemptgrade, $quiz->decimalpoints);
// highlight the highest grade if appropriate // highlight the highest grade if appropriate
if ($overallstats && $numattempts > 1 && !is_null($mygrade) && $attemptgrade == $mygrade && $quiz->grademethod == QUIZ_GRADEHIGHEST) { if ($overallstats && $numattempts > 1 && !is_null($mygrade) && $attemptgrade == $mygrade && $quiz->grademethod == QUIZ_GRADEHIGHEST) {
$table->rowclass[$attempt->attempt] = 'bestrow'; $table->rowclass[$attempt->attempt] = 'bestrow';
Expand Down Expand Up @@ -313,7 +313,7 @@
if ($available && $moreattempts) { if ($available && $moreattempts) {
$a = new stdClass; $a = new stdClass;
$a->method = quiz_get_grading_option_name($quiz->grademethod); $a->method = quiz_get_grading_option_name($quiz->grademethod);
$a->mygrade = $mygrade; $a->mygrade = round($mygrade, $quiz->decimalpoints);
$a->quizgrade = $quiz->grade; $a->quizgrade = $quiz->grade;
$resultinfo .= print_heading(get_string('gradesofar', 'quiz', $a), '', 2, 'main', true); $resultinfo .= print_heading(get_string('gradesofar', 'quiz', $a), '', 2, 'main', true);
} else { } else {
Expand Down

0 comments on commit 49b2521

Please sign in to comment.