From 96192c4459f5a3c054ced82aa4b0781d696bb51c Mon Sep 17 00:00:00 2001 From: moodler Date: Wed, 16 Apr 2003 13:10:48 +0000 Subject: [PATCH] After doing a quiz that has been shuffled, present the feedback in the same order. Note that shuffled ANSWERS may still appear reshuffled. When viewing reports, all shuffling is switched off so that quizzes always appear in the default order (for easier comparison). Also a few tweaks, robustness etc --- mod/quiz/attempt.php | 8 +++++++- mod/quiz/lib.php | 33 ++++++++++++++++++++++++--------- mod/quiz/report.php | 2 ++ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index 921b4247e8..2db51c8fc8 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -78,6 +78,8 @@ $rawanswers = (array)$rawanswers; + $shuffleorder = NULL; + unset($rawanswers["q"]); // quiz id if (! count($rawanswers)) { print_heading(get_string("noanswers", "quiz")); @@ -116,6 +118,8 @@ } else { error("Answer received for non-existent question ($key)!"); } + } else if ($key == "shuffleorder") { + $shuffleorder = explode(",", $value); // Actual order questions were given in } } @@ -142,7 +146,9 @@ print_continue("view.php?id=$cm->id"); if ($quiz->feedback) { - quiz_print_quiz_questions($quiz, $result, $questions); + $quiz->shufflequestions = false; + $quiz->shuffleanswers = false; + quiz_print_quiz_questions($quiz, $result, $questions, $shuffleorder); print_continue("view.php?id=$cm->id"); } diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index a2e1acdbf7..26326c3a08 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -565,14 +565,16 @@ function quiz_print_question($number, $question, $grade, $courseid, if (!$subquestions = get_records_list("quiz_match_sub", "id", $options->subquestions)) { notify("Error: Missing subquestions for this question!"); } - if ($shuffleanswers) { - $subquestions = draw_rand_array($subquestions, count($subquestions)); + if (!empty($question->questiontext)) { + echo text_to_html($question->questiontext); } - echo text_to_html($question->questiontext); - if ($question->image) { + if (!empty($question->image)) { print_file_picture($question->image, $courseid, QUIZ_PICTURE_DEFAULT_HEIGHT); } + if ($shuffleanswers) { + $subquestions = draw_rand_array($subquestions, count($subquestions)); + } foreach ($subquestions as $subquestion) { $answers[$subquestion->id] = $subquestion->answertext; } @@ -711,7 +713,7 @@ function quiz_print_question($number, $question, $grade, $courseid, -function quiz_print_quiz_questions($quiz, $results=NULL, $questions=NULL) { +function quiz_print_quiz_questions($quiz, $results=NULL, $questions=NULL, $shuffleorder=NULL) { // Prints a whole quiz on one page. /// Get the questions @@ -727,7 +729,13 @@ function quiz_print_quiz_questions($quiz, $results=NULL, $questions=NULL) { return false; } - if (!empty($quiz->shufflequestions)) { + if ($shuffleorder) { // Order has been defined, so reorder questions + $oldquestions = $questions; + $questions = array(); + foreach ($shuffleorder as $key) { + $questions[] = $oldquestions[$key]; // This loses the index key, but doesn't matter + } + } else if (!empty($quiz->shufflequestions)) { // Mix everything up $questions = swapshuffle_assoc($questions); } } @@ -772,8 +780,11 @@ function quiz_print_quiz_questions($quiz, $results=NULL, $questions=NULL) { echo "id\">"; $count = 0; + $questionorder = array(); + foreach ($questions as $question) { $count++; + $questionorder[] = $question->id; $feedback = NULL; $response = NULL; @@ -814,13 +825,17 @@ function quiz_print_quiz_questions($quiz, $results=NULL, $questions=NULL) { $feedback, $response, $actualgrades, $correct, $randomquestion, $quiz->shuffleanswers); print_simple_box_end(); - echo "
"; + echo "
"; } if (empty($results)) { - echo "
"; + if (!empty($quiz->shufflequestions)) { // Things have been mixed up, so pass the question order + $shuffleorder = implode(',', $questionorder); + echo "\n"; + } + echo "
"; } - echo ""; + echo ""; return true; } diff --git a/mod/quiz/report.php b/mod/quiz/report.php index e56da1be8c..4d9d75bbb4 100644 --- a/mod/quiz/report.php +++ b/mod/quiz/report.php @@ -126,6 +126,8 @@ $quiz->feedback = true; $quiz->correctanswers = true; + $quiz->shuffleanswers = false; + $quiz->shufflequestions = false; quiz_print_quiz_questions($quiz, $result, $questions); if (empty($review)) { -- 2.39.5