|
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_glossary_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('glossary', '/activity/glossary'); 00040 $paths[] = new restore_path_element('glossary_category', '/activity/glossary/categories/category'); 00041 if ($userinfo) { 00042 $paths[] = new restore_path_element('glossary_entry', '/activity/glossary/entries/entry'); 00043 $paths[] = new restore_path_element('glossary_alias', '/activity/glossary/entries/entry/aliases/alias'); 00044 $paths[] = new restore_path_element('glossary_rating', '/activity/glossary/entries/entry/ratings/rating'); 00045 $paths[] = new restore_path_element('glossary_category_entry', 00046 '/activity/glossary/categories/category/category_entries/category_entry'); 00047 } 00048 00049 // Return the paths wrapped into standard activity structure 00050 return $this->prepare_activity_structure($paths); 00051 } 00052 00053 protected function process_glossary($data) { 00054 global $DB; 00055 00056 $data = (object)$data; 00057 $oldid = $data->id; 00058 $data->course = $this->get_courseid(); 00059 00060 $data->assesstimestart = $this->apply_date_offset($data->assesstimestart); 00061 $data->assesstimefinish = $this->apply_date_offset($data->assesstimefinish); 00062 if ($data->scale < 0) { // scale found, get mapping 00063 $data->scale = -($this->get_mappingid('scale', abs($data->scale))); 00064 } 00065 $formats = get_list_of_plugins('mod/glossary/formats'); // Check format 00066 if (!in_array($data->displayformat, $formats)) { 00067 $data->displayformat = 'dictionary'; 00068 } 00069 if (!empty($data->mainglossary) and $data->mainglossary == 1 and 00070 $DB->record_exists('glossary', array('mainglossary' => 1, 'course' => $this->get_courseid()))) { 00071 // Only allow one main glossary in the course 00072 $data->mainglossary = 0; 00073 } 00074 00075 // insert the glossary record 00076 $newitemid = $DB->insert_record('glossary', $data); 00077 $this->apply_activity_instance($newitemid); 00078 } 00079 00080 protected function process_glossary_entry($data) { 00081 global $DB; 00082 00083 $data = (object)$data; 00084 $oldid = $data->id; 00085 00086 $data->glossaryid = $this->get_new_parentid('glossary'); 00087 $data->userid = $this->get_mappingid('user', $data->userid); 00088 $data->sourceglossaryid = $this->get_mappingid('glossary', $data->sourceglossaryid); 00089 00090 $data->timecreated = $this->apply_date_offset($data->timecreated); 00091 $data->timemodified = $this->apply_date_offset($data->timemodified); 00092 00093 // insert the entry record 00094 $newitemid = $DB->insert_record('glossary_entries', $data); 00095 $this->set_mapping('glossary_entry', $oldid, $newitemid, true); // childs and files by itemname 00096 } 00097 00098 protected function process_glossary_alias($data) { 00099 global $DB; 00100 00101 $data = (object)$data; 00102 $oldid = $data->id; 00103 00104 $data->entryid = $this->get_new_parentid('glossary_entry'); 00105 $data->alias = $data->alias_text; 00106 $newitemid = $DB->insert_record('glossary_alias', $data); 00107 } 00108 00109 protected function process_glossary_rating($data) { 00110 global $DB; 00111 00112 $data = (object)$data; 00113 00114 // Cannot use ratings API, cause, it's missing the ability to specify times (modified/created) 00115 $data->contextid = $this->task->get_contextid(); 00116 $data->itemid = $this->get_new_parentid('glossary_entry'); 00117 if ($data->scaleid < 0) { // scale found, get mapping 00118 $data->scaleid = -($this->get_mappingid('scale', abs($data->scaleid))); 00119 } 00120 $data->rating = $data->value; 00121 $data->userid = $this->get_mappingid('user', $data->userid); 00122 $data->timecreated = $this->apply_date_offset($data->timecreated); 00123 $data->timemodified = $this->apply_date_offset($data->timemodified); 00124 00125 // Make sure that we have both component and ratingarea set. These were added in 2.1. 00126 // Prior to that all ratings were for entries so we know what to set them too. 00127 if (empty($data->component)) { 00128 $data->component = 'mod_glossary'; 00129 } 00130 if (empty($data->ratingarea)) { 00131 $data->ratingarea = 'entry'; 00132 } 00133 00134 $newitemid = $DB->insert_record('rating', $data); 00135 } 00136 00137 protected function process_glossary_category($data) { 00138 global $DB; 00139 00140 $data = (object)$data; 00141 $oldid = $data->id; 00142 00143 $data->glossaryid = $this->get_new_parentid('glossary'); 00144 $newitemid = $DB->insert_record('glossary_categories', $data); 00145 $this->set_mapping('glossary_category', $oldid, $newitemid); 00146 } 00147 00148 protected function process_glossary_category_entry($data) { 00149 global $DB; 00150 00151 $data = (object)$data; 00152 $oldid = $data->id; 00153 00154 $data->categoryid = $this->get_new_parentid('glossary_category'); 00155 $data->entryid = $this->get_mappingid('glossary_entry', $data->entryid); 00156 $newitemid = $DB->insert_record('glossary_entries_categories', $data); 00157 } 00158 00159 protected function after_execute() { 00160 // Add glossary related files, no need to match by itemname (just internally handled context) 00161 $this->add_related_files('mod_glossary', 'intro', null); 00162 // Add entries related files, matching by itemname (glossary_entry) 00163 $this->add_related_files('mod_glossary', 'entry', 'glossary_entry'); 00164 $this->add_related_files('mod_glossary', 'attachment', 'glossary_entry'); 00165 } 00166 }