|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00025 defined('MOODLE_INTERNAL') || die(); 00026 00031 class restore_workshopform_comments_subplugin extends restore_subplugin { 00032 00034 // mappings of XML paths to the processable methods 00036 00040 protected function define_workshop_subplugin_structure() { 00041 00042 $paths = array(); 00043 00044 $elename = $this->get_namefor('dimension'); 00045 $elepath = $this->get_pathfor('/workshopform_comments_dimension'); // we used get_recommended_name() so this works 00046 $paths[] = new restore_path_element($elename, $elepath); 00047 00048 return $paths; // And we return the interesting paths 00049 } 00050 00054 protected function define_referenceassessment_subplugin_structure() { 00055 00056 $paths = array(); 00057 00058 $elename = $this->get_namefor('referencegrade'); 00059 $elepath = $this->get_pathfor('/workshopform_comments_referencegrade'); // we used get_recommended_name() so this works 00060 $paths[] = new restore_path_element($elename, $elepath); 00061 00062 return $paths; // And we return the interesting paths 00063 } 00064 00068 protected function define_exampleassessment_subplugin_structure() { 00069 00070 $paths = array(); 00071 00072 $elename = $this->get_namefor('examplegrade'); 00073 $elepath = $this->get_pathfor('/workshopform_comments_examplegrade'); // we used get_recommended_name() so this works 00074 $paths[] = new restore_path_element($elename, $elepath); 00075 00076 return $paths; // And we return the interesting paths 00077 } 00078 00082 protected function define_assessment_subplugin_structure() { 00083 00084 $paths = array(); 00085 00086 $elename = $this->get_namefor('grade'); 00087 $elepath = $this->get_pathfor('/workshopform_comments_grade'); // we used get_recommended_name() so this works 00088 $paths[] = new restore_path_element($elename, $elepath); 00089 00090 return $paths; // And we return the interesting paths 00091 } 00092 00094 // defined path elements are dispatched to the following methods 00096 00100 public function process_workshopform_comments_dimension($data) { 00101 global $DB; 00102 00103 $data = (object)$data; 00104 $oldid = $data->id; 00105 00106 $data->workshopid = $this->get_new_parentid('workshop'); 00107 00108 $newitemid = $DB->insert_record('workshopform_comments', $data); 00109 $this->set_mapping($this->get_namefor('dimension'), $oldid, $newitemid, true); 00110 00111 // Process files for this workshopform_comments->id only 00112 $this->add_related_files('workshopform_comments', 'description', $this->get_namefor('dimension'), null, $oldid); 00113 } 00114 00118 public function process_workshopform_comments_referencegrade($data) { 00119 $this->process_dimension_grades_structure('workshop_referenceassessment', $data); 00120 } 00121 00125 public function process_workshopform_comments_examplegrade($data) { 00126 $this->process_dimension_grades_structure('workshop_exampleassessment', $data); 00127 } 00128 00132 public function process_workshopform_comments_grade($data) { 00133 $this->process_dimension_grades_structure('workshop_assessment', $data); 00134 } 00135 00137 // internal private methods 00139 00149 private function process_dimension_grades_structure($elementname, $data) { 00150 global $DB; 00151 00152 $data = (object)$data; 00153 $oldid = $data->id; 00154 00155 $data->assessmentid = $this->get_new_parentid($elementname); 00156 $data->strategy = 'comments'; 00157 $data->grade = 100.00000; 00158 $data->dimensionid = $this->get_mappingid($this->get_namefor('dimension'), $data->dimensionid); 00159 00160 $DB->insert_record('workshop_grades', $data); 00161 } 00162 }