Index: mod/quiz/lib.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/quiz/lib.php,v retrieving revision 1.282.2.19 diff -u -r1.282.2.19 lib.php --- mod/quiz/lib.php 14 Jan 2009 07:03:13 -0000 1.282.2.19 +++ mod/quiz/lib.php 18 Feb 2009 06:29:59 -0000 @@ -174,22 +174,39 @@ return $result; } +/** + * Get the best current grade for a particular user in a quiz. + * + * @param object $quiz the quiz object. + * @param integer $userid the id of the user. + * @return float the user's current grade for this quiz. + */ +function quiz_get_best_grade($quiz, $userid) { + $grade = get_field('quiz_grades', 'grade', 'quiz', $quiz->id, 'userid', $userid); + + // Need to detect errors/no result, without catching 0 scores. + if (is_numeric($grade)) { + return round($grade, $quiz->decimalpoints); + } else { + return NULL; + } +} + function quiz_user_outline($course, $user, $mod, $quiz) { /// Return a small object with summary information about what a /// user has done with a given particular instance of this module /// Used for user activity reports. /// $return->time = the time they did it /// $return->info = a short text description - if ($grade = get_record('quiz_grades', 'userid', $user->id, 'quiz', $quiz->id)) { - - $result = new stdClass; - if ((float)$grade->grade) { - $result->info = get_string('grade').': '.round($grade->grade, $quiz->decimalpoints); - } - $result->time = $grade->timemodified; - return $result; + $grade = quiz_get_best_grade($quiz, $user->id); + if (is_null($grade)) { + return NULL; } - return NULL; + + $result = new stdClass; + $result->info = get_string('grade') . ': ' . $grade . '/' . $quiz->grade; + $result->time = get_field('quiz_attempts', 'MAX(timefinish)', 'userid', $user->id, 'quiz', $quiz->id); + return $result; } function quiz_user_complete($course, $user, $mod, $quiz) { @@ -197,7 +214,7 @@ /// a given particular instance of this module, for user activity reports. if ($attempts = get_records_select('quiz_attempts', "userid='$user->id' AND quiz='$quiz->id'", 'attempt ASC')) { - if ($quiz->grade and $quiz->sumgrades && $grade = get_record('quiz_grades', 'userid', $user->id, 'quiz', $quiz->id)) { + if ($quiz->grade && $quiz->sumgrades && $grade = get_record('quiz_grades', 'userid', $user->id, 'quiz', $quiz->id)) { echo get_string('grade').': '.round($grade->grade, $quiz->decimalpoints).'/'.$quiz->grade.'
'; } foreach ($attempts as $attempt) { Index: mod/quiz/locallib.php =================================================================== RCS file: /cvsroot/moodle/moodle/mod/quiz/locallib.php,v retrieving revision 1.127.2.13 diff -u -r1.127.2.13 locallib.php --- mod/quiz/locallib.php 26 Sep 2008 05:55:37 -0000 1.127.2.13 +++ mod/quiz/locallib.php 18 Feb 2009 06:29:59 -0000 @@ -294,24 +294,6 @@ } /** - * Get the best current grade for a particular user in a quiz. - * - * @param object $quiz the quiz object. - * @param integer $userid the id of the user. - * @return float the user's current grade for this quiz. - */ -function quiz_get_best_grade($quiz, $userid) { - $grade = get_field('quiz_grades', 'grade', 'quiz', $quiz->id, 'userid', $userid); - - // Need to detect errors/no result, without catching 0 scores. - if (is_numeric($grade)) { - return round($grade, $quiz->decimalpoints); - } else { - return NULL; - } -} - -/** * Convert the raw grade stored in $attempt into a grade out of the maximum * grade for this quiz. *