diff --git a/question/format.php b/question/format.php index c16be0aa75f..84ac89bad06 100644 --- a/question/format.php +++ b/question/format.php @@ -866,26 +866,4 @@ class qformat_default { $text = $question->questiontext; return format_text(html_to_text($text, 0, false), $format, $formatoptions); } - - /** - * convert files into text output in the given format. - * @param array - * @param string encoding method - * @return string $string - */ - function writefiles($files, $encoding='base64') { - if (empty($files)) { - return ''; - } - $string = ''; - foreach ($files as $file) { - if ($file->is_directory()) { - continue; - } - $string .= ''; - $string .= base64_encode($file->get_content()); - $string .= ''; - } - return $string; - } } diff --git a/question/format/xml/format.php b/question/format/xml/format.php index 49f8152c256..1f153d234e6 100644 --- a/question/format/xml/format.php +++ b/question/format/xml/format.php @@ -1027,6 +1027,28 @@ class qformat_xml extends qformat_default { return $xml; } + + /** + * Generte the XML to represent some files. + * @param array of store array of stored_file objects. + * @return string $string the XML. + */ + public function write_files($files) { + if (empty($files)) { + return ''; + } + $string = ''; + foreach ($files as $file) { + if ($file->is_directory()) { + continue; + } + $string .= ''; + $string .= base64_encode($file->get_content()); + $string .= ''; + } + return $string; + } + function presave_process( $content ) { // override method to allow us to add xml headers and footers @@ -1078,10 +1100,10 @@ class qformat_xml extends qformat_default { $generalfeedbackformat = $this->get_format($question->generalfeedbackformat); $question_text = $this->writetext($question->questiontext); - $question_text_files = $this->writefiles($question->questiontextfiles); + $question_text_files = $this->write_files($question->questiontextfiles); $generalfeedback = $this->writetext($question->generalfeedback); - $generalfeedback_files = $this->writefiles($question->generalfeedbackfiles); + $generalfeedback_files = $this->write_files($question->generalfeedbackfiles); $expout .= " \n"; $expout .= " $name_text\n"; @@ -1136,7 +1158,7 @@ class qformat_xml extends qformat_default { $feedbackformat = $this->get_format($answer->feedbackformat); $expout .= " \n"; $expout .= $this->writetext($answer->feedback,4,false); - $expout .= $this->writefiles($answer->feedbackfiles); + $expout .= $this->write_files($answer->feedbackfiles); $expout .= " \n"; $expout .= " \n"; } @@ -1149,21 +1171,21 @@ class qformat_xml extends qformat_default { $files = $fs->get_area_files($contextid, 'qtype_multichoice', 'correctfeedback', $question->id); $expout .= " \n"; $expout .= $this->writetext($question->options->correctfeedback, 3); - $expout .= $this->writefiles($files); + $expout .= $this->write_files($files); $expout .= " \n"; $textformat = $this->get_format($question->options->partiallycorrectfeedbackformat); $files = $fs->get_area_files($contextid, 'qtype_multichoice', 'partiallycorrectfeedback', $question->id); $expout .= " \n"; $expout .= $this->writetext($question->options->partiallycorrectfeedback, 3); - $expout .= $this->writefiles($files); + $expout .= $this->write_files($files); $expout .= " \n"; $textformat = $this->get_format($question->options->incorrectfeedbackformat); $files = $fs->get_area_files($contextid, 'qtype_multichoice', 'incorrectfeedback', $question->id); $expout .= " \n"; $expout .= $this->writetext($question->options->incorrectfeedback, 3); - $expout .= $this->writefiles($files); + $expout .= $this->write_files($files); $expout .= " \n"; $expout .= " {$question->options->answernumbering}\n"; @@ -1174,7 +1196,7 @@ class qformat_xml extends qformat_default { $feedbackformat = $this->get_format($answer->feedbackformat); $expout .= " \n"; $expout .= $this->writetext($answer->feedback,5,false); - $expout .= $this->writefiles($answer->feedbackfiles); + $expout .= $this->write_files($answer->feedbackfiles); $expout .= " \n"; $expout .= " \n"; } @@ -1188,7 +1210,7 @@ class qformat_xml extends qformat_default { $feedbackformat = $this->get_format($answer->feedbackformat); $expout .= " \n"; $expout .= $this->writetext($answer->feedback); - $expout .= $this->writefiles($answer->feedbackfiles); + $expout .= $this->write_files($answer->feedbackfiles); $expout .= " \n"; $expout .= " \n"; } @@ -1204,7 +1226,7 @@ class qformat_xml extends qformat_default { $feedbackformat = $this->get_format($answer->feedbackformat); $expout .= " \n"; $expout .= $this->writetext($answer->feedback); - $expout .= $this->writefiles($answer->feedbackfiles); + $expout .= $this->write_files($answer->feedbackfiles); $expout .= " \n"; // fraction tag is deprecated // $expout .= " {$answer->fraction}\n"; @@ -1239,7 +1261,7 @@ class qformat_xml extends qformat_default { $files = $fs->get_area_files($contextid, 'qtype_numerical', 'instruction', $question->id); $expout .= " \n"; $expout .= $this->writetext($question->options->instructions, 3); - $expout .= $this->writefiles($files); + $expout .= $this->write_files($files); $expout .= " \n"; } break; @@ -1249,7 +1271,7 @@ class qformat_xml extends qformat_default { $textformat = $this->get_format($subquestion->questiontextformat); $expout .= "\n"; $expout .= $this->writetext($subquestion->questiontext); - $expout .= $this->writefiles($files); + $expout .= $this->write_files($files); $expout .= ""; $expout .= $this->writetext($subquestion->answertext); $expout .= "\n"; @@ -1276,7 +1298,7 @@ class qformat_xml extends qformat_default { $feedbackformat = $this->get_format($answer->feedbackformat); $expout .= " \n"; $expout .= $this->writetext($answer->feedback); - $expout .= $this->writefiles($answer->feedbackfiles); + $expout .= $this->write_files($answer->feedbackfiles); $expout .= " \n"; // fraction tag is deprecated // $expout .= " {$answer->fraction}\n"; @@ -1296,19 +1318,19 @@ class qformat_xml extends qformat_default { $files = $fs->get_area_files($contextid, $component, 'correctfeedback', $question->id); $expout .= " \n"; $expout .= $this->writetext($question->options->correctfeedback, 3); - $expout .= $this->writefiles($files); + $expout .= $this->write_files($files); $expout .= " \n"; $files = $fs->get_area_files($contextid, $component, 'partiallycorrectfeedback', $question->id); $expout .= " \n"; $expout .= $this->writetext($question->options->partiallycorrectfeedback, 3); - $expout .= $this->writefiles($files); + $expout .= $this->write_files($files); $expout .= " \n"; $files = $fs->get_area_files($contextid, $component, 'incorrectfeedback', $question->id); $expout .= " \n"; $expout .= $this->writetext($question->options->incorrectfeedback, 3); - $expout .= $this->writefiles($files); + $expout .= $this->write_files($files); $expout .= " \n"; foreach ($question->options->answers as $answer) { @@ -1327,7 +1349,7 @@ class qformat_xml extends qformat_default { $feedbackformat = $this->get_format($answer->feedbackformat); $expout .= " \n"; $expout .= $this->writetext($answer->feedback); - $expout .= $this->writefiles($answer->feedbackfiles); + $expout .= $this->write_files($answer->feedbackfiles); $expout .= " \n"; $expout .= "\n"; } @@ -1349,7 +1371,7 @@ class qformat_xml extends qformat_default { $files = $fs->get_area_files($contextid, $component, 'instruction', $question->id); $expout .= " \n"; $expout .= $this->writetext($question->options->instructions, 3); - $expout .= $this->writefiles($files); + $expout .= $this->write_files($files); $expout .= " \n"; }