From 586b2c82ed58196ad9df5f91da6ab5c451b10afd Mon Sep 17 00:00:00 2001 From: kaipe Date: Sun, 3 Aug 2003 23:00:45 +0000 Subject: [PATCH] New quiz option - "Each attempt builds on the last" This makes it possible for students to take a tedious quiz, save it half-way and have it graded. The student can then, at a later point, get back to the quiz and have the previous answers already filled in and graded. The student can then continue with the remaining questions as well as redo all the answers that got wrong at the previous attempt. It seems to work fine with one little twisted exception: Say that the student attempts the quiz first and that the teacher thereafter edits the quiz and removes or adds a few questions. This will work out fine for as long as the teacher do not get the idea of adding a question with question type RANDOM. The quiz will be fully functional again after removing that RANDOM question or resetting the option 'Each attempt builds on the last" to NO. Not a very serious problem but it takes someone with greater insight in question type RANDOM to resolve it. As always, I can not commit lang/en/quiz.php. --- As I was using the function quiz_get_attempt_responses I had it refactored removing the obsolete argument $quiz. I also changed the call from review.php --- mod/quiz/attempt.php | 42 +++++++++++++++++++++++++++++++++++++++++- mod/quiz/lib.php | 8 ++++---- mod/quiz/mod.html | 18 ++++++++++++++++++ mod/quiz/review.php | 2 +- mod/quiz/version.php | 2 +- 5 files changed, 65 insertions(+), 7 deletions(-) diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index 326cb5ee75..f75903dd48 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 51481c45bb..0f07c75f95 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 749754a130..ac895a2a27 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 @@ ?> + +

:

+ + eachattemptbuildsonthelast", ""); + helpbutton("eachattemptbuildsonthelast", + get_string("eachattemptbuildsonthelast", "quiz"), + "quiz"); + ?> + +

:

diff --git a/mod/quiz/review.php b/mod/quiz/review.php index 4f6b478260..4dbeda2dc4 100644 --- a/mod/quiz/review.php +++ b/mod/quiz/review.php @@ -83,7 +83,7 @@ print_heading($quiz->name); - if (! $questions = quiz_get_attempt_responses($attempt, $quiz)) { + if (! $questions = quiz_get_attempt_responses($attempt)) { error("Could not reconstruct quiz results for attempt $attempt->id!"); } diff --git a/mod/quiz/version.php b/mod/quiz/version.php index b9e671c07d..8a469d25d2 100644 --- a/mod/quiz/version.php +++ b/mod/quiz/version.php @@ -5,7 +5,7 @@ // This fragment is called by moodle_needs_upgrading() and /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2003072901; // The (date) version of this module +$module->version = 2003080301; // The (date) version of this module $module->cron = 0; // How often should cron check this module (seconds)? ?> -- 2.39.5