Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402]
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 void 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 'preventsubmissionnotingroup', 95 'activity', 96 'activityformat', 97 'timelimit', 98 'submissionattachments')); 99 100 $userflags = new backup_nested_element('userflags'); 101 102 $userflag = new backup_nested_element('userflag', array('id'), 103 array('userid', 104 'assignment', 105 'mailed', 106 'locked', 107 'extensionduedate', 108 'workflowstate', 109 'allocatedmarker')); 110 111 $submissions = new backup_nested_element('submissions'); 112 113 $submission = new backup_nested_element('submission', array('id'), 114 array('userid', 115 'timecreated', 116 'timemodified', 117 'timestarted', 118 'status', 119 'groupid', 120 'attemptnumber', 121 'latest')); 122 123 $grades = new backup_nested_element('grades'); 124 125 $grade = new backup_nested_element('grade', array('id'), 126 array('userid', 127 'timecreated', 128 'timemodified', 129 'grader', 130 'grade', 131 'attemptnumber')); 132 133 $pluginconfigs = new backup_nested_element('plugin_configs'); 134 135 $pluginconfig = new backup_nested_element('plugin_config', array('id'), 136 array('plugin', 137 'subtype', 138 'name', 139 'value')); 140 141 $overrides = new backup_nested_element('overrides'); 142 $override = new backup_nested_element('override', array('id'), array( 143 'groupid', 'userid', 'sortorder', 'allowsubmissionsfromdate', 'duedate', 'cutoffdate', 'timelimit')); 144 145 // Build the tree. 146 $assign->add_child($userflags); 147 $userflags->add_child($userflag); 148 $assign->add_child($submissions); 149 $submissions->add_child($submission); 150 $assign->add_child($grades); 151 $grades->add_child($grade); 152 $assign->add_child($pluginconfigs); 153 $pluginconfigs->add_child($pluginconfig); 154 $assign->add_child($overrides); 155 $overrides->add_child($override); 156 157 // Define sources. 158 $assign->set_source_table('assign', array('id' => backup::VAR_ACTIVITYID)); 159 $pluginconfig->set_source_table('assign_plugin_config', 160 array('assignment' => backup::VAR_PARENTID)); 161 162 // Assign overrides to backup are different depending of user info. 163 $overrideparams = array('assignid' => backup::VAR_PARENTID); 164 165 if ($userinfo) { 166 $userflag->set_source_table('assign_user_flags', 167 array('assignment' => backup::VAR_PARENTID)); 168 169 $submissionparams = array('assignment' => backup::VAR_PARENTID); 170 if (!$groupinfo) { 171 // Without group info, skip group submissions. 172 $submissionparams['groupid'] = backup_helper::is_sqlparam(0); 173 } 174 $submission->set_source_table('assign_submission', $submissionparams); 175 176 $grade->set_source_table('assign_grades', 177 array('assignment' => backup::VAR_PARENTID)); 178 179 // Support 2 types of subplugins. 180 $this->add_subplugin_structure('assignsubmission', $submission, true); 181 $this->add_subplugin_structure('assignfeedback', $grade, true); 182 } else { 183 $overrideparams['userid'] = backup_helper::is_sqlparam(null); // Without userinfo, skip user overrides. 184 } 185 186 if (!$groupinfo) { 187 // Without group info, skip group overrides. 188 $overrideparams['groupid'] = backup_helper::is_sqlparam(0); 189 } 190 $override->set_source_table('assign_overrides', $overrideparams); 191 192 // Define id annotations. 193 $userflag->annotate_ids('user', 'userid'); 194 $userflag->annotate_ids('user', 'allocatedmarker'); 195 $submission->annotate_ids('user', 'userid'); 196 $submission->annotate_ids('group', 'groupid'); 197 $grade->annotate_ids('user', 'userid'); 198 $grade->annotate_ids('user', 'grader'); 199 $assign->annotate_ids('grouping', 'teamsubmissiongroupingid'); 200 $override->annotate_ids('user', 'userid'); 201 $override->annotate_ids('group', 'groupid'); 202 203 // Define file annotations. 204 // These file areas don't have an itemid. 205 $assign->annotate_files('mod_assign', 'intro', null); 206 $assign->annotate_files('mod_assign', 'introattachment', null); 207 $this->annotate_plugin_config_files($assign, 'assignsubmission'); 208 $this->annotate_plugin_config_files($assign, 'assignfeedback'); 209 210 // Return the root element (choice), wrapped into standard activity structure. 211 212 return $this->prepare_activity_structure($assign); 213 } 214 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body