Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

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