|
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 backup_wiki_activity_structure_step extends backup_activity_structure_step { 00033 00034 protected function define_structure() { 00035 00036 // To know if we are including userinfo 00037 $userinfo = $this->get_setting_value('userinfo'); 00038 00039 // Define each element separated 00040 $wiki = new backup_nested_element('wiki', array('id'), array('name', 'intro', 'introformat', 'timecreated', 'timemodified', 'firstpagetitle', 'wikimode', 'defaultformat', 'forceformat', 'editbegin', 'editend')); 00041 00042 $subwikis = new backup_nested_element('subwikis'); 00043 00044 $subwiki = new backup_nested_element('subwiki', array('id'), array('groupid', 'userid')); 00045 00046 $pages = new backup_nested_element('pages'); 00047 00048 $page = new backup_nested_element('page', array('id'), array('title', 'cachedcontent', 'timecreated', 'timemodified', 'timerendered', 'userid', 'pageviews', 'readonly')); 00049 00050 $synonyms = new backup_nested_element('synonyms'); 00051 00052 $synonym = new backup_nested_element('synonym', array('id'), array('pageid', 'pagesynonym')); 00053 00054 $links = new backup_nested_element('links'); 00055 00056 $link = new backup_nested_element('link', array('id'), array('frompageid', 'topageid', 'tomissingpage')); 00057 00058 $versions = new backup_nested_element('versions'); 00059 00060 $version = new backup_nested_element('version', array('id'), array('content', 'contentformat', 'version', 'timecreated', 'userid')); 00061 00062 $tags = new backup_nested_element('tags'); 00063 00064 $tag = new backup_nested_element('tag', array('id'), array('name', 'rawname')); 00065 00066 // Build the tree 00067 $wiki->add_child($subwikis); 00068 $subwikis->add_child($subwiki); 00069 00070 $subwiki->add_child($pages); 00071 $pages->add_child($page); 00072 00073 $subwiki->add_child($synonyms); 00074 $synonyms->add_child($synonym); 00075 00076 $subwiki->add_child($links); 00077 $links->add_child($link); 00078 00079 $page->add_child($versions); 00080 $versions->add_child($version); 00081 00082 $page->add_child($tags); 00083 $tags->add_child($tag); 00084 00085 // Define sources 00086 $wiki->set_source_table('wiki', array('id' => backup::VAR_ACTIVITYID)); 00087 00088 // All these source definitions only happen if we are including user info 00089 if ($userinfo) { 00090 $subwiki->set_source_sql(' 00091 SELECT * 00092 FROM {wiki_subwikis} 00093 WHERE wikiid = ?', array(backup::VAR_PARENTID)); 00094 00095 $page->set_source_table('wiki_pages', array('subwikiid' => backup::VAR_PARENTID)); 00096 00097 $synonym->set_source_table('wiki_synonyms', array('subwikiid' => backup::VAR_PARENTID)); 00098 00099 $link->set_source_table('wiki_links', array('subwikiid' => backup::VAR_PARENTID)); 00100 00101 $version->set_source_table('wiki_versions', array('pageid' => backup::VAR_PARENTID)); 00102 00103 $tag->set_source_sql('SELECT t.id, t.name, t.rawname 00104 FROM {tag} t 00105 JOIN {tag_instance} ti ON ti.tagid = t.id 00106 WHERE ti.itemtype = ? 00107 AND ti.itemid = ?', array( 00108 backup_helper::is_sqlparam('wiki_pages'), 00109 backup::VAR_PARENTID)); 00110 } 00111 00112 // Define id annotations 00113 $subwiki->annotate_ids('group', 'groupid'); 00114 00115 $subwiki->annotate_ids('user', 'userid'); 00116 00117 $page->annotate_ids('user', 'userid'); 00118 00119 $version->annotate_ids('user', 'userid'); 00120 00121 // Define file annotations 00122 $wiki->annotate_files('mod_wiki', 'intro', null); // This file area hasn't itemid 00123 $page->annotate_files('mod_wiki', 'attachments', 'id'); // This file area hasn't itemid 00124 00125 // Return the root element (wiki), wrapped into standard activity structure 00126 return $this->prepare_activity_structure($wiki); 00127 } 00128 00129 }