|
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_choice_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 $paths[] = new restore_path_element('choice', '/activity/choice'); 00040 $paths[] = new restore_path_element('choice_option', '/activity/choice/options/option'); 00041 if ($userinfo) { 00042 $paths[] = new restore_path_element('choice_answer', '/activity/choice/answers/answer'); 00043 } 00044 00045 // Return the paths wrapped into standard activity structure 00046 return $this->prepare_activity_structure($paths); 00047 } 00048 00049 protected function process_choice($data) { 00050 global $DB; 00051 00052 $data = (object)$data; 00053 $oldid = $data->id; 00054 $data->course = $this->get_courseid(); 00055 00056 $data->timeopen = $this->apply_date_offset($data->timeopen); 00057 $data->timeclose = $this->apply_date_offset($data->timeclose); 00058 $data->timemodified = $this->apply_date_offset($data->timemodified); 00059 00060 // insert the choice record 00061 $newitemid = $DB->insert_record('choice', $data); 00062 // immediately after inserting "activity" record, call this 00063 $this->apply_activity_instance($newitemid); 00064 } 00065 00066 protected function process_choice_option($data) { 00067 global $DB; 00068 00069 $data = (object)$data; 00070 $oldid = $data->id; 00071 00072 $data->choiceid = $this->get_new_parentid('choice'); 00073 $data->timemodified = $this->apply_date_offset($data->timemodified); 00074 00075 $newitemid = $DB->insert_record('choice_options', $data); 00076 $this->set_mapping('choice_option', $oldid, $newitemid); 00077 } 00078 00079 protected function process_choice_answer($data) { 00080 global $DB; 00081 00082 $data = (object)$data; 00083 $oldid = $data->id; 00084 00085 $data->choiceid = $this->get_new_parentid('choice'); 00086 $data->optionid = $this->get_mappingid('choice_option', $oldid); 00087 $data->userid = $this->get_mappingid('user', $data->userid); 00088 $data->timemodified = $this->apply_date_offset($data->timemodified); 00089 00090 $newitemid = $DB->insert_record('choice_answers', $data); 00091 // No need to save this mapping as far as nothing depend on it 00092 // (child paths, file areas nor links decoder) 00093 } 00094 00095 protected function after_execute() { 00096 // Add choice related files, no need to match by itemname (just internally handled context) 00097 $this->add_related_files('mod_choice', 'intro', null); 00098 } 00099 }