MDL-28438 Aiken question import broken since MDL-24594.
authorTim Hunt <T.J.Hunt@open.ac.uk>
Mon, 15 Aug 2011 13:42:48 +0000 (14:42 +0100)
committerTim Hunt <T.J.Hunt@open.ac.uk>
Mon, 15 Aug 2011 13:44:57 +0000 (14:44 +0100)
question/format.php
question/format/aiken/format.php
question/format/aiken/simpletest/fixtures/questions.aiken.txt [new file with mode: 0644]

index 8cdbfbd..71e182e 100644 (file)
@@ -595,7 +595,9 @@ class qformat_default {
         $question->image = "";
         $question->usecase = 0;
         $question->multiplier = array();
         $question->image = "";
         $question->usecase = 0;
         $question->multiplier = array();
+        $question->questiontextformat = FORMAT_MOODLE;
         $question->generalfeedback = '';
         $question->generalfeedback = '';
+        $question->generalfeedbackformat = FORMAT_MOODLE;
         $question->correctfeedback = '';
         $question->partiallycorrectfeedback = '';
         $question->incorrectfeedback = '';
         $question->correctfeedback = '';
         $question->partiallycorrectfeedback = '';
         $question->incorrectfeedback = '';
index d9db4bb..4e64c2f 100644 (file)
@@ -76,12 +76,11 @@ class qformat_aiken extends qformat_default {
                 }
                 if (preg_match('/^[A-Z][).][ \t]/', $nowline)) {
                     // A choice. Trim off the label and space, then save
                 }
                 if (preg_match('/^[A-Z][).][ \t]/', $nowline)) {
                     // A choice. Trim off the label and space, then save
-                    $question->answer[] = htmlspecialchars(trim(substr($nowline, 2)), ENT_NOQUOTES);
+                    $question->answer[] = $this->text_field(
+                            htmlspecialchars(trim(substr($nowline, 2)), ENT_NOQUOTES));
                     $question->fraction[] = 0;
                     $question->fraction[] = 0;
-                    $question->feedback[] = '';
-                    continue;
-                }
-                if (preg_match('/^ANSWER:/', $nowline)) {
+                    $question->feedback[] = $this->text_field('');
+                } else if (preg_match('/^ANSWER:/', $nowline)) {
                     // The line that indicates the correct answer. This question is finised.
                     $ans = trim(substr($nowline, strpos($nowline, ':') + 1));
                     $ans = substr($ans, 0, 1);
                     // The line that indicates the correct answer. This question is finised.
                     $ans = trim(substr($nowline, strpos($nowline, ':') + 1));
                     $ans = substr($ans, 0, 1);
@@ -97,15 +96,31 @@ class qformat_aiken extends qformat_default {
                     // Must be the first line of a new question, since no recognised prefix.
                     $question->qtype = MULTICHOICE;
                     $question->name = shorten_text(s($nowline), 50);
                     // Must be the first line of a new question, since no recognised prefix.
                     $question->qtype = MULTICHOICE;
                     $question->name = shorten_text(s($nowline), 50);
-                    $question->questiontext = s($nowline);
+                    $question->questiontext = htmlspecialchars(trim($nowline), ENT_NOQUOTES);
+                    $question->questiontextformat = FORMAT_HTML;
+                    $question->generalfeedback = '';
+                    $question->generalfeedbackformat = FORMAT_HTML;
                     $question->single = 1;
                     $question->single = 1;
-                    $question->feedback[] = '';
+                    $question->answer = array();
+                    $question->fraction = array();
+                    $question->feedback = array();
+                    $question->correctfeedback = $this->text_field('');
+                    $question->partiallycorrectfeedback = $this->text_field('');
+                    $question->incorrectfeedback = $this->text_field('');
                 }
             }
         }
         return $questions;
     }
 
                 }
             }
         }
         return $questions;
     }
 
+    protected function text_field($text) {
+        return array(
+            'text' => htmlspecialchars(trim($text), ENT_NOQUOTES),
+            'format' => FORMAT_HTML,
+            'files' => array(),
+        );
+    }
+
     public function readquestion($lines) {
         //this is no longer needed but might still be called by default.php
         return;
     public function readquestion($lines) {
         //this is no longer needed but might still be called by default.php
         return;
diff --git a/question/format/aiken/simpletest/fixtures/questions.aiken.txt b/question/format/aiken/simpletest/fixtures/questions.aiken.txt
new file mode 100644 (file)
index 0000000..b8c24d4
--- /dev/null
@@ -0,0 +1,11 @@
+The Moodle project was started by:
+A) Petr Skoda
+B) Martin Dougiamas
+C) Eloy Lafuente
+D) Tim Hunt
+ANSWER: B
+
+Moodle's abilities include handling user input that includes <html class="cool"> & images:
+A) True
+B) False
+ANSWER: A