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
21
+ * @subpackage questionnaire
22
+ * @copyright 2011 Robin de Vries <[email protected] >
23
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
+ */
25
+
26
+ defined ('MOODLE_INTERNAL ' ) || die ();
27
+
28
+ /**
29
+ * Choice conversion handler
30
+ */
31
+ class moodle1_mod_questionnaire_handler extends moodle1_mod_handler {
32
+
33
+ /**
34
+ * Declare the paths in moodle.xml we are able to convert
35
+ *
36
+ * The method returns list of {@link convert_path} instances. For each path returned,
37
+ * at least one of on_xxx_start(), process_xxx() and on_xxx_end() methods must be
38
+ * defined. The method process_xxx() is not executed if the associated path element is
39
+ * empty (i.e. it contains none elements or sub-paths only).
40
+ *
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.
44
+ *
45
+ * @return array of {@link convert_path} instances
46
+ */
47
+ public function get_paths () {
48
+ return array (
49
+ new convert_path (
50
+ 'questionnaire ' , '/MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE ' ,
51
+ array (
52
+ 'renamefields ' => array (
53
+ 'summary ' => 'intro ' ,
54
+ ),
55
+ 'newfields ' => array (
56
+ 'introformat ' => 0 ,
57
+ ),
58
+ )
59
+ ),
60
+ new convert_path ('survey ' , '/MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE/SURVEY ' ),
61
+ new convert_path ('question ' , '/MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE/SURVEY/QUESTION ' ),
62
+ new convert_path ('question_choice ' , '/MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE/SURVEY/QUESTION/QUESTION_CHOICE ' ),
63
+ );
64
+ }
65
+ /**
66
+ * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE
67
+ * data available
68
+ */
69
+ public function process_questionnaire ($ data ) {
70
+ // Get the course module id and context id.
71
+ $ instanceid = $ data ['id ' ];
72
+ $ cminfo = $ this ->get_cminfo ($ instanceid );
73
+ $ moduleid = $ cminfo ['id ' ];
74
+ $ contextid = $ this ->converter ->get_contextid (CONTEXT_MODULE , $ moduleid );
75
+
76
+ // We now have all information needed to start writing into the file.
77
+ $ this ->open_xml_writer ("activities/questionnaire_ {$ moduleid }/questionnaire.xml " );
78
+ $ this ->xmlwriter ->begin_tag ('activity ' , array ('id ' => $ instanceid , 'moduleid ' => $ moduleid ,
79
+ 'modulename ' => 'questionnaire ' , 'contextid ' => $ contextid ));
80
+ $ this ->xmlwriter ->begin_tag ('questionnaire ' , array ('id ' => $ instanceid ));
81
+
82
+ unset($ data ['id ' ]); // We already write it as attribute, do not repeat it as child element.
83
+ foreach ($ data as $ field => $ value ) {
84
+ $ this ->xmlwriter ->full_tag ($ field , $ value );
85
+ }
86
+ $ this ->xmlwriter ->begin_tag ('surveys ' );
87
+ }
88
+ /**
89
+ * This is executed when we reach the closing </MOD> tag of our 'questionnaire' path
90
+ */
91
+
92
+ public function on_questionnaire_end () {
93
+ // Close questionnaire.xml.
94
+ $ this ->xmlwriter ->end_tag ('surveys ' );
95
+ $ this ->xmlwriter ->end_tag ('questionnaire ' );
96
+ $ this ->xmlwriter ->end_tag ('activity ' );
97
+ $ this ->close_xml_writer ();
98
+ }
99
+ /**
100
+ * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE/SURVEY
101
+ * data available
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
+ */
124
+ public function process_question ($ data ) {
125
+
126
+ $ this ->xmlwriter ->begin_tag ('question ' , array ('id ' => $ data ['id ' ]));
127
+
128
+ unset($ data ['id ' ]); // We already write it as attribute, do not repeat it as child element.
129
+ foreach ($ data as $ field => $ value ) {
130
+ $ this ->xmlwriter ->full_tag ($ field , $ value );
131
+ }
132
+
133
+ $ this ->xmlwriter ->begin_tag ('quest_choices ' );
134
+ }
135
+ /**
136
+ * This is executed when we reach the closing </QUESTION> tag
137
+ */
138
+ public function on_question_end () {
139
+ $ this ->xmlwriter ->end_tag ('quest_choices ' );
140
+ $ this ->xmlwriter ->end_tag ('question ' );
141
+
142
+ }
143
+
144
+ /**
145
+ * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/QUESTIONNAIRE/SURVEY/QUESTION/QUESTION_CHOICE
146
+ * data available
147
+ */
148
+ public function process_question_choice ($ data ) {
149
+ $ this ->write_xml ('quest_choice ' , $ data , array ('/question_choice/id ' ));
150
+ }
151
+
152
+ }
0 commit comments