MDL-20442 - now you can switch to ignore empty submits
[moodle.git] / mod / feedback / backup / moodle2 / backup_feedback_stepslib.php
1 <?php
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/>.
18 /**
19  * @package moodlecore
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  */
25 /**
26  * Define all the backup steps that will be used by the backup_feedback_activity_task
27  */
29 /**
30  * Define the complete feedback structure for backup, with file and id annotations
31  */
32 class backup_feedback_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         $feedback = new backup_nested_element('feedback', array('id'), array(
41                                                 'name',
42                                                 'intro',
43                                                 'introformat',
44                                                 'anonymous',
45                                                 'email_notification',
46                                                 'multiple_submit',
47                                                 'autonumbering',
48                                                 'site_after_submit',
49                                                 'page_after_submit',
50                                                 'page_after_submitformat',
51                                                 'publish_stats',
52                                                 'timeopen',
53                                                 'timeclose',
54                                                 'timemodified'));
57         $completeds = new backup_nested_element('completeds');
59         $completed = new backup_nested_element('completed', array('id'), array(
60                                                 'userid',
61                                                 'timemodified',
62                                                 'random_response',
63                                                 'anonymous_response'));
65         $items = new backup_nested_element('items');
67         $item = new backup_nested_element('item', array('id'), array(
68                                                 'template',
69                                                 'name',
70                                                 'label',
71                                                 'presentation',
72                                                 'typ',
73                                                 'hasvalue',
74                                                 'position',
75                                                 'required',
76                                                 'options'));
78         $trackings = new backup_nested_element('trackings');
80         $tracking = new backup_nested_element('tracking', array('id'), array(
81                                                 'userid',
82                                                 'completed'));
84         $values = new backup_nested_element('values');
86         $value = new backup_nested_element('value', array('id'), array(
87                                                 'item',
88                                                 'template',
89                                                 'completed',
90                                                 'value'));
93         // Build the tree
94         $feedback->add_child($completeds);
95         $completeds->add_child($completed);
97         $completed->add_child($values);
98         $values->add_child($value);
100         $feedback->add_child($items);
101         $items->add_child($item);
103         $feedback->add_child($trackings);
104         $trackings->add_child($tracking);
106         // Define sources
107         $feedback->set_source_table('feedback', array('id' => backup::VAR_ACTIVITYID));
109         // All these source definitions only happen if we are including user info
110         if ($userinfo) {
111             $completed->set_source_sql('
112                 SELECT *
113                   FROM {feedback_completed}
114                  WHERE feedback = ?',
115                 array(backup::VAR_PARENTID));
117             $item->set_source_table('feedback_item', array('feedback' => backup::VAR_PARENTID));
119             $value->set_source_table('feedback_value', array('completed' => backup::VAR_PARENTID));
121             $tracking->set_source_table('feedback_tracking', array('feedback' => backup::VAR_PARENTID));
122         }
124         // Define id annotations
126         $completed->annotate_ids('user', 'userid');
128         $tracking->annotate_ids('user', 'userid');
130         // Define file annotations
132         $feedback->annotate_files(array('feedback_intro'), null); // This file area hasn't itemid
134         $item->annotate_files(array('feedback_item'), 'id');
136         // Return the root element (feedback), wrapped into standard activity structure
137         return $this->prepare_activity_structure($feedback);
138     }