From 40f6f97f76d50d73945adcc3860e367e1f81b332 Mon Sep 17 00:00:00 2001 From: jerome Date: Tue, 2 Sep 2008 10:06:17 +0000 Subject: [PATCH] MDL-16307: move quiz_get_best_grade() in lib.php, and fix the DB request of quiz_user_complete() --- mod/quiz/lib.php | 22 +++++++++++++++++++++- mod/quiz/locallib.php | 18 ------------------ 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 6d2c6a32af..aae42f5589 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -213,12 +213,32 @@ function quiz_user_outline($course, $user, $mod, $quiz) { return NULL; } +/** + * 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, or NULL if this user does + * not have a grade on this quiz. + */ +function quiz_get_best_grade($quiz, $userid) { + global $DB; + $grade = $DB->get_field('quiz_grades', 'grade', array('quiz' => $quiz->id, 'userid' => $userid)); + + // Need to detect errors/no result, without catching 0 scores. + if (is_numeric($grade)) { + return quiz_format_grade($quiz, $grade); + } else { + return NULL; + } +} + function quiz_user_complete($course, $user, $mod, $quiz) { global $DB; /// Print a detailed representation of what a user has done with /// a given particular instance of this module, for user activity reports. - if ($attempts = $DB->get_records_select('quiz_attempts', "userid=? AND quiz=?", 'attempt ASC', array($user->id, $quiz->id))) { + if ($attempts = $DB->get_records_select('quiz_attempts', "userid=? AND quiz=?", array($user->id, $quiz->id), 'attempt ASC')) { if ($quiz->grade && $quiz->sumgrades && $grade = quiz_get_best_grade($quiz, $user->id)) { echo get_string('grade') . ': ' . $grade . '/' . $quiz->grade . '
'; } diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index 17dbc0dbd0..e287248693 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -366,25 +366,7 @@ function quiz_get_all_question_grades($quiz) { return $grades; } -/** - * 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, or NULL if this user does - * not have a grade on this quiz. - */ -function quiz_get_best_grade($quiz, $userid) { - global $DB; - $grade = $DB->get_field('quiz_grades', 'grade', array('quiz' => $quiz->id, 'userid' => $userid)); - // Need to detect errors/no result, without catching 0 scores. - if (is_numeric($grade)) { - return quiz_format_grade($quiz, $grade); - } else { - return NULL; - } -} /** * Convert the raw grade stored in $attempt into a grade out of the maximum -- 2.39.5