|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00032 class restore_assignment_activity_structure_step extends restore_activity_structure_step { 00033 00034 protected function define_structure() { 00035 00036 $paths = array(); 00037 $userinfo = $this->get_setting_value('userinfo'); 00038 00039 $assignment = new restore_path_element('assignment', '/activity/assignment'); 00040 $paths[] = $assignment; 00041 00042 // Apply for 'assignment' subplugins optional paths at assignment level 00043 $this->add_subplugin_structure('assignment', $assignment); 00044 00045 if ($userinfo) { 00046 $submission = new restore_path_element('assignment_submission', '/activity/assignment/submissions/submission'); 00047 $paths[] = $submission; 00048 // Apply for 'assignment' subplugins optional stuff at submission level 00049 $this->add_subplugin_structure('assignment', $submission); 00050 } 00051 00052 // Return the paths wrapped into standard activity structure 00053 return $this->prepare_activity_structure($paths); 00054 } 00055 00056 protected function process_assignment($data) { 00057 global $DB; 00058 00059 $data = (object)$data; 00060 $oldid = $data->id; 00061 $data->course = $this->get_courseid(); 00062 00063 $data->timedue = $this->apply_date_offset($data->timedue); 00064 $data->timeavailable = $this->apply_date_offset($data->timeavailable); 00065 $data->timemodified = $this->apply_date_offset($data->timemodified); 00066 00067 if ($data->grade < 0) { // scale found, get mapping 00068 $data->grade = -($this->get_mappingid('scale', abs($data->grade))); 00069 } 00070 00071 // insert the assignment record 00072 $newitemid = $DB->insert_record('assignment', $data); 00073 // immediately after inserting "activity" record, call this 00074 $this->apply_activity_instance($newitemid); 00075 } 00076 00077 protected function process_assignment_submission($data) { 00078 global $DB; 00079 00080 $data = (object)$data; 00081 $oldid = $data->id; 00082 00083 $data->assignment = $this->get_new_parentid('assignment'); 00084 $data->timecreated = $this->apply_date_offset($data->timecreated); 00085 $data->timemodified = $this->apply_date_offset($data->timemodified); 00086 $data->timemarked = $this->apply_date_offset($data->timemarked); 00087 00088 $data->userid = $this->get_mappingid('user', $data->userid); 00089 $data->teacher = $this->get_mappingid('user', $data->teacher); 00090 00091 $newitemid = $DB->insert_record('assignment_submissions', $data); 00092 $this->set_mapping('assignment_submission', $oldid, $newitemid, true); // Going to have files 00093 $this->set_mapping(restore_gradingform_plugin::itemid_mapping('submission'), $oldid, $newitemid); 00094 } 00095 00096 protected function after_execute() { 00097 // Add assignment related files, no need to match by itemname (just internally handled context) 00098 $this->add_related_files('mod_assignment', 'intro', null); 00099 // Add assignment submission files, matching by assignment_submission itemname 00100 $this->add_related_files('mod_assignment', 'submission', 'assignment_submission'); 00101 $this->add_related_files('mod_assignment', 'response', 'assignment_submission'); 00102 } 00103 }