|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 // This file is part of Moodle - http://moodle.org/ 00003 // 00004 // Moodle is free software: you can redistribute it and/or modify 00005 // it under the terms of the GNU General Public License as published by 00006 // the Free Software Foundation, either version 3 of the License, or 00007 // (at your option) any later version. 00008 // 00009 // Moodle is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 // GNU General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00016 00026 defined('MOODLE_INTERNAL') || die(); 00027 00031 class moodle1_mod_feedback_handler extends moodle1_mod_handler { 00032 00034 protected $fileman = null; 00035 00037 protected $moduleid = null; 00038 00052 public function get_paths() { 00053 return array( 00054 new convert_path( 00055 'feedback', '/MOODLE_BACKUP/COURSE/MODULES/MOD/FEEDBACK', 00056 array( 00057 'renamefields' => array( 00058 'summary' => 'intro', 00059 'pageaftersub' => 'page_after_submit', 00060 ), 00061 'newfields' => array( 00062 'autonumbering' => 1, 00063 'site_after_submit' => '', 00064 'introformat' => 0, 00065 'page_after_submitformat' => 0, 00066 'completionsubmit' => 0, 00067 ), 00068 ) 00069 ), 00070 new convert_path( 00071 'feedback_item', '/MOODLE_BACKUP/COURSE/MODULES/MOD/FEEDBACK/ITEMS/ITEM', 00072 array ( 00073 'newfields' => array( 00074 'label' => '', 00075 'options' => '', 00076 'dependitem' => 0, 00077 'dependvalue' => '', 00078 ), 00079 ) 00080 ), 00081 ); 00082 } 00083 00088 public function process_feedback($data) { 00089 // get the course module id and context id 00090 $instanceid = $data['id']; 00091 $cminfo = $this->get_cminfo($instanceid); 00092 $this->moduleid = $cminfo['id']; 00093 $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid); 00094 00095 // get a fresh new file manager for this instance 00096 $this->fileman = $this->converter->get_file_manager($contextid, 'mod_feedback'); 00097 00098 // convert course files embedded into the intro 00099 $this->fileman->filearea = 'intro'; 00100 $this->fileman->itemid = 0; 00101 $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman); 00102 00103 // start writing feedback.xml 00104 $this->open_xml_writer("activities/feedback_{$this->moduleid}/feedback.xml"); 00105 $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 00106 'modulename' => 'feedback', 'contextid' => $contextid)); 00107 $this->xmlwriter->begin_tag('feedback', array('id' => $instanceid)); 00108 00109 foreach ($data as $field => $value) { 00110 if ($field <> 'id') { 00111 $this->xmlwriter->full_tag($field, $value); 00112 } 00113 } 00114 00115 $this->xmlwriter->begin_tag('items'); 00116 00117 return $data; 00118 } 00119 00124 public function process_feedback_item($data) { 00125 $this->write_xml('item', $data, array('/item/id')); 00126 } 00127 00131 public function on_feedback_end() { 00132 // finish writing feedback.xml 00133 $this->xmlwriter->end_tag('items'); 00134 $this->xmlwriter->end_tag('feedback'); 00135 $this->xmlwriter->end_tag('activity'); 00136 $this->close_xml_writer(); 00137 00138 // write inforef.xml 00139 $this->open_xml_writer("activities/feedback_{$this->moduleid}/inforef.xml"); 00140 $this->xmlwriter->begin_tag('inforef'); 00141 $this->xmlwriter->begin_tag('fileref'); 00142 foreach ($this->fileman->get_fileids() as $fileid) { 00143 $this->write_xml('file', array('id' => $fileid)); 00144 } 00145 $this->xmlwriter->end_tag('fileref'); 00146 $this->xmlwriter->end_tag('inforef'); 00147 $this->close_xml_writer(); 00148 } 00149 }