mirrored from git://git.moodle.org/moodle.git
/
backup_quiz_stepslib.php
181 lines (136 loc) · 7.33 KB
/
backup_quiz_stepslib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package mod_quiz
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Define all the backup steps that will be used by the backup_quiz_activity_task
*
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class backup_quiz_activity_structure_step extends backup_questions_activity_structure_step {
protected function define_structure() {
// To know if we are including userinfo.
$userinfo = $this->get_setting_value('userinfo');
// Define each element separated.
$quiz = new backup_nested_element('quiz', array('id'), array(
'name', 'intro', 'introformat', 'timeopen', 'timeclose', 'timelimit',
'overduehandling', 'graceperiod', 'preferredbehaviour', 'canredoquestions', 'attempts_number',
'attemptonlast', 'grademethod', 'decimalpoints', 'questiondecimalpoints',
'reviewattempt', 'reviewcorrectness', 'reviewmarks',
'reviewspecificfeedback', 'reviewgeneralfeedback',
'reviewrightanswer', 'reviewoverallfeedback',
'questionsperpage', 'navmethod', 'shuffleanswers',
'sumgrades', 'grade', 'timecreated',
'timemodified', 'password', 'subnet', 'browsersecurity',
'delay1', 'delay2', 'showuserpicture', 'showblocks', 'completionattemptsexhausted', 'completionpass',
'allowofflineattempts'));
// Define elements for access rule subplugin settings.
$this->add_subplugin_structure('quizaccess', $quiz, true);
$qinstances = new backup_nested_element('question_instances');
$qinstance = new backup_nested_element('question_instance', array('id'), array(
'slot', 'page', 'requireprevious', 'questionid', 'questioncategoryid', 'includingsubcategories', 'maxmark'));
$qinstancetags = new backup_nested_element('tags');
$qinstancetag = new backup_nested_element('tag', array('id'), array('tagid', 'tagname'));
$sections = new backup_nested_element('sections');
$section = new backup_nested_element('section', array('id'), array(
'firstslot', 'heading', 'shufflequestions'));
$feedbacks = new backup_nested_element('feedbacks');
$feedback = new backup_nested_element('feedback', array('id'), array(
'feedbacktext', 'feedbacktextformat', 'mingrade', 'maxgrade'));
$overrides = new backup_nested_element('overrides');
$override = new backup_nested_element('override', array('id'), array(
'userid', 'groupid', 'timeopen', 'timeclose',
'timelimit', 'attempts', 'password'));
$grades = new backup_nested_element('grades');
$grade = new backup_nested_element('grade', array('id'), array(
'userid', 'gradeval', 'timemodified'));
$attempts = new backup_nested_element('attempts');
$attempt = new backup_nested_element('attempt', array('id'), array(
'userid', 'attemptnum', 'uniqueid', 'layout', 'currentpage', 'preview',
'state', 'timestart', 'timefinish', 'timemodified', 'timemodifiedoffline', 'timecheckstate', 'sumgrades'));
// This module is using questions, so produce the related question states and sessions
// attaching them to the $attempt element based in 'uniqueid' matching.
$this->add_question_usages($attempt, 'uniqueid');
// Define elements for access rule subplugin attempt data.
$this->add_subplugin_structure('quizaccess', $attempt, true);
// Build the tree.
$quiz->add_child($qinstances);
$qinstances->add_child($qinstance);
$qinstance->add_child($qinstancetags);
$qinstancetags->add_child($qinstancetag);
$quiz->add_child($sections);
$sections->add_child($section);
$quiz->add_child($feedbacks);
$feedbacks->add_child($feedback);
$quiz->add_child($overrides);
$overrides->add_child($override);
$quiz->add_child($grades);
$grades->add_child($grade);
$quiz->add_child($attempts);
$attempts->add_child($attempt);
// Define sources.
$quiz->set_source_table('quiz', array('id' => backup::VAR_ACTIVITYID));
$qinstance->set_source_table('quiz_slots',
array('quizid' => backup::VAR_PARENTID));
$qinstancetag->set_source_table('quiz_slot_tags',
array('slotid' => backup::VAR_PARENTID));
$section->set_source_table('quiz_sections',
array('quizid' => backup::VAR_PARENTID));
$feedback->set_source_table('quiz_feedback',
array('quizid' => backup::VAR_PARENTID));
// Quiz overrides to backup are different depending of user info.
$overrideparams = array('quiz' => backup::VAR_PARENTID);
if (!$userinfo) { // Without userinfo, skip user overrides.
$overrideparams['userid'] = backup_helper::is_sqlparam(null);
}
// Skip group overrides if not including groups.
$groupinfo = $this->get_setting_value('groups');
if (!$groupinfo) {
$overrideparams['groupid'] = backup_helper::is_sqlparam(null);
}
$override->set_source_table('quiz_overrides', $overrideparams);
// All the rest of elements only happen if we are including user info.
if ($userinfo) {
$grade->set_source_table('quiz_grades', array('quiz' => backup::VAR_PARENTID));
$attempt->set_source_sql('
SELECT *
FROM {quiz_attempts}
WHERE quiz = :quiz AND preview = 0',
array('quiz' => backup::VAR_PARENTID));
}
// Define source alias.
$quiz->set_source_alias('attempts', 'attempts_number');
$grade->set_source_alias('grade', 'gradeval');
$attempt->set_source_alias('attempt', 'attemptnum');
// Define id annotations.
$qinstance->annotate_ids('question', 'questionid');
$override->annotate_ids('user', 'userid');
$override->annotate_ids('group', 'groupid');
$grade->annotate_ids('user', 'userid');
$attempt->annotate_ids('user', 'userid');
// Define file annotations.
$quiz->annotate_files('mod_quiz', 'intro', null); // This file area hasn't itemid.
$feedback->annotate_files('mod_quiz', 'feedback', 'id');
// Return the root element (quiz), wrapped into standard activity structure.
return $this->prepare_activity_structure($quiz);
}
}