diff --git a/mod/quiz/questiontypes/match/questiontype.php b/mod/quiz/questiontypes/match/questiontype.php index 25fc288abc3..a2fe0436997 100644 --- a/mod/quiz/questiontypes/match/questiontype.php +++ b/mod/quiz/questiontypes/match/questiontype.php @@ -64,6 +64,13 @@ class quiz_match_qtype extends quiz_default_questiontype { } } + // delete old subquestions records + if (!empty($oldsubquestions)) { + foreach($oldsubquestions as $os) { + delete_records('quiz_match_sub', 'id', $os->id); + } + } + if (count($subquestions) < 3) { $result->noticeyesno = get_string("notenoughsubquestions", "quiz"); return $result; @@ -105,7 +112,7 @@ class quiz_match_qtype extends quiz_default_questiontype { $answer->fraction = 1.0; $state->options->subquestions[$key]->options ->answers[$subquestion->id] = clone($answer); - + $state->responses[$key] = ''; } diff --git a/mod/quiz/questiontypes/multichoice/editquestion.php b/mod/quiz/questiontypes/multichoice/editquestion.php index bd9828f0f81..d4d5032f771 100644 --- a/mod/quiz/questiontypes/multichoice/editquestion.php +++ b/mod/quiz/questiontypes/multichoice/editquestion.php @@ -6,7 +6,8 @@ $options->single = 1; } if (!empty($options->answers)) { - $answersraw = get_records_list("quiz_answers", "id", $options->answers); + $answersraw = get_records("quiz_answers", "question", $question->id, + 'seq_number ASC'); } for ($i=0 ; $i < QUIZ_MAX_NUMBER_ANSWERS ; $i++) { $answers[] = ""; // Make answer slots, default as blank diff --git a/mod/quiz/questiontypes/multichoice/questiontype.php b/mod/quiz/questiontypes/multichoice/questiontype.php index 3e9553dbd19..05398b66e29 100644 --- a/mod/quiz/questiontypes/multichoice/questiontype.php +++ b/mod/quiz/questiontypes/multichoice/questiontype.php @@ -26,7 +26,8 @@ class quiz_multichoice_qtype extends quiz_default_questiontype { return false; } - if (!$question->options->answers = get_records_select('quiz_answers', 'id IN ('.$question->options->answers.')')) { + if (!$question->options->answers = get_records("quiz_answers", + 'question', $question->id, 'seq_number ASC')) { notify('Error: Missing question answers!'); return false; } @@ -66,9 +67,10 @@ class quiz_multichoice_qtype extends quiz_default_questiontype { foreach ($question->answer as $key => $dataanswer) { if ($dataanswer != "") { if ($answer = array_shift($oldanswers)) { // Existing answer, so reuse it - $answer->answer = $dataanswer; - $answer->fraction = $question->fraction[$key]; - $answer->feedback = $question->feedback[$key]; + $answer->answer = $dataanswer; + $answer->fraction = $question->fraction[$key]; + $answer->feedback = $question->feedback[$key]; + $answer->seq_number = $key + 1; if (!update_record("quiz_answers", $answer)) { $result->error = "Could not update quiz answer! (id=$answer->id)"; return $result; @@ -79,6 +81,7 @@ class quiz_multichoice_qtype extends quiz_default_questiontype { $answer->question = $question->id; $answer->fraction = $question->fraction[$key]; $answer->feedback = $question->feedback[$key]; + $answer->seq_number = $key + 1; if (!$answer->id = insert_record("quiz_answers", $answer)) { $result->error = "Could not insert quiz answer! "; return $result; @@ -113,6 +116,13 @@ class quiz_multichoice_qtype extends quiz_default_questiontype { } } + // delete old answer records + if (!empty($oldanswers)) { + foreach($oldanswers as $oa) { + delete_records('quiz_answers', 'id', $oa->id); + } + } + /// Perform sanity checks on fractional grades if ($options->single) { if ($maxfraction != 1) { diff --git a/mod/quiz/questiontypes/numerical/questiontype.php b/mod/quiz/questiontypes/numerical/questiontype.php index a6b3104cfa8..63f9aa6ffce 100644 --- a/mod/quiz/questiontypes/numerical/questiontype.php +++ b/mod/quiz/questiontypes/numerical/questiontype.php @@ -151,6 +151,21 @@ class quiz_numerical_qtype extends quiz_shortanswer_qtype { return $result; } } + + // delete old answer records + if (!empty($oldanswers)) { + foreach($oldanswers as $oa) { + delete_records('quiz_answers', 'id', $oa->id); + } + } + + // delete old answer records + if (!empty($oldoptions)) { + foreach($oldoptions as $oo) { + delete_records('quiz_numerical', 'id', $oo->id); + } + } + } } } diff --git a/mod/quiz/questiontypes/shortanswer/questiontype.php b/mod/quiz/questiontypes/shortanswer/questiontype.php index 8884cb57408..25733e633f6 100644 --- a/mod/quiz/questiontypes/shortanswer/questiontype.php +++ b/mod/quiz/questiontypes/shortanswer/questiontype.php @@ -89,6 +89,13 @@ class quiz_shortanswer_qtype extends quiz_default_questiontype { } } + // delete old answer records + if (!empty($oldanswers)) { + foreach($oldanswers as $oa) { + delete_records('quiz_answers', 'id', $oa->id); + } + } + /// Perform sanity checks on fractional grades if ($maxfraction != 1) { $maxfraction = $maxfraction * 100; diff --git a/mod/quiz/questiontypes/truefalse/questiontype.php b/mod/quiz/questiontypes/truefalse/questiontype.php index aec9b3a6054..0a89351d383 100644 --- a/mod/quiz/questiontypes/truefalse/questiontype.php +++ b/mod/quiz/questiontypes/truefalse/questiontype.php @@ -56,6 +56,13 @@ class quiz_truefalse_qtype extends quiz_default_questiontype { } } + // delete old answer records + if (!empty($oldanswers)) { + foreach($oldanswers as $oa) { + delete_records('quiz_answers', 'id', $oa->id); + } + } + if ($options = get_record("quiz_truefalse", "question", $question->id)) { // No need to do anything, since the answer IDs won't have changed // But we'll do it anyway, just for robustness