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