MDL-28684 QE2 upgrade: recognize empty answer in multichoice questions
authorHenning Bostelmann <henning.bostelmann@york.ac.uk>
Tue, 16 Aug 2011 16:10:35 +0000 (17:10 +0100)
committerHenning Bostelmann <henning.bostelmann@york.ac.uk>
Fri, 19 Aug 2011 09:33:35 +0000 (10:33 +0100)
question/engine/upgrade/behaviourconverters.php
question/engine/upgrade/upgradelib.php
question/type/multichoice/db/upgradelib.php

index a502b8e..5807c02 100644 (file)
@@ -191,7 +191,7 @@ abstract class question_behaviour_attempt_updater {
                 $this->logger->log_assumption("Ignoring bogus state in attempt at question {$state->question}");
                 $this->sequencenumber = 0;
                 $this->qa->steps = array();
-            } else if ($state->answer == '') {
+            } else if ($this->qtypeupdater->is_blank_answer($state)) {
                 $this->logger->log_assumption("Ignoring second start state with blank answer in attempt at question {$state->question}");
                 return;
             } else {
index ed97f21..cfd9875 100644 (file)
@@ -568,6 +568,10 @@ abstract class question_qtype_attempt_updater {
         return $answer1 == $answer2;
     }
 
+    public function is_blank_answer($state) {
+        return $state->answer == '';
+    }
+    
     public abstract function right_answer();
     public abstract function response_summary($state);
     public abstract function was_answered($state);
index 501a6d8..99b5640 100644 (file)
@@ -39,6 +39,13 @@ defined('MOODLE_INTERNAL') || die();
 class qtype_multichoice_qe2_attempt_updater extends question_qtype_attempt_updater {
     protected $order;
 
+    public function is_blank_answer($state) {
+        // blank multichoice answers are not empty strings, they rather end in a colon
+        $a = $state->answer;
+        $empty = (substr($a, strlen($a) - 1) == ':'); 
+        return $empty;
+    }
+    
     public function right_answer() {
         if ($this->question->options->single) {
             foreach ($this->question->options->answers as $ans) {