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_data_activity_task
30 * Define the complete data structure for backup, with file and id annotations
32 class backup_data_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 $data = new backup_nested_element('data', array('id'), array(
41 'name', 'intro', 'introformat', 'comments',
42 'timeavailablefrom', 'timeavailableto', 'timeviewfrom', 'timeviewto',
43 'requiredentries', 'requiredentriestoview', 'maxentries', 'rssarticles',
44 'singletemplate', 'listtemplate', 'listtemplateheader', 'listtemplatefooter',
45 'addtemplate', 'rsstemplate', 'rsstitletemplate', 'csstemplate',
46 'jstemplate', 'asearchtemplate', 'approval', 'manageapproved', 'scale',
47 'assessed', 'assesstimestart', 'assesstimefinish', 'defaultsort',
48 'defaultsortdir', 'editany', 'notification'));
50 $fields = new backup_nested_element('fields');
52 $field = new backup_nested_element('field', array('id'), array(
53 'type', 'name', 'description', 'required', 'param1', 'param2',
54 'param3', 'param4', 'param5', 'param6',
55 'param7', 'param8', 'param9', 'param10'));
57 $records = new backup_nested_element('records');
59 $record = new backup_nested_element('record', array('id'), array(
60 'userid', 'groupid', 'timecreated', 'timemodified',
63 $contents = new backup_nested_element('contents');
65 $content = new backup_nested_element('content', array('id'), array(
66 'fieldid', 'content', 'content1', 'content2',
67 'content3', 'content4'));
69 $ratings = new backup_nested_element('ratings');
71 $rating = new backup_nested_element('rating', array('id'), array(
72 'component', 'ratingarea', 'scaleid', 'value', 'userid', 'timecreated', 'timemodified'));
75 $data->add_child($fields);
76 $fields->add_child($field);
78 $data->add_child($records);
79 $records->add_child($record);
81 $record->add_child($contents);
82 $contents->add_child($content);
84 $record->add_child($ratings);
85 $ratings->add_child($rating);
88 $data->set_source_table('data', array('id' => backup::VAR_ACTIVITYID));
90 $field->set_source_sql('
94 array(backup::VAR_PARENTID));
96 // All the rest of elements only happen if we are including user info
98 $record->set_source_table('data_records', array('dataid' => backup::VAR_PARENTID));
100 $content->set_source_table('data_content', array('recordid' => backup::VAR_PARENTID));
102 $rating->set_source_table('rating', array('contextid' => backup::VAR_CONTEXTID,
103 'itemid' => backup::VAR_PARENTID,
104 'component' => backup_helper::is_sqlparam('mod_data'),
105 'ratingarea' => backup_helper::is_sqlparam('entry')));
106 $rating->set_source_alias('rating', 'value');
109 // Define id annotations
110 $data->annotate_ids('scale', 'scale');
112 $record->annotate_ids('user', 'userid');
113 $record->annotate_ids('group', 'groupid');
115 $rating->annotate_ids('scale', 'scaleid');
116 $rating->annotate_ids('user', 'userid');
118 // Define file annotations
119 $data->annotate_files('mod_data', 'intro', null); // This file area hasn't itemid
120 $content->annotate_files('mod_data', 'content', 'id'); // By content->id
122 // Return the root element (data), wrapped into standard activity structure
123 return $this->prepare_activity_structure($data);