From 8264da3c50575347a245f6f00d6430964dab2241 Mon Sep 17 00:00:00 2001 From: gustav_delius Date: Wed, 6 Jul 2005 19:26:19 +0000 Subject: [PATCH] Fixed bug 3684 --- mod/quiz/locallib.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/mod/quiz/locallib.php b/mod/quiz/locallib.php index 8a032a9ff32..2d4594b07f4 100644 --- a/mod/quiz/locallib.php +++ b/mod/quiz/locallib.php @@ -1229,10 +1229,10 @@ function quiz_restore_question_sessions(&$questions, $quiz, $attempt) { } } else { // Create a new state object - if ($quiz->attemptonlast and $attempt->attempt > 1) { + if ($quiz->attemptonlast and $attempt->attempt > 1 and !$attempt->preview) { // build on states from last attempt - if (empty($lastattemptid)) { - $lastattemptid = get_field('quiz_attempts', 'id', 'quiz', $attempt->quiz, 'userid', $attempt->userid, 'attempt', $attempt->attempt-1); + if (!$lastattemptid = get_field('quiz_attempts', 'id', 'quiz', $attempt->quiz, 'userid', $attempt->userid, 'attempt', $attempt->attempt-1)) { + error('Could not find previous attempt to build on'); } // Load the last graded state for the question $sql = "SELECT $statefields". @@ -1241,7 +1241,9 @@ function quiz_restore_question_sessions(&$questions, $quiz, $attempt) { " WHERE s.id = n.newgraded". " AND n.attemptid = '$lastattemptid'". " AND n.questionid = '$i'"; - $states[$i] = get_record_sql($sql); + if (!$states[$i] = get_record_sql($sql)) { + error('Could not find state for previous attempt to build on'); + } quiz_restore_state($questions[$i], $states[$i]); $states[$i]->attempt = $attempt->id; $states[$i]->question = (int) $i; @@ -1252,6 +1254,7 @@ function quiz_restore_question_sessions(&$questions, $quiz, $attempt) { $states[$i]->raw_grade = ''; $states[$i]->penalty = ''; $states[$i]->sumpenalty = '0.0'; + $states[$i]->changed = true; $states[$i]->last_graded = new object; $states[$i]->last_graded->attempt = $attempt->id; $states[$i]->last_graded->question = (int) $i; @@ -1298,8 +1301,7 @@ function quiz_restore_question_sessions(&$questions, $quiz, $attempt) { * Creates the run-time fields for the states * * Extends the state objects for a question by calling -* {@link restore_session_and_responses()} or it creates a new one by -* calling {@link create_session_and_responses()} +* {@link restore_session_and_responses()} * @return boolean Represents success or failure * @param array $questions The questions for which states are needed * @param array $states The states as loaded from the database, indexed