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_accumulative 20 * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.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_accumulative subplugin. 29 */ 30 class restore_workshopform_accumulative_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_accumulative_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_accumulative_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_accumulative_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_accumulative_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_accumulative_dimension element 98 */ 99 public function process_workshopform_accumulative_dimension($data) { 100 global $DB; 101 102 $data = (object)$data; 103 $oldid = $data->id; 104 105 $data->workshopid = $this->get_new_parentid('workshop'); 106 if ($data->grade < 0) { // scale found, get mapping 107 $data->grade = -($this->get_mappingid('scale', abs($data->grade))); 108 } 109 110 $newitemid = $DB->insert_record('workshopform_accumulative', $data); 111 $this->set_mapping($this->get_namefor('dimension'), $oldid, $newitemid, true); 112 113 // Process files for this workshopform_accumulative->id only 114 $this->add_related_files('workshopform_accumulative', 'description', $this->get_namefor('dimension'), null, $oldid); 115 } 116 117 /** 118 * Processes the workshopform_accumulative_referencegrade element 119 */ 120 public function process_workshopform_accumulative_referencegrade($data) { 121 $this->process_dimension_grades_structure('workshop_referenceassessment', $data); 122 } 123 124 /** 125 * Processes the workshopform_accumulative_examplegrade element 126 */ 127 public function process_workshopform_accumulative_examplegrade($data) { 128 $this->process_dimension_grades_structure('workshop_exampleassessment', $data); 129 } 130 131 /** 132 * Processes the workshopform_accumulative_grade element 133 */ 134 public function process_workshopform_accumulative_grade($data) { 135 $this->process_dimension_grades_structure('workshop_assessment', $data); 136 } 137 138 //////////////////////////////////////////////////////////////////////////// 139 // internal private methods 140 //////////////////////////////////////////////////////////////////////////// 141 142 /** 143 * Process the dimension grades linked with the given type of assessment 144 * 145 * Populates the workshop_grades table with new records mapped to the restored 146 * instances of assessments. 147 * 148 * @param mixed $elementname the name of the assessment element 149 * @param array $data parsed xml data 150 */ 151 private function process_dimension_grades_structure($elementname, $data) { 152 global $DB; 153 154 $data = (object)$data; 155 $oldid = $data->id; 156 157 $data->assessmentid = $this->get_new_parentid($elementname); 158 $data->strategy = 'accumulative'; 159 $data->dimensionid = $this->get_mappingid($this->get_namefor('dimension'), $data->dimensionid); 160 161 $DB->insert_record('workshop_grades', $data); 162 } 163 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body