]> git.mjollnir.org Git - moodle.git/commitdiff
random question history MDL-20951: Two minor bugs in the fix for MDL-20776.
authorTim Hunt <T.J.Hunt@open.ac.uk>
Tue, 24 Nov 2009 11:49:21 +0000 (11:49 +0000)
committerTim Hunt <T.J.Hunt@open.ac.uk>
Tue, 24 Nov 2009 11:49:21 +0000 (11:49 +0000)
Thanks to Oleg Sychev for noticing these problems.

question/type/questiontype.php

index 7157f97c0700b192c936f79b1947da9e668ec7dc..1c63909e9c6041efb2d1d83f838a2ae88205f736 100644 (file)
@@ -1088,8 +1088,10 @@ class default_questiontype {
         $params = array('aid' => $state->attempt);
         if (isset($question->randomquestionid)) {
             $params['qid'] = $question->randomquestionid;
+            $randomprefix = 'random' . $question->id . '-';
         } else {
             $params['qid'] = $question->id;
+            $randomprefix = '';
         }
         if ($options->history == 'all') {
             $eventtest = 'event > 0';
@@ -1098,7 +1100,7 @@ class default_questiontype {
         }
         $states = $DB->get_records_select('question_states', 
                 'attempt = :aid AND question = :qid AND ' . $eventtest, $params, 'seq_number ASC');
-        if (empty($states)) {
+        if (count($states) <= 1) {
             return '';
         }
 
@@ -1117,6 +1119,9 @@ class default_questiontype {
         }
 
         foreach ($states as $st) {
+            if ($randomprefix && strpos($st->answer, $randomprefix) === 0) {
+                $st->answer = substr($st->answer, strlen($randomprefix));
+            }
             $st->responses[''] = $st->answer;
             $this->restore_session_and_responses($question, $st);