]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-10030 - the logic controlling whether students were allowed to see the review...
authortjhunt <tjhunt>
Fri, 21 Sep 2007 16:01:40 +0000 (16:01 +0000)
committertjhunt <tjhunt>
Fri, 21 Sep 2007 16:01:40 +0000 (16:01 +0000)
mod/quiz/locallib.php
mod/quiz/review.php

index fb6b8b24d2e4f1130dac5afd351b4b4b662c17de..e451724fca089ce66985bcc664687c540293aea4 100644 (file)
@@ -34,6 +34,16 @@ define("QUIZ_ATTEMPTFIRST", "3");
 define("QUIZ_ATTEMPTLAST",  "4");
 /**#@-*/
 
+/**#@+
+ * Constants to describe the various states a quiz attempt can be in.
+ */
+define('QUIZ_STATE_DURING', 'during'); 
+define('QUIZ_STATE_IMMEDIATELY', 'immedately'); 
+define('QUIZ_STATE_OPEN', 'open'); 
+define('QUIZ_STATE_CLOSED', 'closed'); 
+define('QUIZ_STATE_TEACHERACCESS', 'teacheraccess'); // State only relevant if you are in a studenty role.
+/**#@-*/
+
 /// Functions related to attempts /////////////////////////////////////////
 
 /**
@@ -680,6 +690,7 @@ function quiz_get_renderoptions($reviewoptions, $state) {
     // Always show responses and scores
     $options->responses = true;
     $options->scores = true;
+    $options->quizstate = QUIZ_STATE_DURING;
 
     return $options;
 }
@@ -712,6 +723,7 @@ function quiz_get_reviewoptions($quiz, $attempt, $context=null) {
         $options->solutions = false;
         $options->generalfeedback = true;
         $options->overallfeedback = true;
+        $options->quizstate = QUIZ_STATE_TEACHERACCESS;
 
         // Show a link to the comment box only for closed attempts
         if ($attempt->timefinish) {
@@ -720,10 +732,13 @@ function quiz_get_reviewoptions($quiz, $attempt, $context=null) {
     } else {
         if (((time() - $attempt->timefinish) < 120) || $attempt->timefinish==0) {
             $quiz_state_mask = QUIZ_REVIEW_IMMEDIATELY;
+            $options->quizstate = QUIZ_STATE_IMMEDIATELY;
         } else if (!$quiz->timeclose or time() < $quiz->timeclose) {
             $quiz_state_mask = QUIZ_REVIEW_OPEN;
+            $options->quizstate = QUIZ_STATE_OPEN;
         } else {
             $quiz_state_mask = QUIZ_REVIEW_CLOSED;
+            $options->quizstate = QUIZ_STATE_CLOSED;
         }
         $options->responses = ($quiz->review & $quiz_state_mask & QUIZ_REVIEW_RESPONSES) ? 1 : 0;
         $options->scores = ($quiz->review & $quiz_state_mask & QUIZ_REVIEW_SCORES) ? 1 : 0;
index bd20a8ef94b97f6f6122c4317d1426fefc3520d3..c21ac84f8d1d9fea87b5243da37d44c2e7300ed6 100644 (file)
     $options = quiz_get_reviewoptions($quiz, $attempt, $context);
     $popup = $isteacher ? 0 : $quiz->popup; // Controls whether this is shown in a javascript-protected window.
 
+    $timenow = time();
     if (!has_capability('mod/quiz:viewreports', $context)) {
+        // Can't review during the attempt.
         if (!$attempt->timefinish) {
-            redirect('attempt.php?q='.$quiz->id);
+            redirect('attempt.php?q=' . $quiz->id);
         }
-        // If not even responses are to be shown in review then we
-        // don't allow any review
-        if (!($quiz->review & QUIZ_REVIEW_RESPONSES)) {
+        // Can't review other student's attempts.
+        if ($attempt->userid != $USER->id) {
+            error("This is not your attempt!", 'view.php?q=' . $quiz->id);
+        }
+        // Can't review if Student's may review ... Responses is turned on.
+        if (!$options->responses) {
+            if ($options->quizstate == QUIZ_STATE_IMMEDIATELY) {
+                $message = '';
+            } else if ($options->quizstate == QUIZ_STATE_OPEN && $quiz->timeclose &&
+                        ($quiz->review & QUIZ_REVIEW_CLOSED & QUIZ_REVIEW_RESPONSES)) {
+                $message = get_string('noreviewuntil', 'quiz', userdate($quiz->timeclose));
+            } else {
+                $message = get_string('noreview', 'quiz');
+            }
             if (empty($popup)) {
-                redirect('view.php?q='.$quiz->id);
+                redirect('view.php?q=' . $quiz->id, $message);
             } else {
                 ?><script type="text/javascript">
                 opener.document.location.reload();
                 die();
             }
         }
-        if ((time() - $attempt->timefinish) > 120) { // always allow review right after attempt
-            if ((!$quiz->timeclose or time() < $quiz->timeclose) and !($quiz->review & QUIZ_REVIEW_OPEN)) {
-                redirect('view.php?q='.$quiz->id, get_string("noreviewuntil", "quiz", userdate($quiz->timeclose)));
-            }
-            if ($quiz->timeclose and time() >= $quiz->timeclose and !($quiz->review & QUIZ_REVIEW_CLOSED)) {
-                redirect('view.php?q='.$quiz->id, get_string("noreview", "quiz"));
-            }
-        }
-        if ($attempt->userid != $USER->id) {
-            error("This is not your attempt!", 'view.php?q='.$quiz->id);
-        }
     }
 
     add_to_log($course->id, "quiz", "review", "review.php?id=$cm->id&amp;attempt=$attempt->id", "$quiz->id", "$cm->id");