From 78fc17ebdfd9f243856e8398370ca2e1c5e4f4b1 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Mon, 31 Oct 2011 18:17:11 +0000 Subject: [PATCH] MDL-29058 question export: include files from hints & combined feedback. --- question/format/xml/format.php | 48 ++++++++++++++++++++++++++-------- question/type/upgrade.txt | 16 ++++++++++++ 2 files changed, 53 insertions(+), 11 deletions(-) create mode 100755 question/type/upgrade.txt diff --git a/question/format/xml/format.php b/question/format/xml/format.php index b744ce527a6..9da3511b962 100644 --- a/question/format/xml/format.php +++ b/question/format/xml/format.php @@ -1127,7 +1127,7 @@ class qformat_xml extends qformat_default { "\n"; $expout .= " " . $question->options->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 .= " " . $this->get_single($question->options->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 .= " format($hint->hintformat)}>\n"; $output .= ' ' . $this->writetext($hint->hint); + if (!empty($hint->shownumcorrect)) { $output .= " \n"; } if (!empty($hint->clearwrong)) { $output .= " \n"; } + if (!empty($hint->options)) { $output .= ' ' . $this->xml_escape($hint->options) . "\n"; } + $output .= $this->writefiles($files); $output .= " \n"; return $output; } - public function write_combined_feedback($questionoptions) { - $output = " format($questionoptions->correctfeedbackformat)}> - {$this->writetext($questionoptions->correctfeedback)} - format($questionoptions->partiallycorrectfeedbackformat)}> - {$this->writetext($questionoptions->partiallycorrectfeedback)} - format($questionoptions->incorrectfeedbackformat)}> - {$this->writetext($questionoptions->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 .= " \n"; + } + if (!empty($questionoptions->shownumcorrect)) { $output .= " \n"; } diff --git a/question/type/upgrade.txt b/question/type/upgrade.txt new file mode 100755 index 00000000000..75e42f33b16 --- /dev/null +++ b/question/type/upgrade.txt @@ -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