|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00031 class restore_feedback_activity_structure_step extends restore_activity_structure_step { 00032 00033 protected function define_structure() { 00034 00035 $paths = array(); 00036 $userinfo = $this->get_setting_value('userinfo'); 00037 00038 $paths[] = new restore_path_element('feedback', '/activity/feedback'); 00039 $paths[] = new restore_path_element('feedback_item', '/activity/feedback/items/item'); 00040 if ($userinfo) { 00041 $paths[] = new restore_path_element('feedback_completed', '/activity/feedback/completeds/completed'); 00042 $paths[] = new restore_path_element('feedback_value', '/activity/feedback/completeds/completed/values/value'); 00043 $paths[] = new restore_path_element('feedback_tracking', '/activity/feedback/trackings/tracking'); 00044 } 00045 00046 // Return the paths wrapped into standard activity structure 00047 return $this->prepare_activity_structure($paths); 00048 } 00049 00050 protected function process_feedback($data) { 00051 global $DB; 00052 00053 $data = (object)$data; 00054 $oldid = $data->id; 00055 $data->course = $this->get_courseid(); 00056 00057 $data->timeopen = $this->apply_date_offset($data->timeopen); 00058 $data->timeclose = $this->apply_date_offset($data->timeclose); 00059 $data->timemodified = $this->apply_date_offset($data->timemodified); 00060 00061 // insert the feedback record 00062 $newitemid = $DB->insert_record('feedback', $data); 00063 // immediately after inserting "activity" record, call this 00064 $this->apply_activity_instance($newitemid); 00065 } 00066 00067 protected function process_feedback_item($data) { 00068 global $DB; 00069 00070 $data = (object)$data; 00071 $oldid = $data->id; 00072 $data->feedback = $this->get_new_parentid('feedback'); 00073 00074 //dependitem 00075 $data->dependitem = $this->get_mappingid('feedback_item', $data->dependitem); 00076 00077 $newitemid = $DB->insert_record('feedback_item', $data); 00078 $this->set_mapping('feedback_item', $oldid, $newitemid, true); // Can have files 00079 } 00080 00081 protected function process_feedback_completed($data) { 00082 global $DB; 00083 00084 $data = (object)$data; 00085 $oldid = $data->id; 00086 $data->feedback = $this->get_new_parentid('feedback'); 00087 $data->userid = $this->get_mappingid('user', $data->userid); 00088 $data->timemodified = $this->apply_date_offset($data->timemodified); 00089 00090 $newitemid = $DB->insert_record('feedback_completed', $data); 00091 $this->set_mapping('feedback_completed', $oldid, $newitemid); 00092 } 00093 00094 protected function process_feedback_value($data) { 00095 global $DB; 00096 00097 $data = (object)$data; 00098 $oldid = $data->id; 00099 $data->completed = $this->get_new_parentid('feedback_completed'); 00100 $data->item = $this->get_mappingid('feedback_item', $data->item); 00101 $data->course_id = $this->get_courseid(); 00102 00103 $newitemid = $DB->insert_record('feedback_value', $data); 00104 $this->set_mapping('feedback_value', $oldid, $newitemid); 00105 } 00106 00107 protected function process_feedback_tracking($data) { 00108 global $DB; 00109 00110 $data = (object)$data; 00111 $oldid = $data->id; 00112 $data->feedback = $this->get_new_parentid('feedback'); 00113 $data->completed = $this->get_mappingid('feedback_completed', $data->completed); 00114 $data->userid = $this->get_mappingid('user', $data->userid); 00115 00116 $newitemid = $DB->insert_record('feedback_tracking', $data); 00117 } 00118 00119 00120 protected function after_execute() { 00121 // Add feedback related files, no need to match by itemname (just internally handled context) 00122 $this->add_related_files('mod_feedback', 'intro', null); 00123 $this->add_related_files('mod_feedback', 'item', 'feedback_item'); 00124 } 00125 }