1 <?php 2 3 // This file is part of Moodle - http://moodle.org/ 4 // 5 // Moodle is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // Moodle is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 17 18 /** 19 * @package mod_glossary 20 * @subpackage backup-moodle2 21 * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com} 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 /** 26 * Define all the backup steps that will be used by the backup_glossary_activity_task 27 */ 28 29 /** 30 * Define the complete glossary structure for backup, with file and id annotations 31 */ 32 class backup_glossary_activity_structure_step extends backup_activity_structure_step { 33 34 protected function define_structure() { 35 36 // To know if we are including userinfo 37 $userinfo = $this->get_setting_value('userinfo'); 38 39 // Define each element separated 40 $glossary = new backup_nested_element('glossary', array('id'), array( 41 'name', 'intro', 'introformat', 'allowduplicatedentries', 'displayformat', 42 'mainglossary', 'showspecial', 'showalphabet', 'showall', 43 'allowcomments', 'allowprintview', 'usedynalink', 'defaultapproval', 44 'globalglossary', 'entbypage', 'editalways', 'rsstype', 45 'rssarticles', 'assessed', 'assesstimestart', 'assesstimefinish', 46 'scale', 'timecreated', 'timemodified', 'completionentries')); 47 48 $entries = new backup_nested_element('entries'); 49 50 $entry = new backup_nested_element('entry', array('id'), array( 51 'userid', 'concept', 'definition', 'definitionformat', 52 'definitiontrust', 'attachment', 'timecreated', 'timemodified', 53 'teacherentry', 'sourceglossaryid', 'usedynalink', 'casesensitive', 54 'fullmatch', 'approved')); 55 56 $tags = new backup_nested_element('entriestags'); 57 $tag = new backup_nested_element('tag', array('id'), array('itemid', 'rawname')); 58 59 $aliases = new backup_nested_element('aliases'); 60 61 $alias = new backup_nested_element('alias', array('id'), array( 62 'alias_text')); 63 64 $ratings = new backup_nested_element('ratings'); 65 66 $rating = new backup_nested_element('rating', array('id'), array( 67 'component', 'ratingarea', 'scaleid', 'value', 'userid', 'timecreated', 'timemodified')); 68 69 $categories = new backup_nested_element('categories'); 70 71 $category = new backup_nested_element('category', array('id'), array( 72 'name', 'usedynalink')); 73 74 $categoryentries = new backup_nested_element('category_entries'); 75 76 $categoryentry = new backup_nested_element('category_entry', array('id'), array( 77 'entryid')); 78 79 // Build the tree 80 $glossary->add_child($entries); 81 $entries->add_child($entry); 82 83 $glossary->add_child($tags); 84 $tags->add_child($tag); 85 86 $entry->add_child($aliases); 87 $aliases->add_child($alias); 88 89 $entry->add_child($ratings); 90 $ratings->add_child($rating); 91 92 $glossary->add_child($categories); 93 $categories->add_child($category); 94 95 $category->add_child($categoryentries); 96 $categoryentries->add_child($categoryentry); 97 98 // Define sources 99 $glossary->set_source_table('glossary', array('id' => backup::VAR_ACTIVITYID)); 100 101 $category->set_source_table('glossary_categories', array('glossaryid' => backup::VAR_PARENTID)); 102 103 // All the rest of elements only happen if we are including user info 104 if ($userinfo) { 105 $entry->set_source_table('glossary_entries', array('glossaryid' => backup::VAR_PARENTID)); 106 107 $alias->set_source_table('glossary_alias', array('entryid' => backup::VAR_PARENTID)); 108 $alias->set_source_alias('alias', 'alias_text'); 109 110 $rating->set_source_table('rating', array('contextid' => backup::VAR_CONTEXTID, 111 'itemid' => backup::VAR_PARENTID, 112 'component' => backup_helper::is_sqlparam('mod_glossary'), 113 'ratingarea' => backup_helper::is_sqlparam('entry'))); 114 $rating->set_source_alias('rating', 'value'); 115 116 $categoryentry->set_source_table('glossary_entries_categories', array('categoryid' => backup::VAR_PARENTID)); 117 118 if (core_tag_tag::is_enabled('mod_glossary', 'glossary_entries')) { 119 $tag->set_source_sql('SELECT t.id, ti.itemid, t.rawname 120 FROM {tag} t 121 JOIN {tag_instance} ti ON ti.tagid = t.id 122 WHERE ti.itemtype = ? 123 AND ti.component = ? 124 AND ti.contextid = ?', array( 125 backup_helper::is_sqlparam('glossary_entries'), 126 backup_helper::is_sqlparam('mod_glossary'), 127 backup::VAR_CONTEXTID)); 128 } 129 } 130 131 // Define id annotations 132 $glossary->annotate_ids('scale', 'scale'); 133 134 $entry->annotate_ids('user', 'userid'); 135 136 $rating->annotate_ids('scale', 'scaleid'); 137 138 $rating->annotate_ids('user', 'userid'); 139 140 // Define file annotations 141 $glossary->annotate_files('mod_glossary', 'intro', null); // This file area hasn't itemid 142 143 $entry->annotate_files('mod_glossary', 'entry', 'id'); 144 $entry->annotate_files('mod_glossary', 'attachment', 'id'); 145 146 // Return the root element (glossary), wrapped into standard activity structure 147 return $this->prepare_activity_structure($glossary); 148 } 149 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body