Trouble updating multianswer question

Trouble updating multianswer question

by Daniel Mikšík -
Number of replies: 3
Picture of Core developers Picture of Translators
If I open an existing multianswer question for editing and save it (even without changing anything in the question text!), the sequence of the embedded question ids in the quiz_multianswers table gets changed. If students attempted to answer such a multianswer question, their marks get lost.
What baffles me is that after executing the same sequence of actions at demo.moodle.com the ids' sequence is kept intact.
I'm using the latest stable code from CVS (1.5.3+), MySQL 4.1.16, PHP 5.0.4.

Example (my Moodle installation)
- original sequence in quiz_multianswers:
33550,33551,33552,33553,33554,33555,33556,33557,33558,33559,33560,33561,33562,33563,33564,33565


mod/quiz/questiontypes/multianswer/questiontype.php, function save_question_options(), line 62:
if (!$oldwrappedids = get_records('quiz_questions', 'parent', $question->id, '', 'id, id')) {
- the resulting SQL reads: SELECT id, id FROM mdl_quiz_questions WHERE parent = '33549'
- the $oldwrappedids array contains: ( [0] => 33560 [1] => 33561 [2] => 33562 [3] => 33563 [4] => 33559 [5] => 33556 [6] => 33557 [7] => 33558 [8] => 33555 [9] => 33553 [10] => 33554 [11] => 33551 [12] => 33552 [13] => 33550 [14] => 33564 [15] => 33565 )

- updated sequence in quiz_multianswers:
33560,33561,33562,33563,33559,33556,33557,33558,33555,33553,33554,33551,33552,33550,33564,33565

If I get it right, the ids for updating a multianswer question are taken from the query to the
mdl_quiz_questions table -- the array contains the same numbers as the sequence field of the parent question in quiz_multianswers, but it does not necessarily match the actual (original) sequence saved in quiz_multianswers.
Wouldn't it be safer to build the
$oldwrappedids array on the basis of the quiz_multianswers table?
Should I consider this a bug, and file it as such?
Thank you for any answer.
Dan
Average of ratings: -
In reply to Daniel Mikšík

Re: Trouble updating multianswer question

by Gustav W Delius -
Dan, thanks a lot for your scrutiny of the code. I must admit I did not write any of the question types and this one worries me as much as you. At least the comments in the save_question_options() method in the multianswer question type acknowledge that there is a problem with existing student answers when a question gets edited. However, as you point out, the problems are greater than what the author acknowledges, because the ordering of the array returned by get_records() is left to chance.

This definitely merits an entry in the bug tracker and if you could also supply a fix then that would be even better.