diff --git a/backup/converter/moodle1/handlerlib.php b/backup/converter/moodle1/handlerlib.php index c5276fb84a1..a09fba84467 100644 --- a/backup/converter/moodle1/handlerlib.php +++ b/backup/converter/moodle1/handlerlib.php @@ -1327,35 +1327,49 @@ abstract class moodle1_qtype_handler extends moodle1_plugin_handler { /** * Writes the numerical_options structure * + * @see get_default_numerical_options() + * @param array $numericaloption + */ + protected function write_numerical_options(array $numericaloption) { + + $this->xmlwriter->begin_tag('numerical_options'); + if (!empty($numericaloption)) { + $this->write_xml('numerical_option', $numericaloption, array('/numerical_option/id')); + } + $this->xmlwriter->end_tag('numerical_options'); + } + + /** + * Returns default numerical_option structure + * * This structure is not present in moodle.xml, we create a new artificial one here. * - * @param array $numericaloptions + * @see write_numerical_options() * @param int $oldquestiontextformat + * @return array */ - protected function write_numerical_options($oldquestiontextformat) { + protected function get_default_numerical_options($oldquestiontextformat) { global $CFG; // replay the upgrade step 2009100100 - new table $options = array( - 'numerical_option' => array( - 'id' => $this->converter->get_nextid(), - 'instructions' => null, - 'instructionsformat' => 0, - 'showunits' => 0, - 'unitsleft' => 0, - 'unitgradingtype' => 0, - 'unitpenalty' => 0.1 - ) + 'id' => $this->converter->get_nextid(), + 'instructions' => null, + 'instructionsformat' => 0, + 'showunits' => 0, + 'unitsleft' => 0, + 'unitgradingtype' => 0, + 'unitpenalty' => 0.1 ); // replay the upgrade step 2009100101 if ($CFG->texteditors !== 'textarea' and $oldquestiontextformat == FORMAT_MOODLE) { - $options['numerical_option']['instructionsformat'] = FORMAT_HTML; + $options['instructionsformat'] = FORMAT_HTML; } else { - $options['numerical_option']['instructionsformat'] = $oldquestiontextformat; + $options['instructionsformat'] = $oldquestiontextformat; } - $this->write_xml('numerical_options', $options, array('/numerical_options/numerical_option/id')); + return $options; } /// implementation details follow ////////////////////////////////////////// diff --git a/question/type/numerical/backup/moodle1/lib.php b/question/type/numerical/backup/moodle1/lib.php index 9024f39b5b3..eb244584727 100644 --- a/question/type/numerical/backup/moodle1/lib.php +++ b/question/type/numerical/backup/moodle1/lib.php @@ -50,16 +50,16 @@ class moodle1_qtype_numerical_handler extends moodle1_qtype_handler { $this->write_answers($data['answers'], $this->pluginname); } - // convert and write the numerical units + // convert and write the numerical units and numerical options if (isset($data['numerical'][0]['numerical_units'])) { - $numericalunits = $data['numerical'][0]['numerical_units']; + $numericalunits = $data['numerical'][0]['numerical_units']; + $numericaloptions = $this->get_default_numerical_options($data['oldquestiontextformat']); } else { - $numericalunits = array(); + $numericalunits = array(); + $numericaloptions = array(); } $this->write_numerical_units($numericalunits); - - // append new numerical_options structure - $this->write_numerical_options($data['oldquestiontextformat']); + $this->write_numerical_options($numericaloptions); // and finally numerical_records $this->xmlwriter->begin_tag('numerical_records');