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 restore 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 * Restores the rubric specific data from grading.xml file
32 class restore_gradingform_rubric_plugin extends restore_gradingform_plugin {
35 * Declares the rubric XML paths attached to the form definition element
37 * @return array of {@link restore_path_element}
39 protected function define_definition_plugin_structure() {
43 $paths[] = new restore_path_element('gradingform_rubric_criterion',
44 $this->get_pathfor('/criteria/criterion'));
46 $paths[] = new restore_path_element('gradingform_rubric_level',
47 $this->get_pathfor('/criteria/criterion/levels/level'));
53 * Declares the rubric XML paths attached to the form instance element
55 * @return array of {@link restore_path_element}
57 protected function define_instance_plugin_structure() {
61 $paths[] = new restore_path_element('gradinform_rubric_filling',
62 $this->get_pathfor('/fillings/filling'));
68 * Processes criterion element data
70 * Sets the mapping 'gradingform_rubric_criterion' to be used later by
71 * {@link self::process_gradinform_rubric_filling()}
73 public function process_gradingform_rubric_criterion($data) {
76 $data = (object)$data;
78 $data->definitionid = $this->get_new_parentid('grading_definition');
80 $newid = $DB->insert_record('gradingform_rubric_criteria', $data);
81 $this->set_mapping('gradingform_rubric_criterion', $oldid, $newid);
85 * Processes level element data
87 * Sets the mapping 'gradingform_rubric_level' to be used later by
88 * {@link self::process_gradinform_rubric_filling()}
90 public function process_gradingform_rubric_level($data) {
93 $data = (object)$data;
95 $data->criterionid = $this->get_new_parentid('gradingform_rubric_criterion');
97 $newid = $DB->insert_record('gradingform_rubric_levels', $data);
98 $this->set_mapping('gradingform_rubric_level', $oldid, $newid);
102 * Processes filling element data
104 public function process_gradinform_rubric_filling($data) {
107 $data = (object)$data;
108 $data->instanceid = $this->get_new_parentid('grading_instance');
109 $data->criterionid = $this->get_mappingid('gradingform_rubric_criterion', $data->criterionid);
110 $data->levelid = $this->get_mappingid('gradingform_rubric_level', $data->levelid);
112 $DB->insert_record('gradingform_rubric_fillings', $data);