MDL-27626 numerical_options are written only if there are some numerical_units available
This reflects the logic of the backup 2.0. Previously, the new numerical_options structure was written always, even if there were no numerical_units.
This commit is contained in:
@@ -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 //////////////////////////////////////////
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user