From e1122620b540e88cb0a037b8c690fde7cf53fb0c Mon Sep 17 00:00:00 2001 From: moodler Date: Wed, 16 Apr 2003 13:48:16 +0000 Subject: [PATCH] Er, similar to the last few changes but this way seems to actually work. :-) Need sleep ... --- mod/quiz/lib.php | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 760e603d94..5016acb12e 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -729,17 +729,19 @@ function quiz_print_quiz_questions($quiz, $results=NULL, $questions=NULL, $shuff return false; } - 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 + if (!empty($quiz->shufflequestions)) { // Mix everything up $questions = swapshuffle_assoc($questions); } } + 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 + } + } + if (!$grades = get_records_list("quiz_question_grades", "question", $quiz->questions, "", "question,grade")) { notify("No grades were found for these questions!"); return false; @@ -785,6 +787,8 @@ function quiz_print_quiz_questions($quiz, $results=NULL, $questions=NULL, $shuff foreach ($questions as $question) { $count++; + $questionorder[] = $question->id; + $feedback = NULL; $response = NULL; $actualgrades = NULL; @@ -819,7 +823,6 @@ function quiz_print_quiz_questions($quiz, $results=NULL, $questions=NULL, $shuff } } - $questionorder[] = $question->id; print_simple_box_start("CENTER", "90%"); quiz_print_question($count, $question, $grades[$question->id]->grade, $quiz->course, @@ -1454,8 +1457,8 @@ function quiz_grade_attempt_results($quiz, $questions) { $qarr = explode('-', $questionanswer); // Extract subquestion/answer. $subquestionid = $qarr[0]; $subanswerid = $qarr[1]; - if (($subquestionid == $subanswerid) or - ($answers[$subquestionid]->answertext == $answers[$subanswerid]->answertext)) { + if ($subquestionid and $subanswerid and (($subquestionid == $subanswerid) or + ($answers[$subquestionid]->answertext == $answers[$subanswerid]->answertext))) { // Either the ids match exactly, or the answertexts match exactly // (in case two subquestions had the same answer) $matchcount++; @@ -1543,7 +1546,9 @@ function quiz_save_question_options($question) { switch ($question->qtype) { case SHORTANSWER: - $oldanswers = get_records("quiz_answers", "question", $question->id, "id ASC"); // might be NULL + if (!$oldanswers = get_records("quiz_answers", "question", $question->id, "id ASC")) { + $oldanswers = array(); + } $answers = array(); $maxfraction = -1; @@ -1608,7 +1613,9 @@ function quiz_save_question_options($question) { case TRUEFALSE: - $oldanswers = get_records("quiz_answers", "question", $question->id, "id ASC"); // might be NULL + if (!$oldanswers = get_records("quiz_answers", "question", $question->id, "id ASC")) { + $oldanswers = array(); + } if ($true = array_shift($oldanswers)) { // Existing answer, so reuse it $true->fraction = $question->answer; @@ -1672,7 +1679,9 @@ function quiz_save_question_options($question) { case MULTICHOICE: - $oldanswers = get_records("quiz_answers", "question", $question->id, "id ASC"); // might be NULL + if (!$oldanswers = get_records("quiz_answers", "question", $question->id, "id ASC")) { + $oldanswers = array(); + } $totalfraction = 0; $maxfraction = -1; @@ -1749,7 +1758,9 @@ function quiz_save_question_options($question) { case MATCH: - $oldsubquestions = get_records("quiz_match_sub", "question", $question->id, "id ASC"); // might be NULL + if (!$oldsubquestions = get_records("quiz_match_sub", "question", $question->id, "id ASC")) { + $oldsubquestions = array(); + } $subquestions = array(); -- 2.39.5