Merge branch 'MDL-30021' of git://github.com/timhunt/moodle
[moodle.git] / question / type / numerical / backup / moodle1 / lib.php
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
18 /**
19  * @package    qtype
20  * @subpackage numerical
21  * @copyright  2011 David Mudrak <david@moodle.com>
22  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23  */
25 defined('MOODLE_INTERNAL') || die();
27 /**
28  * Multichoice question type conversion handler
29  */
30 class moodle1_qtype_numerical_handler extends moodle1_qtype_handler {
32     /**
33      * @return array
34      */
35     public function get_question_subpaths() {
36         return array(
37             'ANSWERS/ANSWER',
38             'NUMERICAL',
39             'NUMERICAL/NUMERICAL_UNITS/NUMERICAL_UNIT',
40         );
41     }
43     /**
44      * Appends the numerical specific information to the question
45      */
46     public function process_question(array $data, array $raw) {
48         // convert and write the answers first
49         if (isset($data['answers'])) {
50             $this->write_answers($data['answers'], $this->pluginname);
51         }
53         // convert and write the numerical units and numerical options
54         if (isset($data['numerical'][0]['numerical_units'])) {
55             $numericalunits = $data['numerical'][0]['numerical_units'];
56         } else {
57             $numericalunits = array();
58         }
59         $numericaloptions = $this->get_default_numerical_options(
60                 $data['oldquestiontextformat'], $numericalunits);
62         $this->write_numerical_units($numericalunits);
63         $this->write_numerical_options($numericaloptions);
65         // and finally numerical_records
66         $this->xmlwriter->begin_tag('numerical_records');
67         foreach ($data['numerical'] as $numericalrecord) {
68             // we do not use write_xml() here because $numericalrecords contains more than we want
69             $this->xmlwriter->begin_tag('numerical_record', array('id' => $this->converter->get_nextid()));
70             $this->xmlwriter->full_tag('answer', $numericalrecord['answer']);
71             $this->xmlwriter->full_tag('tolerance', $numericalrecord['tolerance']);
72             $this->xmlwriter->end_tag('numerical_record');
73         }
74         $this->xmlwriter->end_tag('numerical_records');
75     }
76 }