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 |
* Define all the backup steps that will be used by the backup_quiz_activity_task.
|
|
|
19 |
*
|
|
|
20 |
* @package mod_quiz
|
|
|
21 |
* @subpackage backup-moodle2
|
|
|
22 |
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
class backup_quiz_activity_structure_step extends backup_questions_activity_structure_step {
|
|
|
26 |
|
|
|
27 |
protected function define_structure() {
|
|
|
28 |
|
|
|
29 |
// To know if we are including userinfo.
|
|
|
30 |
$userinfo = $this->get_setting_value('userinfo');
|
|
|
31 |
|
|
|
32 |
// Define each element separated.
|
|
|
33 |
$quiz = new backup_nested_element('quiz', ['id'], [
|
|
|
34 |
'name', 'intro', 'introformat', 'timeopen', 'timeclose', 'timelimit',
|
|
|
35 |
'overduehandling', 'graceperiod', 'preferredbehaviour', 'canredoquestions', 'attempts_number',
|
|
|
36 |
'attemptonlast', 'grademethod', 'decimalpoints', 'questiondecimalpoints',
|
|
|
37 |
'reviewattempt', 'reviewcorrectness', 'reviewmaxmarks', 'reviewmarks',
|
|
|
38 |
'reviewspecificfeedback', 'reviewgeneralfeedback',
|
|
|
39 |
'reviewrightanswer', 'reviewoverallfeedback',
|
|
|
40 |
'questionsperpage', 'navmethod', 'shuffleanswers',
|
|
|
41 |
'sumgrades', 'grade', 'timecreated',
|
|
|
42 |
'timemodified', 'password', 'subnet', 'browsersecurity',
|
|
|
43 |
'delay1', 'delay2', 'showuserpicture', 'showblocks', 'completionattemptsexhausted',
|
|
|
44 |
'completionminattempts', 'allowofflineattempts']);
|
|
|
45 |
|
|
|
46 |
// Define elements for access rule subplugin settings.
|
|
|
47 |
$this->add_subplugin_structure('quizaccess', $quiz, true);
|
|
|
48 |
|
|
|
49 |
$quizgradeitems = new backup_nested_element('quiz_grade_items');
|
|
|
50 |
|
|
|
51 |
$quizgradeitem = new backup_nested_element('quiz_grade_item', ['id'], ['sortorder', 'name']);
|
|
|
52 |
|
|
|
53 |
$qinstances = new backup_nested_element('question_instances');
|
|
|
54 |
|
|
|
55 |
$qinstance = new backup_nested_element('question_instance', ['id'],
|
|
|
56 |
['quizid', 'slot', 'page', 'displaynumber', 'requireprevious', 'maxmark', 'quizgradeitemid']);
|
|
|
57 |
|
|
|
58 |
$this->add_question_references($qinstance, 'mod_quiz', 'slot');
|
|
|
59 |
|
|
|
60 |
$this->add_question_set_references($qinstance, 'mod_quiz', 'slot');
|
|
|
61 |
|
|
|
62 |
$sections = new backup_nested_element('sections');
|
|
|
63 |
|
|
|
64 |
$section = new backup_nested_element('section', ['id'], ['firstslot', 'heading', 'shufflequestions']);
|
|
|
65 |
|
|
|
66 |
$feedbacks = new backup_nested_element('feedbacks');
|
|
|
67 |
|
|
|
68 |
$feedback = new backup_nested_element('feedback', ['id'], ['feedbacktext', 'feedbacktextformat', 'mingrade', 'maxgrade']);
|
|
|
69 |
|
|
|
70 |
$overrides = new backup_nested_element('overrides');
|
|
|
71 |
|
|
|
72 |
$override = new backup_nested_element('override', ['id'], [
|
|
|
73 |
'userid', 'groupid', 'timeopen', 'timeclose',
|
|
|
74 |
'timelimit', 'attempts', 'password']);
|
|
|
75 |
|
|
|
76 |
$grades = new backup_nested_element('grades');
|
|
|
77 |
|
|
|
78 |
$grade = new backup_nested_element('grade', ['id'], ['userid', 'gradeval', 'timemodified']);
|
|
|
79 |
|
|
|
80 |
$attempts = new backup_nested_element('attempts');
|
|
|
81 |
|
|
|
82 |
$attempt = new backup_nested_element('attempt', ['id'], [
|
|
|
83 |
'userid', 'attemptnum', 'uniqueid', 'layout', 'currentpage', 'preview',
|
|
|
84 |
'state', 'timestart', 'timefinish', 'timemodified', 'timemodifiedoffline',
|
|
|
85 |
'timecheckstate', 'sumgrades', 'gradednotificationsenttime']);
|
|
|
86 |
|
|
|
87 |
// This module is using questions, so produce the related question states and sessions
|
|
|
88 |
// attaching them to the $attempt element based in 'uniqueid' matching.
|
|
|
89 |
$this->add_question_usages($attempt, 'uniqueid');
|
|
|
90 |
|
|
|
91 |
// Define elements for access rule subplugin attempt data.
|
|
|
92 |
$this->add_subplugin_structure('quizaccess', $attempt, true);
|
|
|
93 |
|
|
|
94 |
// Build the tree.
|
|
|
95 |
$quiz->add_child($quizgradeitems);
|
|
|
96 |
$quizgradeitems->add_child($quizgradeitem);
|
|
|
97 |
|
|
|
98 |
$quiz->add_child($qinstances);
|
|
|
99 |
$qinstances->add_child($qinstance);
|
|
|
100 |
|
|
|
101 |
$quiz->add_child($sections);
|
|
|
102 |
$sections->add_child($section);
|
|
|
103 |
|
|
|
104 |
$quiz->add_child($feedbacks);
|
|
|
105 |
$feedbacks->add_child($feedback);
|
|
|
106 |
|
|
|
107 |
$quiz->add_child($overrides);
|
|
|
108 |
$overrides->add_child($override);
|
|
|
109 |
|
|
|
110 |
$quiz->add_child($grades);
|
|
|
111 |
$grades->add_child($grade);
|
|
|
112 |
|
|
|
113 |
$quiz->add_child($attempts);
|
|
|
114 |
$attempts->add_child($attempt);
|
|
|
115 |
|
|
|
116 |
// Define sources.
|
|
|
117 |
$quiz->set_source_table('quiz', ['id' => backup::VAR_ACTIVITYID]);
|
|
|
118 |
|
|
|
119 |
$quizgradeitem->set_source_table('quiz_grade_items', ['quizid' => backup::VAR_PARENTID]);
|
|
|
120 |
|
|
|
121 |
$qinstance->set_source_table('quiz_slots', ['quizid' => backup::VAR_PARENTID]);
|
|
|
122 |
|
|
|
123 |
$section->set_source_table('quiz_sections', ['quizid' => backup::VAR_PARENTID]);
|
|
|
124 |
|
|
|
125 |
$feedback->set_source_table('quiz_feedback', ['quizid' => backup::VAR_PARENTID]);
|
|
|
126 |
|
|
|
127 |
// Quiz overrides to backup are different depending of user info.
|
|
|
128 |
$overrideparams = ['quiz' => backup::VAR_PARENTID];
|
|
|
129 |
if (!$userinfo) { // Without userinfo, skip user overrides.
|
|
|
130 |
$overrideparams['userid'] = backup_helper::is_sqlparam(null);
|
|
|
131 |
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
// Skip group overrides if not including groups.
|
|
|
135 |
$groupinfo = $this->get_setting_value('groups');
|
|
|
136 |
if (!$groupinfo) {
|
|
|
137 |
$overrideparams['groupid'] = backup_helper::is_sqlparam(null);
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
$override->set_source_table('quiz_overrides', $overrideparams);
|
|
|
141 |
|
|
|
142 |
// All the rest of elements only happen if we are including user info.
|
|
|
143 |
if ($userinfo) {
|
|
|
144 |
$grade->set_source_table('quiz_grades', ['quiz' => backup::VAR_PARENTID]);
|
|
|
145 |
$attempt->set_source_sql('
|
|
|
146 |
SELECT *
|
|
|
147 |
FROM {quiz_attempts}
|
|
|
148 |
WHERE quiz = :quiz AND preview = 0', ['quiz' => backup::VAR_PARENTID]);
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
// Define source alias.
|
|
|
152 |
$quiz->set_source_alias('attempts', 'attempts_number');
|
|
|
153 |
$grade->set_source_alias('grade', 'gradeval');
|
|
|
154 |
$attempt->set_source_alias('attempt', 'attemptnum');
|
|
|
155 |
|
|
|
156 |
// Define id annotations.
|
|
|
157 |
$override->annotate_ids('user', 'userid');
|
|
|
158 |
$override->annotate_ids('group', 'groupid');
|
|
|
159 |
$grade->annotate_ids('user', 'userid');
|
|
|
160 |
$attempt->annotate_ids('user', 'userid');
|
|
|
161 |
|
|
|
162 |
// Define file annotations.
|
|
|
163 |
$quiz->annotate_files('mod_quiz', 'intro', null); // This file area hasn't itemid.
|
|
|
164 |
$feedback->annotate_files('mod_quiz', 'feedback', 'id');
|
|
|
165 |
|
|
|
166 |
// Return the root element (quiz), wrapped into standard activity structure.
|
|
|
167 |
return $this->prepare_activity_structure($quiz);
|
|
|
168 |
}
|
|
|
169 |
}
|