Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
 * 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',
1441 ariadna 44
            'completionminattempts', 'allowofflineattempts', 'precreateattempts']);
1 efrain 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
 
1441 ariadna 62
        $this->annotate_set_reference_bank_entries($this->task->get_contextid(), 'mod_quiz', 'slot', $this->task->get_backupid());
63
 
1 efrain 64
        $sections = new backup_nested_element('sections');
65
 
66
        $section = new backup_nested_element('section', ['id'], ['firstslot', 'heading', 'shufflequestions']);
67
 
68
        $feedbacks = new backup_nested_element('feedbacks');
69
 
70
        $feedback = new backup_nested_element('feedback', ['id'], ['feedbacktext', 'feedbacktextformat', 'mingrade', 'maxgrade']);
71
 
72
        $overrides = new backup_nested_element('overrides');
73
 
74
        $override = new backup_nested_element('override', ['id'], [
75
            'userid', 'groupid', 'timeopen', 'timeclose',
76
            'timelimit', 'attempts', 'password']);
77
 
78
        $grades = new backup_nested_element('grades');
79
 
80
        $grade = new backup_nested_element('grade', ['id'], ['userid', 'gradeval', 'timemodified']);
81
 
82
        $attempts = new backup_nested_element('attempts');
83
 
84
        $attempt = new backup_nested_element('attempt', ['id'], [
85
            'userid', 'attemptnum', 'uniqueid', 'layout', 'currentpage', 'preview',
86
            'state', 'timestart', 'timefinish', 'timemodified', 'timemodifiedoffline',
87
            'timecheckstate', 'sumgrades', 'gradednotificationsenttime']);
88
 
89
        // This module is using questions, so produce the related question states and sessions
90
        // attaching them to the $attempt element based in 'uniqueid' matching.
91
        $this->add_question_usages($attempt, 'uniqueid');
92
 
93
        // Define elements for access rule subplugin attempt data.
94
        $this->add_subplugin_structure('quizaccess', $attempt, true);
95
 
96
        // Build the tree.
97
        $quiz->add_child($quizgradeitems);
98
        $quizgradeitems->add_child($quizgradeitem);
99
 
100
        $quiz->add_child($qinstances);
101
        $qinstances->add_child($qinstance);
102
 
103
        $quiz->add_child($sections);
104
        $sections->add_child($section);
105
 
106
        $quiz->add_child($feedbacks);
107
        $feedbacks->add_child($feedback);
108
 
109
        $quiz->add_child($overrides);
110
        $overrides->add_child($override);
111
 
112
        $quiz->add_child($grades);
113
        $grades->add_child($grade);
114
 
115
        $quiz->add_child($attempts);
116
        $attempts->add_child($attempt);
117
 
118
        // Define sources.
119
        $quiz->set_source_table('quiz', ['id' => backup::VAR_ACTIVITYID]);
120
 
121
        $quizgradeitem->set_source_table('quiz_grade_items', ['quizid' => backup::VAR_PARENTID]);
122
 
123
        $qinstance->set_source_table('quiz_slots', ['quizid' => backup::VAR_PARENTID]);
124
 
125
        $section->set_source_table('quiz_sections', ['quizid' => backup::VAR_PARENTID]);
126
 
127
        $feedback->set_source_table('quiz_feedback', ['quizid' => backup::VAR_PARENTID]);
128
 
129
        // Quiz overrides to backup are different depending of user info.
130
        $overrideparams = ['quiz' => backup::VAR_PARENTID];
131
        if (!$userinfo) { //  Without userinfo, skip user overrides.
132
            $overrideparams['userid'] = backup_helper::is_sqlparam(null);
133
 
134
        }
135
 
136
        // Skip group overrides if not including groups.
137
        $groupinfo = $this->get_setting_value('groups');
138
        if (!$groupinfo) {
139
            $overrideparams['groupid'] = backup_helper::is_sqlparam(null);
140
        }
141
 
142
        $override->set_source_table('quiz_overrides', $overrideparams);
143
 
144
        // All the rest of elements only happen if we are including user info.
145
        if ($userinfo) {
146
            $grade->set_source_table('quiz_grades', ['quiz' => backup::VAR_PARENTID]);
147
            $attempt->set_source_sql('
148
                    SELECT *
149
                    FROM {quiz_attempts}
150
                    WHERE quiz = :quiz AND preview = 0', ['quiz' => backup::VAR_PARENTID]);
151
        }
152
 
153
        // Define source alias.
154
        $quiz->set_source_alias('attempts', 'attempts_number');
155
        $grade->set_source_alias('grade', 'gradeval');
156
        $attempt->set_source_alias('attempt', 'attemptnum');
157
 
158
        // Define id annotations.
159
        $override->annotate_ids('user', 'userid');
160
        $override->annotate_ids('group', 'groupid');
161
        $grade->annotate_ids('user', 'userid');
162
        $attempt->annotate_ids('user', 'userid');
163
 
164
        // Define file annotations.
165
        $quiz->annotate_files('mod_quiz', 'intro', null); // This file area hasn't itemid.
166
        $feedback->annotate_files('mod_quiz', 'feedback', 'id');
167
 
168
        // Return the root element (quiz), wrapped into standard activity structure.
169
        return $this->prepare_activity_structure($quiz);
170
    }
171
}