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/>.
19 * Support for backup API
21 * @package gradingform
23 * @copyright 2011 David Mudrak <david@moodle.com>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 defined('MOODLE_INTERNAL') || die();
30 * Defines rubric backup structures
32 class backup_gradingform_rubric_plugin extends backup_gradingform_plugin {
35 * Declares rubric structures to append to the grading form definition
37 protected function define_definition_plugin_structure() {
39 // Append data only if the grand-parent element has 'method' set to 'rubric'
40 $plugin = $this->get_plugin_element(null, '../../method', 'rubric');
42 // Create a visible container for our data
43 $pluginwrapper = new backup_nested_element($this->get_recommended_name());
45 // Connect our visible container to the parent
46 $plugin->add_child($pluginwrapper);
48 // Define our elements
50 $criteria = new backup_nested_element('criteria');
52 $criterion = new backup_nested_element('criterion', array('id'), array(
53 'sortorder', 'description', 'descriptionformat'));
55 $levels = new backup_nested_element('levels');
57 $level = new backup_nested_element('level', array('id'), array(
58 'score', 'definition', 'definitionformat'));
60 // Build elements hierarchy
62 $pluginwrapper->add_child($criteria);
63 $criteria->add_child($criterion);
64 $criterion->add_child($levels);
65 $levels->add_child($level);
67 // Set sources to populate the data
69 $criterion->set_source_table('gradingform_rubric_criteria',
70 array('definitionid' => backup::VAR_PARENTID));
72 $level->set_source_table('gradingform_rubric_levels',
73 array('criterionid' => backup::VAR_PARENTID));
75 // no need to annotate ids or files yet (one day when criterion definition supports
76 // embedded files, they must be annotated here)
82 * Declares rubric structures to append to the grading form instances
84 protected function define_instance_plugin_structure() {
86 // Append data only if the ancestor 'definition' element has 'method' set to 'rubric'
87 $plugin = $this->get_plugin_element(null, '../../../../method', 'rubric');
89 // Create a visible container for our data
90 $pluginwrapper = new backup_nested_element($this->get_recommended_name());
92 // Connect our visible container to the parent
93 $plugin->add_child($pluginwrapper);
95 // Define our elements
97 $fillings = new backup_nested_element('fillings');
99 $filling = new backup_nested_element('filling', array('id'), array(
100 'criterionid', 'levelid', 'remark', 'remarkformat'));
102 // Build elements hierarchy
104 $pluginwrapper->add_child($fillings);
105 $fillings->add_child($filling);
107 // Set sources to populate the data
109 $filling->set_source_table('gradingform_rubric_fillings',
110 array('forminstanceid' => backup::VAR_PARENTID));
112 // no need to annotate ids or files yet (one day when remark field supports
113 // embedded fileds, they must be annotated here)