]> git.mjollnir.org Git - moodle.git/commitdiff
mod/quiz/index changes to only display quiz grades when teacher allows
authormjollnir_ <mjollnir_>
Tue, 18 Apr 2006 22:55:28 +0000 (22:55 +0000)
committermjollnir_ <mjollnir_>
Tue, 18 Apr 2006 22:55:28 +0000 (22:55 +0000)
Changes to index.php to only allow student to view overall quiz scores when
teacher has not set options forbidding this, and it can't give away what
scores were for attempts where results should still be hidden.
Credit: Peter Bulmer peterbulmer@catalyst.net.nz

mod/quiz/index.php
mod/quiz/locallib.php

index 71c0f335375d64b265dd506ec528ff70501d0b38..e8f2986f8e3b3e78afe2cca6caf21d68aca92114 100644 (file)
                 $gradecol = "";
             }
         } else {
+            // If student has no grade for this quiz, 
+            // or the quiz has no grade, display nothing in grade col
             if ($bestgrade === NULL || $quiz->grade == 0) {
                 $gradecol = "";
             } else {
-                $gradecol = "$bestgrade / $quiz->grade";
+                //If all quiz's attempts have visible results, show bestgrade
+                if(all_attempt_results_visible($quiz, $USER)) {
+                    $gradecol = "$bestgrade / $quiz->grade";
+                } else {
+                    $gradecol = "";
+                }
             }
         }
 
index 5fcea170a4fa1d16f1a21939589f9f75021cf8a1..afd7670858186bee20f655251f21fac59e9f8630 100644 (file)
@@ -550,5 +550,31 @@ function quiz_get_reviewoptions($quiz, $attempt, $isteacher=false) {
 
     return $options;
 }
+////////////////////////////////////////////////////////////////////////////////
+/**
+* Return boolean indicating if the quiz has attempts with hidden grades
+*
+* Selects all attempts matching specified quiz & user, and examines each to
+* check they all have visible results.
+* @return boolean        If the quiz has attempts without visible results
+* @param object $quiz    The quiz being examined
+* @param object $user    The user concerned
+*/
+function all_attempt_results_visible($quiz, $user) {
+    global $CFG;
+    $sql = 'SELECT timefinish, preview FROM '.$CFG->prefix.'quiz_attempts qa'.
+        ' WHERE qa.quiz='.$quiz->id.' AND qa.userid='.$user->id.
+        ' ORDER BY id DESC';
+    $attempts = get_records_sql($sql);
+    foreach ($attempts as $attempt) {            
+        $attemptoptions = quiz_get_reviewoptions($quiz, $attempt);
+        //if any attempt has scores option not set, not all attempt results are
+        //visible
+        if (!$attemptoptions->scores) {
+           return false;
+        }
+    }
+    return true;
+}
 
 ?>