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