|
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 00027 defined('MOODLE_INTERNAL') || die(); 00028 00032 class moodle1_mod_choice_handler extends moodle1_mod_handler { 00033 00035 protected $fileman = null; 00036 00038 protected $moduleid = null; 00039 00053 public function get_paths() { 00054 return array( 00055 new convert_path( 00056 'choice', '/MOODLE_BACKUP/COURSE/MODULES/MOD/CHOICE', 00057 array( 00058 'renamefields' => array( 00059 'text' => 'intro', 00060 'format' => 'introformat', 00061 ), 00062 'newfields' => array( 00063 'completionsubmit' => 0, 00064 ), 00065 'dropfields' => array( 00066 'modtype' 00067 ), 00068 ) 00069 ), 00070 new convert_path('choice_options', '/MOODLE_BACKUP/COURSE/MODULES/MOD/CHOICE/OPTIONS'), 00071 new convert_path('choice_option', '/MOODLE_BACKUP/COURSE/MODULES/MOD/CHOICE/OPTIONS/OPTION'), 00072 ); 00073 } 00074 00079 public function process_choice($data) { 00080 00081 // get the course module id and context id 00082 $instanceid = $data['id']; 00083 $cminfo = $this->get_cminfo($instanceid); 00084 $this->moduleid = $cminfo['id']; 00085 $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid); 00086 00087 // get a fresh new file manager for this instance 00088 $this->fileman = $this->converter->get_file_manager($contextid, 'mod_choice'); 00089 00090 // convert course files embedded into the intro 00091 $this->fileman->filearea = 'intro'; 00092 $this->fileman->itemid = 0; 00093 $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman); 00094 00095 // start writing choice.xml 00096 $this->open_xml_writer("activities/choice_{$this->moduleid}/choice.xml"); 00097 $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 00098 'modulename' => 'choice', 'contextid' => $contextid)); 00099 $this->xmlwriter->begin_tag('choice', array('id' => $instanceid)); 00100 00101 foreach ($data as $field => $value) { 00102 if ($field <> 'id') { 00103 $this->xmlwriter->full_tag($field, $value); 00104 } 00105 } 00106 00107 return $data; 00108 } 00109 00113 public function on_choice_options_start() { 00114 $this->xmlwriter->begin_tag('options'); 00115 } 00116 00121 public function process_choice_option($data) { 00122 $this->write_xml('option', $data, array('/option/id')); 00123 } 00124 00128 public function on_choice_options_end() { 00129 $this->xmlwriter->end_tag('options'); 00130 } 00131 00135 public function on_choice_end() { 00136 // finalize choice.xml 00137 $this->xmlwriter->end_tag('choice'); 00138 $this->xmlwriter->end_tag('activity'); 00139 $this->close_xml_writer(); 00140 00141 // write inforef.xml 00142 $this->open_xml_writer("activities/choice_{$this->moduleid}/inforef.xml"); 00143 $this->xmlwriter->begin_tag('inforef'); 00144 $this->xmlwriter->begin_tag('fileref'); 00145 foreach ($this->fileman->get_fileids() as $fileid) { 00146 $this->write_xml('file', array('id' => $fileid)); 00147 } 00148 $this->xmlwriter->end_tag('fileref'); 00149 $this->xmlwriter->end_tag('inforef'); 00150 $this->close_xml_writer(); 00151 } 00152 }