MDL-23479 backup - various fixes in feedback backup & restore + delete old code ...
[moodle.git] / mod / feedback / backup / moodle2 / backup_feedback_stepslib.php
CommitLineData
b4d91fcb
AG
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 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 */
24
25/**
26 * Define all the backup steps that will be used by the backup_feedback_activity_task
27 */
28
29/**
30 * Define the complete feedback structure for backup, with file and id annotations
31 */
32class backup_feedback_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 $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'));
55
56
57 $completeds = new backup_nested_element('completeds');
58
59 $completed = new backup_nested_element('completed', array('id'), array(
60 'userid',
61 'timemodified',
62 'random_response',
63 'anonymous_response'));
64
65 $items = new backup_nested_element('items');
66
67 $item = new backup_nested_element('item', array('id'), array(
68 'template',
69 'name',
70 'label',
71 'presentation',
72 'typ',
73 'hasvalue',
74 'position',
6b0b5729
AG
75 'required',
76 'options'));
b4d91fcb
AG
77
78 $trackings = new backup_nested_element('trackings');
79
80 $tracking = new backup_nested_element('tracking', array('id'), array(
81 'userid',
82 'completed'));
83
84 $values = new backup_nested_element('values');
85
86 $value = new backup_nested_element('value', array('id'), array(
87 'item',
88 'template',
89 'completed',
90 'value'));
91
92
93 // Build the tree
d68c337f
EL
94 $feedback->add_child($items);
95 $items->add_child($item);
96
b4d91fcb
AG
97 $feedback->add_child($completeds);
98 $completeds->add_child($completed);
99
100 $completed->add_child($values);
101 $values->add_child($value);
102
b4d91fcb
AG
103 $feedback->add_child($trackings);
104 $trackings->add_child($tracking);
105
106 // Define sources
107 $feedback->set_source_table('feedback', array('id' => backup::VAR_ACTIVITYID));
108
d68c337f
EL
109 $item->set_source_table('feedback_item', array('feedback' => backup::VAR_PARENTID));
110
b4d91fcb
AG
111 // All these source definitions only happen if we are including user info
112 if ($userinfo) {
113 $completed->set_source_sql('
114 SELECT *
115 FROM {feedback_completed}
116 WHERE feedback = ?',
117 array(backup::VAR_PARENTID));
118
b4d91fcb
AG
119 $value->set_source_table('feedback_value', array('completed' => backup::VAR_PARENTID));
120
121 $tracking->set_source_table('feedback_tracking', array('feedback' => backup::VAR_PARENTID));
122 }
123
124 // Define id annotations
125
126 $completed->annotate_ids('user', 'userid');
127
128 $tracking->annotate_ids('user', 'userid');
129
130 // Define file annotations
131
64f93798 132 $feedback->annotate_files('mod_feedback', 'intro', null); // This file area hasn't itemid
b4d91fcb 133
64f93798 134 $item->annotate_files('mod_feedback', 'item', 'id');
b4d91fcb
AG
135
136 // Return the root element (feedback), wrapped into standard activity structure
137 return $this->prepare_activity_structure($feedback);
138 }
139
140}