diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php
index 326cb5ee75f2d..f75903dd488d7 100644
--- a/mod/quiz/attempt.php
+++ b/mod/quiz/attempt.php
@@ -191,7 +191,47 @@
echo "
";
- if (! quiz_print_quiz_questions($quiz)) {
+ $result = NULL; // Default
+ $questions = NULL; // Default
+ if ($quiz->eachattemptbuildsonthelast) {
+ $latestfinishedattempt->attempt = 0;
+ foreach ($attempts as $attempt) {
+ if ($attempt->timefinish
+ && $attempt->attempt > $latestfinishedattempt->attempt)
+ {
+ $latestfinishedattempt = $attempt;
+ }
+ }
+ if ($latestfinishedattempt->attempt > 0
+ and $questions =
+ quiz_get_attempt_responses($latestfinishedattempt))
+ {
+ // An previous attempt to continue on is found:
+ quiz_remove_unwanted_questions($questions, $quiz); // In case the quiz has been changed
+
+ if (!($result = quiz_grade_attempt_results($quiz, $questions))) {
+ // No results, reset to defaults:
+ $questions = NULL;
+ $result = NULL;
+
+ } else {
+ // We're on, latest attempt responses are to be included.
+ // In order to have this accomplished by
+ // the method quiz_print_quiz_questions we need to
+ // temporarilly change some of the $quiz attributes
+ // and remove some of the information from result.
+
+ $quiz->correctanswers = false; // Not a good idea to show them, huh?
+ $result->feedback = array(); // Not to be printed
+ $result->attemptbuildsonthelast = true;
+ }
+
+ } else {
+ // No latest attempt, or latest attempt was empty - Reset to defaults
+ $questions = NULL;
+ }
+ }
+ if (! quiz_print_quiz_questions($quiz, $result, $questions)) {
print_continue("view.php?id=$cm->id");
}
diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php
index 51481c45bb0d5..0f07c75f95880 100644
--- a/mod/quiz/lib.php
+++ b/mod/quiz/lib.php
@@ -338,7 +338,7 @@ function quiz_get_answers($question, $answerids=NULL) {
}
-function quiz_get_attempt_responses($attempt, $quiz) {
+function quiz_get_attempt_responses($attempt) {
// Given an attempt object, this function gets all the
// stored responses and returns them in a format suitable
// for regrading using quiz_grade_attempt_results()
@@ -598,7 +598,7 @@ function quiz_print_question($number, $question, $grade, $courseid,
$answer = $answers[$answerid];
$qnumchar = chr(ord('a') + $key);
- if (empty($feedback) or empty($response[$answerid])) {
+ if (empty($response[$answerid])) {
$checked = "";
} else {
$checked = "CHECKED";
@@ -990,7 +990,7 @@ function quiz_print_quiz_questions($quiz, $results=NULL, $questions=NULL, $shuff
echo "
";
}
- if (empty($results)) {
+ if (empty($results) || $results->attemptbuildsonthelast) {
if (!empty($quiz->shufflequestions)) { // Things have been mixed up, so pass the question order
$shuffleorder = implode(',', $questionorder);
echo "\n";
@@ -2234,7 +2234,7 @@ function quiz_save_question_options($question) {
function quiz_remove_unwanted_questions(&$questions, $quiz) {
/// Given an array of questions, and a list of question IDs,
/// this function removes unwanted questions from the array
-/// Used by review.php to counter changing quizzes
+/// Used by review.php and attempt.php to counter changing quizzes
$quizquestions = array();
$quizids = explode(",", $quiz->questions);
diff --git a/mod/quiz/mod.html b/mod/quiz/mod.html
index 749754a1303cc..ac895a2a27c5e 100644
--- a/mod/quiz/mod.html
+++ b/mod/quiz/mod.html
@@ -19,6 +19,9 @@
if (!isset($form->attempts)) {
$form->attempts = 0;
}
+ if (!isset($form->eachattemptbuildsonthelast)) {
+ $form->eachattemptbuildsonthelast = 0;
+ }
if (!isset($form->grademethod)) {
$form->grademethod = "";
}
@@ -130,6 +133,21 @@
?>
+
:
: