Merge branch 'MDL-29058' of git://github.com/timhunt/moodle
authorAparup Banerjee <aparup@moodle.com>
Wed, 9 Nov 2011 03:29:45 +0000 (11:29 +0800)
committerAparup Banerjee <aparup@moodle.com>
Wed, 9 Nov 2011 03:29:45 +0000 (11:29 +0800)
question/format/xml/format.php
question/type/upgrade.txt [new file with mode: 0755]

index d51408d..c6974c6 100644 (file)
@@ -1127,7 +1127,7 @@ class qformat_xml extends qformat_default {
                         "</shuffleanswers>\n";
                 $expout .= "    <answernumbering>" . $question->options->answernumbering .
                         "</answernumbering>\n";
-                $expout .= $this->write_combined_feedback($question->options);
+                $expout .= $this->write_combined_feedback($question->options, $question->id, $question->contextid);
                 $expout .= $this->write_answers($question->options->answers);
                 break;
 
@@ -1181,7 +1181,7 @@ class qformat_xml extends qformat_default {
                 $expout .= "    <shuffleanswers>" .
                         $this->get_single($question->options->shuffleanswers) .
                         "</shuffleanswers>\n";
-                $expout .= $this->write_combined_feedback($question->options);
+                $expout .= $this->write_combined_feedback($question->options, $question->id, $question->contextid);
                 foreach ($question->options->subquestions as $subquestion) {
                     $files = $fs->get_area_files($contextid, 'qtype_match',
                             'subquestion', $subquestion->id);
@@ -1409,6 +1409,11 @@ class qformat_xml extends qformat_default {
         return $output;
     }
 
+    /**
+     * Write out the hints.
+     * @param object $question the question definition data.
+     * @return string XML to output.
+     */
     public function write_hints($question) {
         if (empty($question->hints)) {
             return '';
@@ -1416,7 +1421,7 @@ class qformat_xml extends qformat_default {
 
         $output = '';
         foreach ($question->hints as $hint) {
-            $output .= $this->write_hint($hint);
+            $output .= $this->write_hint($hint, $question->contextid);
         }
         return $output;
     }
@@ -1429,30 +1434,51 @@ class qformat_xml extends qformat_default {
         return 'format="' . $this->get_format($format) . '"';
     }
 
-    public function write_hint($hint) {
+    public function write_hint($hint, $contextid) {
+        $fs = get_file_storage();
+        $files = $fs->get_area_files($contextid, 'question', 'hint', $hint->id);
+
         $output = '';
         $output .= "    <hint {$this->format($hint->hintformat)}>\n";
         $output .= '      ' . $this->writetext($hint->hint);
+
         if (!empty($hint->shownumcorrect)) {
             $output .= "      <shownumcorrect/>\n";
         }
         if (!empty($hint->clearwrong)) {
             $output .= "      <clearwrong/>\n";
         }
+
         if (!empty($hint->options)) {
             $output .= '      <options>' . $this->xml_escape($hint->options) . "</options>\n";
         }
+        $output .= $this->writefiles($files);
         $output .= "    </hint>\n";
         return $output;
     }
 
-    public function write_combined_feedback($questionoptions) {
-        $output = "    <correctfeedback {$this->format($questionoptions->correctfeedbackformat)}>
-      {$this->writetext($questionoptions->correctfeedback)}    </correctfeedback>
-    <partiallycorrectfeedback {$this->format($questionoptions->partiallycorrectfeedbackformat)}>
-      {$this->writetext($questionoptions->partiallycorrectfeedback)}    </partiallycorrectfeedback>
-    <incorrectfeedback {$this->format($questionoptions->incorrectfeedbackformat)}>
-      {$this->writetext($questionoptions->incorrectfeedback)}    </incorrectfeedback>\n";
+    /**
+     * Output the combined feedback fields.
+     * @param object $questionoptions the question definition data.
+     * @param int $questionid the question id.
+     * @param int $contextid the question context id.
+     * @return string XML to output.
+     */
+    public function write_combined_feedback($questionoptions, $questionid, $contextid) {
+        $fs = get_file_storage();
+        $output = '';
+
+        $fields = array('correctfeedback', 'partiallycorrectfeedback', 'incorrectfeedback');
+        foreach ($fields as $field) {
+            $formatfield = $field . 'format';
+            $files = $fs->get_area_files($contextid, 'question', $field, $questionid);
+
+            $output .= "    <{$field} {$this->format($questionoptions->$formatfield)}>\n";
+            $output .= '      ' . $this->writetext($questionoptions->$field);
+            $output .= $this->writefiles($files);
+            $output .= "    </{$field}>\n";
+        }
+
         if (!empty($questionoptions->shownumcorrect)) {
             $output .= "    <shownumcorrect/>\n";
         }
diff --git a/question/type/upgrade.txt b/question/type/upgrade.txt
new file mode 100755 (executable)
index 0000000..75e42f3
--- /dev/null
@@ -0,0 +1,16 @@
+This files describes API changes for question type plugins.
+
+=== 2.2 ===
+
+* The XML import/export base class has had some minor API changes. The
+  - write_combined_feedback method now requires that you pass the questionid and
+    contextid. (MDL-29058)
+  - calls to the import_hints and import_answer methods now should pass the question
+    text format as the last argument, to be used as a default if necessary. (MDL-29739)
+  If you do not upgrade your code, it will not break, but there will be PHP
+  warnings, and it the export will not work 100% correctly.
+
+* Question type plugins should start using a string called 'pluginname' for the
+  question type name, as with other plugins. Using a string with the same name
+  as the question type (e.g. get_string('essay', 'qtype_essay') will be supported
+  for one more release, but will generate a debugging warning.
\ No newline at end of file