]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-16307: move quiz_get_best_grade() in lib.php, and fix the DB request of quiz_user...
authorjerome <jerome>
Tue, 2 Sep 2008 10:06:17 +0000 (10:06 +0000)
committerjerome <jerome>
Tue, 2 Sep 2008 10:06:17 +0000 (10:06 +0000)
mod/quiz/lib.php
mod/quiz/locallib.php

index 6d2c6a32afc029e1d4d1add41b4505997e5ba309..aae42f55890bddb986498fcc10741aa3e03e98a1 100644 (file)
@@ -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 . '<br />';
         }
index 17dbc0dbd0adab72fde461fc19b096143330ed93..e287248693fe144e4f2a22cfc6ef189ddda2fe05 100644 (file)
@@ -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