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;
foreach ($questions as $question) {
$count++;
+ $questionorder[] = $question->id;
+
$feedback = NULL;
$response = NULL;
$actualgrades = NULL;
}
}
- $questionorder[] = $question->id;
print_simple_box_start("CENTER", "90%");
quiz_print_question($count, $question, $grades[$question->id]->grade, $quiz->course,
$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++;
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;
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;
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;
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();