MDL-29108 Advanced grading - renaming DB field forminstanceid to instanceid
[moodle.git] / grade / grading / form / rubric / backup / moodle2 / restore_gradingform_rubric_plugin.class.php
CommitLineData
37065c2e
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 restore 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
27defined('MOODLE_INTERNAL') || die();
28
29/**
30 * Restores the rubric specific data from grading.xml file
31 */
32class restore_gradingform_rubric_plugin extends restore_gradingform_plugin {
33
34 /**
35 * Declares the rubric XML paths attached to the form definition element
36 *
37 * @return array of {@link restore_path_element}
38 */
39 protected function define_definition_plugin_structure() {
40
41 $paths = array();
42
43 $paths[] = new restore_path_element('gradingform_rubric_criterion',
44 $this->get_pathfor('/criteria/criterion'));
45
46 $paths[] = new restore_path_element('gradingform_rubric_level',
47 $this->get_pathfor('/criteria/criterion/levels/level'));
48
49 return $paths;
50 }
51
52 /**
53 * Declares the rubric XML paths attached to the form instance element
54 *
55 * @return array of {@link restore_path_element}
56 */
57 protected function define_instance_plugin_structure() {
58
59 $paths = array();
60
61 $paths[] = new restore_path_element('gradinform_rubric_filling',
62 $this->get_pathfor('/fillings/filling'));
63
64 return $paths;
65 }
66
67 /**
68 * Processes criterion element data
69 *
70 * Sets the mapping 'gradingform_rubric_criterion' to be used later by
71 * {@link self::process_gradinform_rubric_filling()}
72 */
73 public function process_gradingform_rubric_criterion($data) {
74 global $DB;
75
76 $data = (object)$data;
77 $oldid = $data->id;
71ab436a 78 $data->definitionid = $this->get_new_parentid('grading_definition');
37065c2e
DM
79
80 $newid = $DB->insert_record('gradingform_rubric_criteria', $data);
81 $this->set_mapping('gradingform_rubric_criterion', $oldid, $newid);
82 }
83
84 /**
85 * Processes level element data
86 *
87 * Sets the mapping 'gradingform_rubric_level' to be used later by
88 * {@link self::process_gradinform_rubric_filling()}
89 */
90 public function process_gradingform_rubric_level($data) {
91 global $DB;
92
93 $data = (object)$data;
94 $oldid = $data->id;
95 $data->criterionid = $this->get_new_parentid('gradingform_rubric_criterion');
96
97 $newid = $DB->insert_record('gradingform_rubric_levels', $data);
98 $this->set_mapping('gradingform_rubric_level', $oldid, $newid);
99 }
100
101 /**
102 * Processes filling element data
103 */
104 public function process_gradinform_rubric_filling($data) {
105 global $DB;
106
107 $data = (object)$data;
6f07a6a2 108 $data->instanceid = $this->get_new_parentid('grading_instance');
37065c2e
DM
109 $data->criterionid = $this->get_mappingid('gradingform_rubric_criterion', $data->criterionid);
110 $data->levelid = $this->get_mappingid('gradingform_rubric_level', $data->levelid);
111
112 $DB->insert_record('gradingform_rubric_fillings', $data);
113 }
114}