]> git.mjollnir.org Git - moodle.git/commitdiff
Improve the quiz_rescale_grade function, and call it from one other place, instead...
authortjhunt <tjhunt>
Tue, 18 Dec 2007 18:20:25 +0000 (18:20 +0000)
committertjhunt <tjhunt>
Tue, 18 Dec 2007 18:20:25 +0000 (18:20 +0000)
mod/quiz/locallib.php
mod/quiz/report/overview/report.php

index 2561b5f659e7e906389ace6794bdfcc3835d1a58..0e0123a58270cc62309ab7ce11c9538ae4a8a6b1 100644 (file)
@@ -303,7 +303,7 @@ function quiz_get_best_grade($quiz, $userid) {
 
     // Need to detect errors/no result, without catching 0 scores.
     if (is_numeric($grade)) {
-        return round($grade,$quiz->decimalpoints);
+        return round($grade, $quiz->decimalpoints);
     } else {
         return NULL;
     }
@@ -317,12 +317,16 @@ function quiz_get_best_grade($quiz, $userid) {
  * @param object $quiz the quiz object. Only the fields grade, sumgrades and decimalpoints are used.
  * @return float the rescaled grade.
  */
-function quiz_rescale_grade($rawgrade, $quiz) {
+function quiz_rescale_grade($rawgrade, $quiz, $round = true) {
     if ($quiz->sumgrades) {
-        return round($rawgrade*$quiz->grade/$quiz->sumgrades, $quiz->decimalpoints);
+        $grade = $rawgrade * $quiz->grade / $quiz->sumgrades;
+        if ($round) {
+            $grade = round($grade, $quiz->decimalpoints);
+        }
     } else {
-        return 0;
+        $grade = 0;
     }
+    return $grade;
 }
 
 /**
index 8906cae13f74df0d85f014356b1308914e9cc1d5..d2c15952d4b722316297298c9e6af60df234d5f6 100644 (file)
@@ -492,7 +492,7 @@ class quiz_report extends quiz_default_report {
                     // Grades columns.
                     if ($showgrades) {
                         if ($attempt->timefinish) {
-                            $grade = round($attempt->sumgrades / $quiz->sumgrades * $quiz->grade,$quiz->decimalpoints);
+                            $grade = quiz_rescale_grade($attempt->sumgrades, $quiz);
                             if (!$download) {
                                 $row[] = '<a href="review.php?q='.$quiz->id.'&amp;attempt='.$attempt->attempt.'">'.$grade.'</a>';
                             } else {