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_numerrors
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_numerrors subplugin.
29
 */
30
class restore_workshopform_numerrors_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('map');
44
        $elepath = $this->get_pathfor('/workshopform_numerrors_map'); // we used get_recommended_name() so this works
45
        $paths[] = new restore_path_element($elename, $elepath);
46
 
47
        $elename = $this->get_namefor('dimension');
48
        $elepath = $this->get_pathfor('/workshopform_numerrors_dimension'); // we used get_recommended_name() so this works
49
        $paths[] = new restore_path_element($elename, $elepath);
50
 
51
        return $paths; // And we return the interesting paths
52
    }
53
 
54
    /**
55
     * Returns the paths to be handled by the subplugin at referenceassessment level
56
     */
57
    protected function define_referenceassessment_subplugin_structure() {
58
 
59
        $paths = array();
60
 
61
        $elename = $this->get_namefor('referencegrade');
62
        $elepath = $this->get_pathfor('/workshopform_numerrors_referencegrade'); // we used get_recommended_name() so this works
63
        $paths[] = new restore_path_element($elename, $elepath);
64
 
65
        return $paths; // And we return the interesting paths
66
    }
67
 
68
    /**
69
     * Returns the paths to be handled by the subplugin at exampleassessment level
70
     */
71
    protected function define_exampleassessment_subplugin_structure() {
72
 
73
        $paths = array();
74
 
75
        $elename = $this->get_namefor('examplegrade');
76
        $elepath = $this->get_pathfor('/workshopform_numerrors_examplegrade'); // we used get_recommended_name() so this works
77
        $paths[] = new restore_path_element($elename, $elepath);
78
 
79
        return $paths; // And we return the interesting paths
80
    }
81
 
82
    /**
83
     * Returns the paths to be handled by the subplugin at assessment level
84
     */
85
    protected function define_assessment_subplugin_structure() {
86
 
87
        $paths = array();
88
 
89
        $elename = $this->get_namefor('grade');
90
        $elepath = $this->get_pathfor('/workshopform_numerrors_grade'); // we used get_recommended_name() so this works
91
        $paths[] = new restore_path_element($elename, $elepath);
92
 
93
        return $paths; // And we return the interesting paths
94
    }
95
 
96
    ////////////////////////////////////////////////////////////////////////////
97
    // defined path elements are dispatched to the following methods
98
    ////////////////////////////////////////////////////////////////////////////
99
 
100
    /**
101
     * Processes the workshopform_numerrors_map element
102
     */
103
    public function process_workshopform_numerrors_map($data) {
104
        global $DB;
105
 
106
        $data = (object)$data;
107
        $data->workshopid = $this->get_new_parentid('workshop');
108
        $DB->insert_record('workshopform_numerrors_map', $data);
109
    }
110
 
111
    /**
112
     * Processes the workshopform_numerrors_dimension element
113
     */
114
    public function process_workshopform_numerrors_dimension($data) {
115
        global $DB;
116
 
117
        $data = (object)$data;
118
        $oldid = $data->id;
119
 
120
        $data->workshopid = $this->get_new_parentid('workshop');
121
 
122
        $newitemid = $DB->insert_record('workshopform_numerrors', $data);
123
        $this->set_mapping($this->get_namefor('dimension'), $oldid, $newitemid, true);
124
 
125
        // Process files for this workshopform_numerrors->id only
126
        $this->add_related_files('workshopform_numerrors', 'description', $this->get_namefor('dimension'), null, $oldid);
127
    }
128
 
129
    /**
130
     * Processes the workshopform_numerrors_referencegrade element
131
     */
132
    public function process_workshopform_numerrors_referencegrade($data) {
133
        $this->process_dimension_grades_structure('workshop_referenceassessment', $data);
134
    }
135
 
136
    /**
137
     * Processes the workshopform_numerrors_examplegrade element
138
     */
139
    public function process_workshopform_numerrors_examplegrade($data) {
140
        $this->process_dimension_grades_structure('workshop_exampleassessment', $data);
141
    }
142
 
143
    /**
144
     * Processes the workshopform_numerrors_grade element
145
     */
146
    public function process_workshopform_numerrors_grade($data) {
147
        $this->process_dimension_grades_structure('workshop_assessment', $data);
148
    }
149
 
150
    ////////////////////////////////////////////////////////////////////////////
151
    // internal private methods
152
    ////////////////////////////////////////////////////////////////////////////
153
 
154
    /**
155
     * Process the dimension grades linked with the given type of assessment
156
     *
157
     * Populates the workshop_grades table with new records mapped to the restored
158
     * instances of assessments.
159
     *
160
     * @param mixed $elementname the name of the assessment element
161
     * @param array $data parsed xml data
162
     */
163
    private function process_dimension_grades_structure($elementname, $data) {
164
        global $DB;
165
 
166
        $data = (object)$data;
167
        $oldid = $data->id;
168
 
169
        $data->assessmentid = $this->get_new_parentid($elementname);
170
        $data->strategy = 'numerrors';
171
        $data->dimensionid = $this->get_mappingid($this->get_namefor('dimension'), $data->dimensionid);
172
 
173
        $DB->insert_record('workshop_grades', $data);
174
    }
175
}