MDL-30998: updated docblocks for advanced grading
[moodle.git] / grade / grading / form / rubric / backup / moodle2 / backup_gradingform_rubric_plugin.class.php
CommitLineData
9b553d47 1<?php
9b553d47
DM
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Support for backup API
19 *
d22e9e32 20 * @package gradingform_rubric
9b553d47
DM
21 * @copyright 2011 David Mudrak <david@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
26
27/**
28 * Defines rubric backup structures
d22e9e32
MG
29 *
30 * @copyright 2011 David Mudrak <david@moodle.com>
31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
9b553d47
DM
32 */
33class backup_gradingform_rubric_plugin extends backup_gradingform_plugin {
34
35 /**
36 * Declares rubric structures to append to the grading form definition
37 */
38 protected function define_definition_plugin_structure() {
39
40 // Append data only if the grand-parent element has 'method' set to 'rubric'
41 $plugin = $this->get_plugin_element(null, '../../method', 'rubric');
42
43 // Create a visible container for our data
44 $pluginwrapper = new backup_nested_element($this->get_recommended_name());
45
46 // Connect our visible container to the parent
47 $plugin->add_child($pluginwrapper);
48
49 // Define our elements
50
51 $criteria = new backup_nested_element('criteria');
52
53 $criterion = new backup_nested_element('criterion', array('id'), array(
54 'sortorder', 'description', 'descriptionformat'));
55
56 $levels = new backup_nested_element('levels');
57
58 $level = new backup_nested_element('level', array('id'), array(
59 'score', 'definition', 'definitionformat'));
60
61 // Build elements hierarchy
62
63 $pluginwrapper->add_child($criteria);
64 $criteria->add_child($criterion);
65 $criterion->add_child($levels);
66 $levels->add_child($level);
67
68 // Set sources to populate the data
69
70 $criterion->set_source_table('gradingform_rubric_criteria',
71ab436a 71 array('definitionid' => backup::VAR_PARENTID));
9b553d47
DM
72
73 $level->set_source_table('gradingform_rubric_levels',
74 array('criterionid' => backup::VAR_PARENTID));
75
76 // no need to annotate ids or files yet (one day when criterion definition supports
77 // embedded files, they must be annotated here)
78
79 return $plugin;
80 }
81
82 /**
83 * Declares rubric structures to append to the grading form instances
84 */
85 protected function define_instance_plugin_structure() {
86
87 // Append data only if the ancestor 'definition' element has 'method' set to 'rubric'
88 $plugin = $this->get_plugin_element(null, '../../../../method', 'rubric');
89
90 // Create a visible container for our data
91 $pluginwrapper = new backup_nested_element($this->get_recommended_name());
92
93 // Connect our visible container to the parent
94 $plugin->add_child($pluginwrapper);
95
96 // Define our elements
97
98 $fillings = new backup_nested_element('fillings');
99
100 $filling = new backup_nested_element('filling', array('id'), array(
101 'criterionid', 'levelid', 'remark', 'remarkformat'));
102
103 // Build elements hierarchy
104
105 $pluginwrapper->add_child($fillings);
106 $fillings->add_child($filling);
107
108 // Set sources to populate the data
109
b4b6fc91
DM
110 // Binding criterionid to ensure it's existence
111 $filling->set_source_sql('SELECT rf.*
112 FROM {gradingform_rubric_fillings} rf
113 JOIN {grading_instances} gi ON gi.id = rf.instanceid
114 JOIN {gradingform_rubric_criteria} rc ON rc.id = rf.criterionid AND gi.definitionid = rc.definitionid
115 WHERE rf.instanceid = :instanceid',
116 array('instanceid' => backup::VAR_PARENTID));
9b553d47
DM
117
118 // no need to annotate ids or files yet (one day when remark field supports
119 // embedded fileds, they must be annotated here)
120
121 return $plugin;
122 }
123}