Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * @package    workshopform_rubric
20
 * @copyright  2010 onwards David Mudrak <david@moodle.com>
21
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
 
24
defined('MOODLE_INTERNAL') || die();
25
 
26
/**
27
 * restore subplugin class that provides the necessary information
28
 * needed to restore one workshopform_rubric subplugin.
29
 */
30
class restore_workshopform_rubric_subplugin extends restore_subplugin {
31
 
32
    ////////////////////////////////////////////////////////////////////////////
33
    // mappings of XML paths to the processable methods
34
    ////////////////////////////////////////////////////////////////////////////
35
 
36
    /**
37
     * Returns the paths to be handled by the subplugin at workshop level
38
     */
39
    protected function define_workshop_subplugin_structure() {
40
 
41
        $paths = array();
42
 
43
        $elename = $this->get_namefor('config');
44
        $elepath = $this->get_pathfor('/workshopform_rubric_config');
45
        $paths[] = new restore_path_element($elename, $elepath);
46
 
47
        $elename = $this->get_namefor('dimension');
48
        $elepath = $this->get_pathfor('/workshopform_rubric_dimension');
49
        $paths[] = new restore_path_element($elename, $elepath);
50
 
51
        $elename = $this->get_namefor('level');
52
        $elepath = $this->get_pathfor('/workshopform_rubric_dimension/workshopform_rubric_level');
53
        $paths[] = new restore_path_element($elename, $elepath);
54
 
55
        return $paths; // And we return the interesting paths
56
    }
57
 
58
    /**
59
     * Returns the paths to be handled by the subplugin at referenceassessment level
60
     */
61
    protected function define_referenceassessment_subplugin_structure() {
62
 
63
        $paths = array();
64
 
65
        $elename = $this->get_namefor('referencegrade');
66
        $elepath = $this->get_pathfor('/workshopform_rubric_referencegrade'); // we used get_recommended_name() so this works
67
        $paths[] = new restore_path_element($elename, $elepath);
68
 
69
        return $paths; // And we return the interesting paths
70
    }
71
 
72
    /**
73
     * Returns the paths to be handled by the subplugin at exampleassessment level
74
     */
75
    protected function define_exampleassessment_subplugin_structure() {
76
 
77
        $paths = array();
78
 
79
        $elename = $this->get_namefor('examplegrade');
80
        $elepath = $this->get_pathfor('/workshopform_rubric_examplegrade'); // we used get_recommended_name() so this works
81
        $paths[] = new restore_path_element($elename, $elepath);
82
 
83
        return $paths; // And we return the interesting paths
84
    }
85
 
86
    /**
87
     * Returns the paths to be handled by the subplugin at assessment level
88
     */
89
    protected function define_assessment_subplugin_structure() {
90
 
91
        $paths = array();
92
 
93
        $elename = $this->get_namefor('grade');
94
        $elepath = $this->get_pathfor('/workshopform_rubric_grade'); // we used get_recommended_name() so this works
95
        $paths[] = new restore_path_element($elename, $elepath);
96
 
97
        return $paths; // And we return the interesting paths
98
    }
99
 
100
    ////////////////////////////////////////////////////////////////////////////
101
    // defined path elements are dispatched to the following methods
102
    ////////////////////////////////////////////////////////////////////////////
103
 
104
    /**
105
     * Processes the workshopform_rubric_map element
106
     */
107
    public function process_workshopform_rubric_config($data) {
108
        global $DB;
109
 
110
        $data = (object)$data;
111
        $data->workshopid = $this->get_new_parentid('workshop');
112
        $DB->insert_record('workshopform_rubric_config', $data);
113
    }
114
 
115
    /**
116
     * Processes the workshopform_rubric_dimension element
117
     */
118
    public function process_workshopform_rubric_dimension($data) {
119
        global $DB;
120
 
121
        $data = (object)$data;
122
        $oldid = $data->id;
123
 
124
        $data->workshopid = $this->get_new_parentid('workshop');
125
 
126
        $newitemid = $DB->insert_record('workshopform_rubric', $data);
127
        $this->set_mapping($this->get_namefor('dimension'), $oldid, $newitemid, true);
128
 
129
        // Process files for this workshopform_rubric->id only
130
        $this->add_related_files('workshopform_rubric', 'description', $this->get_namefor('dimension'), null, $oldid);
131
    }
132
 
133
    /**
134
     * Processes the workshopform_rubric_level element
135
     */
136
    public function process_workshopform_rubric_level($data) {
137
        global $DB;
138
 
139
        $data = (object)$data;
140
        $data->dimensionid = $this->get_new_parentid($this->get_namefor('dimension'));
141
        $DB->insert_record('workshopform_rubric_levels', $data);
142
    }
143
 
144
    /**
145
     * Processes the workshopform_rubric_referencegrade element
146
     */
147
    public function process_workshopform_rubric_referencegrade($data) {
148
        $this->process_dimension_grades_structure('workshop_referenceassessment', $data);
149
    }
150
 
151
    /**
152
     * Processes the workshopform_rubric_examplegrade element
153
     */
154
    public function process_workshopform_rubric_examplegrade($data) {
155
        $this->process_dimension_grades_structure('workshop_exampleassessment', $data);
156
    }
157
 
158
    /**
159
     * Processes the workshopform_rubric_grade element
160
     */
161
    public function process_workshopform_rubric_grade($data) {
162
        $this->process_dimension_grades_structure('workshop_assessment', $data);
163
    }
164
 
165
    ////////////////////////////////////////////////////////////////////////////
166
    // internal private methods
167
    ////////////////////////////////////////////////////////////////////////////
168
 
169
    /**
170
     * Process the dimension grades linked with the given type of assessment
171
     *
172
     * Populates the workshop_grades table with new records mapped to the restored
173
     * instances of assessments.
174
     *
175
     * @param mixed $elementname the name of the assessment element
176
     * @param array $data parsed xml data
177
     */
178
    private function process_dimension_grades_structure($elementname, $data) {
179
        global $DB;
180
 
181
        $data = (object)$data;
182
        $oldid = $data->id;
183
 
184
        $data->assessmentid = $this->get_new_parentid($elementname);
185
        $data->strategy = 'rubric';
186
        $data->dimensionid = $this->get_mappingid($this->get_namefor('dimension'), $data->dimensionid);
187
 
188
        $DB->insert_record('workshop_grades', $data);
189
    }
190
}