From: tjhunt Date: Fri, 21 Sep 2007 16:01:40 +0000 (+0000) Subject: MDL-10030 - the logic controlling whether students were allowed to see the review... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=a4faed6925f6175d6b498d65b55cba50f4870a0d;p=moodle.git MDL-10030 - the logic controlling whether students were allowed to see the review screen was wrong. --- diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index fb6b8b24d2..e451724fca 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -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; diff --git a/mod/quiz/review.php b/mod/quiz/review.php index bd20a8ef94..c21ac84f8d 100644 --- a/mod/quiz/review.php +++ b/mod/quiz/review.php @@ -46,15 +46,28 @@ $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 { ?>