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