|
[
Permalink
| « Hide
]
Pierre Pichet added a comment - 09/Nov/09 08:32 PM
The first question in the screenshot-1 was a regular numerical and the second was a random question which use a copy of the first one ..
After the discussion in the forum I tracked down the bug and found the core reason.
In SQL table mdl_question_states the question column normally holds the question number which is defined in mdl_question_* tables. But in case of a random question the question column in mdl_question_states contains a question number which is not the real number of the question, instead the real question number is stored in the answer column. id attempt question originalquestion seq_number answer timestamp event grade raw_grade penalty So in this case question number 650 is not valid in a sense that this cannot be found yhe question tables, instead number of the question is 629. Moodle extracts the real question number (629). In file ./question/type/questiontype.php there is function history, which produces "History of responses". In the SQL query $states = get_records_select('question_states', "attempt = '$state->attempt' AND question = '$question->id' AND event > '0'", 'seq_number ASC'); $question->id is the real question number (aka 629, since formerly Moodle decoded the answer field), but question column contains 650, so there are no matches. Instead of this query I modified the source to $states = get_records_select('question_states', "attempt = '$state->attempt' AND (question = '$question->id' OR answer LIKE '%random$question->id%') AND event > '0'", 'seq_number ASC'); Introduced OR answer LIKE '%random$question->id%' to the condition. This way the query will find regular questions as well as random questions correctly. In case of a random question the answer column is not valid for further process because of the "randomxxx-" prefix,so further modification is needed. foreach ($states as $st) { is modified as foreach ($states as $st) { to remove the unwanted "randomxxx-" prefix. These small modifications made "History of responses" work as expected. As I see the table structure, this is universally usable for all type of questions/random questions, no problem can arise. Oh, well worked out. Actually, we have had similar problems with other parts of the question. I think you will find there is a
Thanks, with this randomquestionid field the SQL query can be modified to
question = '$question->id' OR question = '$question->randomquestionid' which is more straightforward and safe, but you definitely need both id and randomquestionid, to have history on random and non-random questions as well. $st->answer=eregi_replace('random.*d','d',$st>answer); // modification or something similar is still needed to preformat answer column. Our Moodle is already modified according to this and it works fine so far. I would rather do
if (!empty($question->randomquestionid) { $qid = $question->randomquestionid; } else { $qid = $question->id; } in the PHP code, and use $qid in the SQL, but basically you are right. Do you feel up to creating a patch, or do you want to wait for me to get around to it? Well, I am not a developer, don't have latest moodle CVS installed and not an experienced patch creator, so maybe its better to leave it to you. Nevertheless, if I will have some time in the next weeks and find this issue open, maybe I will give it a try, because it's small enough task to start with. But don't hesitate to get around it, if you reach this in your to-do list.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||