Skip to content

Commit

Permalink
MDL-77328 qformat_xml: Avoid dynamic declaration for question_answer
Browse files Browse the repository at this point in the history
Declare qformat_xml::answerfiles and qformat_xml::feedbackfiles instead
of dynamically declaring answerfiles and feedbackfiles for the
question_answer instance when exporting questions and answers to XML
format.
  • Loading branch information
junpataleta authored and ilyatregubov committed Jul 21, 2023
1 parent 185c14a commit 7325906
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions question/format/xml/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@
*/
class qformat_xml extends qformat_default {

/** @var array Array of files for question answers. */
protected $answerfiles = [];

/** @var array Array of files for feedback to question answers. */
protected $feedbackfiles = [];

public function provide_import() {
return true;
}
Expand Down Expand Up @@ -1203,9 +1209,9 @@ public function writequestion($question) {
$contextid, 'question', 'generalfeedback', $question->id);
if (!empty($question->options->answers)) {
foreach ($question->options->answers as $answer) {
$answer->answerfiles = $fs->get_area_files(
$this->answerfiles[$answer->id] = $fs->get_area_files(
$contextid, 'question', 'answer', $answer->id);
$answer->feedbackfiles = $fs->get_area_files(
$this->feedbackfiles[$answer->id] = $fs->get_area_files(
$contextid, 'question', 'answerfeedback', $answer->id);
}
}
Expand Down Expand Up @@ -1593,10 +1599,10 @@ public function write_answer($answer, $extra = '') {
$output = '';
$output .= " <answer fraction=\"{$percent}\" {$this->format($answer->answerformat)}>\n";
$output .= $this->writetext($answer->answer, 3);
$output .= $this->write_files($answer->answerfiles);
$output .= $this->write_files($this->answerfiles[$answer->id]);
$output .= " <feedback {$this->format($answer->feedbackformat)}>\n";
$output .= $this->writetext($answer->feedback, 4);
$output .= $this->write_files($answer->feedbackfiles);
$output .= $this->write_files($this->feedbackfiles[$answer->id]);
$output .= " </feedback>\n";
$output .= $extra;
$output .= " </answer>\n";
Expand Down

0 comments on commit 7325906

Please sign in to comment.