3 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
19 * Provides support for the conversion of moodle1 backup to the moodle2 format
23 * @copyright 2011 David Mudrak <david@moodle.com>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') || die();
30 * Choice conversion handler
32 class moodle1_mod_choice_handler extends moodle1_mod_handler {
35 * Declare the paths in moodle.xml we are able to convert
37 * The method returns list of {@link convert_path} instances.
38 * For each path returned, the corresponding conversion method must be
41 * Note that the path /MOODLE_BACKUP/COURSE/MODULES/MOD/CHOICE does not
42 * actually exist in the file. The last element with the module name was
43 * appended by the moodle1_converter class.
45 * @return array of {@link convert_path} instances
47 public function get_paths() {
50 'choice', '/MOODLE_BACKUP/COURSE/MODULES/MOD/CHOICE',
52 'renamefields' => array(
54 'format' => 'introformat',
57 'completionsubmit' => 0,
59 'dropfields' => array(
64 new convert_path('choice_option', '/MOODLE_BACKUP/COURSE/MODULES/MOD/CHOICE/OPTIONS/OPTION'),
69 * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/CHOICE
72 public function process_choice($data) {
74 // get the course module id and context id
75 $instanceid = $data['id'];
76 $moduleid = $this->get_moduleid($instanceid);
77 $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
79 // we now have all information needed to start writing into the file
80 $this->open_xml_writer("activities/choice_{$moduleid}/choice.xml");
81 $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
82 'modulename' => 'choice', 'contextid' => $contextid));
83 $this->xmlwriter->begin_tag('choice', array('id' => $instanceid));
85 unset($data['id']); // we already write it as attribute, do not repeat it as child element
86 foreach ($data as $field => $value) {
87 $this->xmlwriter->full_tag($field, $value);
90 $this->xmlwriter->begin_tag('options');
94 * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/CHOICE/OPTIONS/OPTION
97 public function process_choice_option($data) {
98 $this->write_xml('option', $data, array('/option/id'));
102 * This is executed when we reach the closing </MOD> tag of our 'choice' path
104 public function on_choice_end() {
106 $this->xmlwriter->end_tag('options');
107 $this->xmlwriter->end_tag('choice');
108 $this->xmlwriter->end_tag('activity');
109 $this->close_xml_writer();