MDL-19936 backup - added restore of eval->best and form->accumulative
[moodle.git] / mod / workshop / form / accumulative / backup / moodle2 / restore_workshopform_accumulative_subplugin.class.php
1 <?php
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/>.
18 /**
19  * @package moodlecore
20  * @subpackage backup-moodle2
21  * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
22  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23  */
25 /**
26  * restore subplugin class that provides the necessary information
27  * needed to restore one workshopform->accumulative subplugin.
28  */
29 class restore_workshopform_accumulative_subplugin extends restore_subplugin {
31     /**
32      * Returns the paths to be handled by the subplugin at workshop level
33      */
34     protected function define_workshop_subplugin_structure() {
36         $paths = array();
38         $elename = $this->get_namefor('workshopform_accumulative_dimension');
39         $elepath = $this->get_pathfor('/workshopform_accumulative_dimension'); // we used get_recommended_name() so this works
40         $paths[] = new restore_path_element($elename, $elepath);
42         return $paths; // And we return the interesting paths
43     }
45     /**
46      * Returns the paths to be handled by the subplugin at referenceassessment level
47      */
48     protected function define_referenceassessment_subplugin_structure() {
50         $paths = array();
52         $elename = $this->get_namefor('workshopform_accumulative_referencegrade');
53         $elepath = $this->get_pathfor('/workshopform_accumulative_referencegrade'); // we used get_recommended_name() so this works
54         $paths[] = new restore_path_element($elename, $elepath);
56         return $paths; // And we return the interesting paths
57     }
59     /**
60      * Returns the paths to be handled by the subplugin at exampleassessment level
61      */
62     protected function define_exampleassessment_subplugin_structure() {
64         $paths = array();
66         $elename = $this->get_namefor('workshopform_accumulative_examplegrade');
67         $elepath = $this->get_pathfor('/workshopform_accumulative_examplegrade'); // we used get_recommended_name() so this works
68         $paths[] = new restore_path_element($elename, $elepath);
70         return $paths; // And we return the interesting paths
71     }
73     /**
74      * Returns the paths to be handled by the subplugin at assessment level
75      */
76     protected function define_assessment_subplugin_structure() {
78         $paths = array();
80         $elename = $this->get_namefor('workshopform_accumulative_grade');
81         $elepath = $this->get_pathfor('/workshopform_accumulative_grade'); // we used get_recommended_name() so this works
82         $paths[] = new restore_path_element($elename, $elepath);
84         return $paths; // And we return the interesting paths
85     }
87     /**
88      * This method processes the workshopform_accumulative_dimension  element
89      * inside one accumulative workshopform (see accumulative subplugin backup)
90      */
91     public function process_workshopform_accumulative_workshopform_accumulative_dimension($data) {
92         global $DB;
94         $data = (object)$data;
95         $oldid = $data->id;
97         $data->workshopid = $this->get_new_parentid('workshop');
98         if ($data->grade < 0) { // scale found, get mapping
99             $data->grade = -($this->get_mappingid('scale', abs($data->grade)));
100         }
102         $newitemid = $DB->insert_record('workshopform_accumulative', $data);
103         $this->set_mapping('workshopform_accumulative', $oldid, $newitemid, true);
105         // Process files for this workshopform_accumulative->id only
106         $this->add_related_files('workshopform_accumulative', 'description', 'workshopform_accumulative', null, $oldid);
107     }
109     /**
110      * This method processes the workshopform_accumulative_referencegrade element
111      * inside one accumulative workshopform (see accumulative subplugin backup)
112      */
113     public function process_workshopform_accumulative_workshopform_accumulative_referencegrade($data) {
114         global $DB;
116         $data = (object)$data;
117         $oldid = $data->id;
119         $data->assessmentid = $this->get_new_parentid('workshop_referenceassessment');
120         $data->strategy = 'accumulative';
121         $data->dimensionid = $this->get_mappingid('workshopform_accumulative', $data->dimensionid);
123         $newitemid = $DB->insert_record('workshop_grades', $data);
124     }
126     /**
127      * This method processes the workshopform_accumulative_examplegrade  element
128      * inside one accumulative workshopform (see accumulative subplugin backup)
129      */
130     public function process_workshopform_accumulative_workshopform_accumulative_examplegrade($data) {
131         global $DB;
133         $data = (object)$data;
134         $oldid = $data->id;
136         $data->assessmentid = $this->get_new_parentid('workshop_exampleassessment');
137         $data->strategy = 'accumulative';
138         $data->dimensionid = $this->get_mappingid('workshopform_accumulative', $data->dimensionid);
140         $newitemid = $DB->insert_record('workshop_grades', $data);
141     }
143     /**
144      * This method processes the workshopform_accumulative_grade  element
145      * inside one accumulative workshopform (see accumulative subplugin backup)
146      */
147     public function process_workshopform_accumulative_workshopform_accumulative_grade($data) {
148         global $DB;
150         $data = (object)$data;
151         $oldid = $data->id;
153         $data->assessmentid = $this->get_new_parentid('workshop_assessment');
154         $data->strategy = 'accumulative';
155         $data->dimensionid = $this->get_mappingid('workshopform_accumulative', $data->dimensionid);
157         $newitemid = $DB->insert_record('workshop_grades', $data);
158     }