From 589475665e162aa2a946b58bc1ffe83583f0d640 Mon Sep 17 00:00:00 2001 From: David Mudrak Date: Thu, 2 Jun 2011 18:35:30 +0200 Subject: [PATCH] MDL-27626 numerical question type conversion handler --- .../type/numerical/backup/moodle1/lib.php | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 question/type/numerical/backup/moodle1/lib.php diff --git a/question/type/numerical/backup/moodle1/lib.php b/question/type/numerical/backup/moodle1/lib.php new file mode 100644 index 00000000000..980d5844038 --- /dev/null +++ b/question/type/numerical/backup/moodle1/lib.php @@ -0,0 +1,73 @@ +. + +/** + * @package qtype + * @subpackage numerical + * @copyright 2011 David Mudrak + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +/** + * Multichoice question type conversion handler + */ +class moodle1_qtype_numerical_handler extends moodle1_qtype_handler { + + /** + * @return array + */ + public function get_question_subpaths() { + return array( + 'ANSWERS/ANSWER', + 'NUMERICAL', + 'NUMERICAL/NUMERICAL_UNITS/NUMERICAL_UNIT', + ); + } + + /** + * Appends the numerical specific information to the question + */ + public function process_question(array $data, array $raw) { + + // convert and write the answers first + $this->write_answers($data['answers'], $this->pluginname); + + // convert and write the numerical units + if (isset($data['numerical'][0]['numerical_units'])) { + $numericalunits = $data['numerical'][0]['numerical_units']; + } else { + $numericalunits = array(); + } + $this->write_numerical_units($numericalunits); + + // append new numerical_options structure + $this->write_numerical_options($data['oldquestiontextformat']); + + // and finally numerical_records + $this->xmlwriter->begin_tag('numerical_records'); + foreach ($data['numerical'] as $numericalrecord) { + // we do not use write_xml() here because $numericalrecords contains more than we want + $this->xmlwriter->begin_tag('numerical_record', array('id' => $this->converter->get_nextid())); + $this->xmlwriter->full_tag('answer', $numericalrecord['answer']); + $this->xmlwriter->full_tag('tolerance', $numericalrecord['tolerance']); + $this->xmlwriter->end_tag('numerical_record'); + } + $this->xmlwriter->end_tag('numerical_records'); + } +}