Fix for bug #3707.

This commit is contained in:
mindforge
2005-07-08 11:37:55 +00:00
parent c1b6ab8118
commit 42c19f0e8d
6 changed files with 53 additions and 6 deletions
@@ -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] = '';
}
@@ -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
@@ -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) {
@@ -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);
}
}
}
}
}
@@ -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;
@@ -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