Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Provides support for the conversion of moodle1 backup to the moodle2 format
19
 *
20
 * @package    mod_questionnaire
21
 * @copyright  2011 Robin de Vries <robin@celp.nl>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
/**
26
 * Choice conversion handler
27
 */
28
class moodle1_mod_questionnaire_handler extends moodle1_mod_handler {
29
 
30
    /**
31
     * Declare the paths in moodle.xml we are able to convert
32
     *
33
     * The method returns list of convert_path instances. For each path returned,
34
     * at least one of on_xxx_start(), process_xxx() and on_xxx_end() methods must be
35
     * defined. The method process_xxx() is not executed if the associated path element is
36
     * empty (i.e. it contains none elements or sub-paths only).
37
     *
38
     * Note that the path /MOODLE_BACKUP/COURSE/MODULES/MOD/CHOICE does not
39
     * actually exist in the file. The last element with the module name was
40
     * appended by the moodle1_converter class.
41
     *
42
     * @return array of convert_path instances
43
     */
44
    public function get_paths() {
45
        return array(
46
            new convert_path(
47
                'questionnaire', '/MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE',
48
                array(
49
                    'renamefields' => array(
50
                        'summary' => 'intro',
51
                    ),
52
                    'newfields' => array(
53
                        'introformat' => 0,
54
                    ),
55
                )
56
            ),
57
            new convert_path('survey', '/MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE/SURVEY'),
58
            new convert_path('question', '/MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE/SURVEY/QUESTION'),
59
            new convert_path('question_choice', '/MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE/SURVEY/QUESTION/QUESTION_CHOICE'),
60
        );
61
    }
62
 
63
    /**
64
     * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE
65
     * data available.
66
     * @param array $data
67
     */
68
    public function process_questionnaire($data) {
69
        // Get the course module id and context id.
70
        $instanceid = $data['id'];
71
        $cminfo = $this->get_cminfo($instanceid);
72
        $moduleid = $cminfo['id'];
73
        $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
74
 
75
        // We now have all information needed to start writing into the file.
76
        $this->open_xml_writer("activities/questionnaire_{$moduleid}/questionnaire.xml");
77
        $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
78
            'modulename' => 'questionnaire', 'contextid' => $contextid));
79
        $this->xmlwriter->begin_tag('questionnaire', array('id' => $instanceid));
80
 
81
        unset($data['id']); // We already write it as attribute, do not repeat it as child element.
82
        foreach ($data as $field => $value) {
83
            $this->xmlwriter->full_tag($field, $value);
84
        }
85
        $this->xmlwriter->begin_tag('surveys');
86
    }
87
    /**
88
     * This is executed when we reach the closing </MOD> tag of our 'questionnaire' path
89
     */
90
    public function on_questionnaire_end() {
91
        // Close questionnaire.xml.
92
        $this->xmlwriter->end_tag('surveys');
93
        $this->xmlwriter->end_tag('questionnaire');
94
        $this->xmlwriter->end_tag('activity');
95
        $this->close_xml_writer();
96
    }
97
 
98
    /**
99
     * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE/SURVEY
100
     * data available
101
     * @param array $data
102
     */
103
    public function process_survey($data) {
104
        $this->xmlwriter->begin_tag('survey', array('id' => $data['id']));
105
        unset($data['id']); // We already write it as attribute, do not repeat it as child element.
106
        foreach ($data as $field => $value) {
107
            $this->xmlwriter->full_tag($field, $value);
108
        }
109
        $this->xmlwriter->begin_tag('questions');
110
    }
111
 
112
    /**
113
     * This is executed when we reach the closing </SURVEY> tag
114
     */
115
    public function on_survey_end() {
116
        $this->xmlwriter->end_tag('questions');
117
        $this->xmlwriter->end_tag('survey');
118
    }
119
 
120
    /**
121
     * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE/SURVEY/QUESTION
122
     * data available
123
     * @param array $data
124
     */
125
    public function process_question($data) {
126
 
127
        $this->xmlwriter->begin_tag('question', array('id' => $data['id']));
128
 
129
        unset($data['id']); // We already write it as attribute, do not repeat it as child element.
130
        foreach ($data as $field => $value) {
131
            $this->xmlwriter->full_tag($field, $value);
132
        }
133
 
134
        $this->xmlwriter->begin_tag('quest_choices');
135
    }
136
    /**
137
     * This is executed when we reach the closing </QUESTION> tag
138
     */
139
    public function on_question_end() {
140
        $this->xmlwriter->end_tag('quest_choices');
141
        $this->xmlwriter->end_tag('question');
142
 
143
    }
144
 
145
    /**
146
     * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE/SURVEY/QUESTION/QUESTION_CHOICE
147
     * data available
148
     * @param array $data
149
     */
150
    public function process_question_choice($data) {
151
        $this->write_xml('quest_choice', $data, array('/question_choice/id'));
152
    }
153
}