Commit | Line | Data |
---|---|---|
9b553d47 DM |
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 | * Support for backup API | |
20 | * | |
21 | * @package gradingform | |
22 | * @subpackage rubric | |
23 | * @copyright 2011 David Mudrak <david@moodle.com> | |
24 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
25 | */ | |
26 | ||
27 | defined('MOODLE_INTERNAL') || die(); | |
28 | ||
29 | /** | |
30 | * Defines rubric backup structures | |
31 | */ | |
32 | class backup_gradingform_rubric_plugin extends backup_gradingform_plugin { | |
33 | ||
34 | /** | |
35 | * Declares rubric structures to append to the grading form definition | |
36 | */ | |
37 | protected function define_definition_plugin_structure() { | |
38 | ||
39 | // Append data only if the grand-parent element has 'method' set to 'rubric' | |
40 | $plugin = $this->get_plugin_element(null, '../../method', 'rubric'); | |
41 | ||
42 | // Create a visible container for our data | |
43 | $pluginwrapper = new backup_nested_element($this->get_recommended_name()); | |
44 | ||
45 | // Connect our visible container to the parent | |
46 | $plugin->add_child($pluginwrapper); | |
47 | ||
48 | // Define our elements | |
49 | ||
50 | $criteria = new backup_nested_element('criteria'); | |
51 | ||
52 | $criterion = new backup_nested_element('criterion', array('id'), array( | |
53 | 'sortorder', 'description', 'descriptionformat')); | |
54 | ||
55 | $levels = new backup_nested_element('levels'); | |
56 | ||
57 | $level = new backup_nested_element('level', array('id'), array( | |
58 | 'score', 'definition', 'definitionformat')); | |
59 | ||
60 | // Build elements hierarchy | |
61 | ||
62 | $pluginwrapper->add_child($criteria); | |
63 | $criteria->add_child($criterion); | |
64 | $criterion->add_child($levels); | |
65 | $levels->add_child($level); | |
66 | ||
67 | // Set sources to populate the data | |
68 | ||
69 | $criterion->set_source_table('gradingform_rubric_criteria', | |
71ab436a | 70 | array('definitionid' => backup::VAR_PARENTID)); |
9b553d47 DM |
71 | |
72 | $level->set_source_table('gradingform_rubric_levels', | |
73 | array('criterionid' => backup::VAR_PARENTID)); | |
74 | ||
75 | // no need to annotate ids or files yet (one day when criterion definition supports | |
76 | // embedded files, they must be annotated here) | |
77 | ||
78 | return $plugin; | |
79 | } | |
80 | ||
81 | /** | |
82 | * Declares rubric structures to append to the grading form instances | |
83 | */ | |
84 | protected function define_instance_plugin_structure() { | |
85 | ||
86 | // Append data only if the ancestor 'definition' element has 'method' set to 'rubric' | |
87 | $plugin = $this->get_plugin_element(null, '../../../../method', 'rubric'); | |
88 | ||
89 | // Create a visible container for our data | |
90 | $pluginwrapper = new backup_nested_element($this->get_recommended_name()); | |
91 | ||
92 | // Connect our visible container to the parent | |
93 | $plugin->add_child($pluginwrapper); | |
94 | ||
95 | // Define our elements | |
96 | ||
97 | $fillings = new backup_nested_element('fillings'); | |
98 | ||
99 | $filling = new backup_nested_element('filling', array('id'), array( | |
100 | 'criterionid', 'levelid', 'remark', 'remarkformat')); | |
101 | ||
102 | // Build elements hierarchy | |
103 | ||
104 | $pluginwrapper->add_child($fillings); | |
105 | $fillings->add_child($filling); | |
106 | ||
107 | // Set sources to populate the data | |
108 | ||
109 | $filling->set_source_table('gradingform_rubric_fillings', | |
6f07a6a2 | 110 | array('instanceid' => backup::VAR_PARENTID)); |
9b553d47 DM |
111 | |
112 | // no need to annotate ids or files yet (one day when remark field supports | |
113 | // embedded fileds, they must be annotated here) | |
114 | ||
115 | return $plugin; | |
116 | } | |
117 | } |