3 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
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
26 * Define all the backup steps that will be used by the backup_glossary_activity_task
30 * Define the complete glossary structure for backup, with file and id annotations
32 class backup_glossary_activity_structure_step extends backup_activity_structure_step {
34 protected function define_structure() {
36 // To know if we are including userinfo
37 $userinfo = $this->get_setting_value('userinfo');
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'));
48 $entries = new backup_nested_element('entries');
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'));
56 $aliases = new backup_nested_element('aliases');
58 $alias = new backup_nested_element('alias', array('id'), array(
61 $ratings = new backup_nested_element('ratings');
63 $rating = new backup_nested_element('rating', array('id'), array(
64 'component', 'ratingarea', 'scaleid', 'value', 'userid', 'timecreated', 'timemodified'));
66 $categories = new backup_nested_element('categories');
68 $category = new backup_nested_element('category', array('id'), array(
69 'name', 'usedynalink'));
71 $categoryentries = new backup_nested_element('category_entries');
73 $categoryentry = new backup_nested_element('category_entry', array('id'), array(
77 $glossary->add_child($entries);
78 $entries->add_child($entry);
80 $entry->add_child($aliases);
81 $aliases->add_child($alias);
83 $entry->add_child($ratings);
84 $ratings->add_child($rating);
86 $glossary->add_child($categories);
87 $categories->add_child($category);
89 $category->add_child($categoryentries);
90 $categoryentries->add_child($categoryentry);
93 $glossary->set_source_table('glossary', array('id' => backup::VAR_ACTIVITYID));
95 $category->set_source_table('glossary_categories', array('glossaryid' => backup::VAR_PARENTID));
97 // All the rest of elements only happen if we are including user info
99 $entry->set_source_table('glossary_entries', array('glossaryid' => backup::VAR_PARENTID));
101 $alias->set_source_table('glossary_alias', array('entryid' => backup::VAR_PARENTID));
102 $alias->set_source_alias('alias', 'alias_text');
104 $rating->set_source_table('rating', array('contextid' => backup::VAR_CONTEXTID,
105 'itemid' => backup::VAR_PARENTID,
106 'component' => 'mod_glossary',
107 'ratingarea' => 'entry'));
108 $rating->set_source_alias('rating', 'value');
110 $categoryentry->set_source_table('glossary_entries_categories', array('categoryid' => backup::VAR_PARENTID));
113 // Define id annotations
114 $glossary->annotate_ids('scale', 'scale');
116 $entry->annotate_ids('user', 'userid');
118 $rating->annotate_ids('scale', 'scaleid');
120 $rating->annotate_ids('user', 'userid');
122 // Define file annotations
123 $glossary->annotate_files('mod_glossary', 'intro', null); // This file area hasn't itemid
125 $entry->annotate_files('mod_glossary', 'entry', 'id');
126 $entry->annotate_files('mod_glossary', 'attachment', 'id');
128 // Return the root element (glossary), wrapped into standard activity structure
129 return $this->prepare_activity_structure($glossary);