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_assign_activity_task
|
|
|
19 |
*
|
|
|
20 |
* @package mod_assign
|
|
|
21 |
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
defined('MOODLE_INTERNAL') || die();
|
|
|
26 |
|
|
|
27 |
require_once($CFG->dirroot . '/mod/assign/locallib.php');
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Define the complete choice structure for backup, with file and id annotations
|
|
|
31 |
*
|
|
|
32 |
* @package mod_assign
|
|
|
33 |
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
|
|
|
34 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
35 |
*/
|
|
|
36 |
class backup_assign_activity_structure_step extends backup_activity_structure_step {
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* Annotate files from plugin configuration
|
|
|
40 |
* @param backup_nested_element $assign the backup structure of the activity
|
|
|
41 |
* @param string $subtype the plugin type to handle
|
|
|
42 |
* @return void
|
|
|
43 |
*/
|
|
|
44 |
protected function annotate_plugin_config_files(backup_nested_element $assign, $subtype) {
|
|
|
45 |
$dummyassign = new assign(null, null, null);
|
|
|
46 |
$plugins = $dummyassign->load_plugins($subtype);
|
|
|
47 |
foreach ($plugins as $plugin) {
|
|
|
48 |
$component = $plugin->get_subtype() . '_' . $plugin->get_type();
|
|
|
49 |
$areas = $plugin->get_config_file_areas();
|
|
|
50 |
foreach ($areas as $area) {
|
|
|
51 |
$assign->annotate_files($component, $area, null);
|
|
|
52 |
}
|
|
|
53 |
}
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* Define the structure for the assign activity
|
|
|
58 |
* @return backup_nested_element
|
|
|
59 |
*/
|
|
|
60 |
protected function define_structure() {
|
|
|
61 |
|
|
|
62 |
// To know if we are including userinfo.
|
|
|
63 |
$userinfo = $this->get_setting_value('userinfo');
|
|
|
64 |
$groupinfo = $this->get_setting_value('groups');
|
|
|
65 |
|
|
|
66 |
// Define each element separated.
|
|
|
67 |
$assign = new backup_nested_element('assign', array('id'),
|
|
|
68 |
array('name',
|
|
|
69 |
'intro',
|
|
|
70 |
'introformat',
|
|
|
71 |
'alwaysshowdescription',
|
|
|
72 |
'submissiondrafts',
|
|
|
73 |
'sendnotifications',
|
|
|
74 |
'sendlatenotifications',
|
|
|
75 |
'sendstudentnotifications',
|
|
|
76 |
'duedate',
|
|
|
77 |
'cutoffdate',
|
|
|
78 |
'gradingduedate',
|
|
|
79 |
'allowsubmissionsfromdate',
|
|
|
80 |
'grade',
|
|
|
81 |
'timemodified',
|
|
|
82 |
'completionsubmit',
|
|
|
83 |
'requiresubmissionstatement',
|
|
|
84 |
'teamsubmission',
|
|
|
85 |
'requireallteammemberssubmit',
|
|
|
86 |
'teamsubmissiongroupingid',
|
|
|
87 |
'blindmarking',
|
|
|
88 |
'hidegrader',
|
|
|
89 |
'revealidentities',
|
|
|
90 |
'attemptreopenmethod',
|
|
|
91 |
'maxattempts',
|
|
|
92 |
'markingworkflow',
|
|
|
93 |
'markingallocation',
|
|
|
94 |
'markinganonymous',
|
|
|
95 |
'preventsubmissionnotingroup',
|
|
|
96 |
'activity',
|
|
|
97 |
'activityformat',
|
|
|
98 |
'timelimit',
|
|
|
99 |
'submissionattachments'));
|
|
|
100 |
|
|
|
101 |
$userflags = new backup_nested_element('userflags');
|
|
|
102 |
|
|
|
103 |
$userflag = new backup_nested_element('userflag', array('id'),
|
|
|
104 |
array('userid',
|
|
|
105 |
'assignment',
|
|
|
106 |
'mailed',
|
|
|
107 |
'locked',
|
|
|
108 |
'extensionduedate',
|
|
|
109 |
'workflowstate',
|
|
|
110 |
'allocatedmarker'));
|
|
|
111 |
|
|
|
112 |
$submissions = new backup_nested_element('submissions');
|
|
|
113 |
|
|
|
114 |
$submission = new backup_nested_element('submission', array('id'),
|
|
|
115 |
array('userid',
|
|
|
116 |
'timecreated',
|
|
|
117 |
'timemodified',
|
|
|
118 |
'timestarted',
|
|
|
119 |
'status',
|
|
|
120 |
'groupid',
|
|
|
121 |
'attemptnumber',
|
|
|
122 |
'latest'));
|
|
|
123 |
|
|
|
124 |
$grades = new backup_nested_element('grades');
|
|
|
125 |
|
|
|
126 |
$grade = new backup_nested_element('grade', array('id'),
|
|
|
127 |
array('userid',
|
|
|
128 |
'timecreated',
|
|
|
129 |
'timemodified',
|
|
|
130 |
'grader',
|
|
|
131 |
'grade',
|
|
|
132 |
'attemptnumber'));
|
|
|
133 |
|
|
|
134 |
$pluginconfigs = new backup_nested_element('plugin_configs');
|
|
|
135 |
|
|
|
136 |
$pluginconfig = new backup_nested_element('plugin_config', array('id'),
|
|
|
137 |
array('plugin',
|
|
|
138 |
'subtype',
|
|
|
139 |
'name',
|
|
|
140 |
'value'));
|
|
|
141 |
|
|
|
142 |
$overrides = new backup_nested_element('overrides');
|
|
|
143 |
$override = new backup_nested_element('override', array('id'), array(
|
|
|
144 |
'groupid', 'userid', 'sortorder', 'allowsubmissionsfromdate', 'duedate', 'cutoffdate', 'timelimit'));
|
|
|
145 |
|
|
|
146 |
// Build the tree.
|
|
|
147 |
$assign->add_child($userflags);
|
|
|
148 |
$userflags->add_child($userflag);
|
|
|
149 |
$assign->add_child($submissions);
|
|
|
150 |
$submissions->add_child($submission);
|
|
|
151 |
$assign->add_child($grades);
|
|
|
152 |
$grades->add_child($grade);
|
|
|
153 |
$assign->add_child($pluginconfigs);
|
|
|
154 |
$pluginconfigs->add_child($pluginconfig);
|
|
|
155 |
$assign->add_child($overrides);
|
|
|
156 |
$overrides->add_child($override);
|
|
|
157 |
|
|
|
158 |
// Define sources.
|
|
|
159 |
$assign->set_source_table('assign', array('id' => backup::VAR_ACTIVITYID));
|
|
|
160 |
$pluginconfig->set_source_table('assign_plugin_config',
|
|
|
161 |
array('assignment' => backup::VAR_PARENTID));
|
|
|
162 |
|
|
|
163 |
// Assign overrides to backup are different depending of user info.
|
|
|
164 |
$overrideparams = array('assignid' => backup::VAR_PARENTID);
|
|
|
165 |
|
|
|
166 |
if ($userinfo) {
|
|
|
167 |
$userflag->set_source_table('assign_user_flags',
|
|
|
168 |
array('assignment' => backup::VAR_PARENTID));
|
|
|
169 |
|
|
|
170 |
$submissionparams = array('assignment' => backup::VAR_PARENTID);
|
|
|
171 |
if (!$groupinfo) {
|
|
|
172 |
// Without group info, skip group submissions.
|
|
|
173 |
$submissionparams['groupid'] = backup_helper::is_sqlparam(0);
|
|
|
174 |
}
|
|
|
175 |
$submission->set_source_table('assign_submission', $submissionparams);
|
|
|
176 |
|
|
|
177 |
$grade->set_source_table('assign_grades',
|
|
|
178 |
array('assignment' => backup::VAR_PARENTID));
|
|
|
179 |
|
|
|
180 |
// Support 2 types of subplugins.
|
|
|
181 |
$this->add_subplugin_structure('assignsubmission', $submission, true);
|
|
|
182 |
$this->add_subplugin_structure('assignfeedback', $grade, true);
|
|
|
183 |
} else {
|
|
|
184 |
$overrideparams['userid'] = backup_helper::is_sqlparam(null); // Without userinfo, skip user overrides.
|
|
|
185 |
}
|
|
|
186 |
|
|
|
187 |
if (!$groupinfo) {
|
|
|
188 |
// Without group info, skip group overrides.
|
|
|
189 |
$overrideparams['groupid'] = backup_helper::is_sqlparam(0);
|
|
|
190 |
}
|
|
|
191 |
$override->set_source_table('assign_overrides', $overrideparams);
|
|
|
192 |
|
|
|
193 |
// Define id annotations.
|
|
|
194 |
$userflag->annotate_ids('user', 'userid');
|
|
|
195 |
$userflag->annotate_ids('user', 'allocatedmarker');
|
|
|
196 |
$submission->annotate_ids('user', 'userid');
|
|
|
197 |
$submission->annotate_ids('group', 'groupid');
|
|
|
198 |
$grade->annotate_ids('user', 'userid');
|
|
|
199 |
$grade->annotate_ids('user', 'grader');
|
|
|
200 |
$assign->annotate_ids('grouping', 'teamsubmissiongroupingid');
|
|
|
201 |
$override->annotate_ids('user', 'userid');
|
|
|
202 |
$override->annotate_ids('group', 'groupid');
|
|
|
203 |
|
|
|
204 |
// Define file annotations.
|
|
|
205 |
// These file areas don't have an itemid.
|
|
|
206 |
$assign->annotate_files('mod_assign', 'intro', null);
|
|
|
207 |
$assign->annotate_files('mod_assign', 'introattachment', null);
|
|
|
208 |
$assign->annotate_files('mod_assign', 'activityattachment', null);
|
|
|
209 |
|
|
|
210 |
$this->annotate_plugin_config_files($assign, 'assignsubmission');
|
|
|
211 |
$this->annotate_plugin_config_files($assign, 'assignfeedback');
|
|
|
212 |
|
|
|
213 |
// Return the root element (choice), wrapped into standard activity structure.
|
|
|
214 |
|
|
|
215 |
return $this->prepare_activity_structure($assign);
|
|
|
216 |
}
|
|
|
217 |
}
|