|
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_chat_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('chat', '/activity/chat'); 00040 if ($userinfo) { 00041 $paths[] = new restore_path_element('chat_message', '/activity/chat/messages/message'); 00042 } 00043 00044 // Return the paths wrapped into standard activity structure 00045 return $this->prepare_activity_structure($paths); 00046 } 00047 00048 protected function process_chat($data) { 00049 global $DB; 00050 00051 $data = (object)$data; 00052 $oldid = $data->id; 00053 $data->course = $this->get_courseid(); 00054 00055 $data->chattime = $this->apply_date_offset($data->chattime); 00056 $data->timemodified = $this->apply_date_offset($data->timemodified); 00057 00058 // insert the chat record 00059 $newitemid = $DB->insert_record('chat', $data); 00060 // immediately after inserting "activity" record, call this 00061 $this->apply_activity_instance($newitemid); 00062 } 00063 00064 protected function process_chat_message($data) { 00065 global $DB; 00066 00067 $data = (object)$data; 00068 $oldid = $data->id; 00069 $data->chatid = $this->get_new_parentid('chat'); 00070 $data->userid = $this->get_mappingid('user', $data->userid); 00071 $data->groupid = $this->get_mappingid('group', $data->groupid); 00072 $data->message = $data->message_text; 00073 $data->timestamp = $this->apply_date_offset($data->timestamp); 00074 00075 $newitemid = $DB->insert_record('chat_messages', $data); 00076 $this->set_mapping('chat_message', $oldid, $newitemid); // because of decode 00077 } 00078 00079 protected function after_execute() { 00080 // Add chat related files, no need to match by itemname (just internally handled context) 00081 $this->add_related_files('mod_chat', 'intro', null); 00082 } 00083 }