Permalink
Browse files

MDL-29058 question export: include files from hints & combined feedback.

  • Loading branch information...
1 parent fe5f412 commit 78fc17ebdfd9f243856e8398370ca2e1c5e4f4b1 @timhunt timhunt committed Oct 31, 2011
Showing with 53 additions and 11 deletions.
  1. +37 −11 question/format/xml/format.php
  2. +16 −0 question/type/upgrade.txt
@@ -1127,7 +1127,7 @@ public function writequestion($question) {
"</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 @@ public function writequestion($question) {
$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,14 +1409,19 @@ public function write_answer($answer, $extra = '') {
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 '';
}
$output = '';
foreach ($question->hints as $hint) {
- $output .= $this->write_hint($hint);
+ $output .= $this->write_hint($hint, $question->contextid);
}
return $output;
}
@@ -1429,30 +1434,51 @@ protected function format($format) {
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";
}
View
@@ -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.

0 comments on commit 78fc17e

Please sign in to comment.