|
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_survey_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 'survey', '/MOODLE_BACKUP/COURSE/MODULES/MOD/SURVEY', 00057 array( 00058 'newfields' => array( 00059 'introformat' => 0, 00060 ), 00061 ) 00062 ), 00063 ); 00064 } 00065 00070 public function process_survey($data) { 00071 global $CFG; 00072 00073 // get the course module id and context id 00074 $instanceid = $data['id']; 00075 $cminfo = $this->get_cminfo($instanceid); 00076 $this->moduleid = $cminfo['id']; 00077 $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid); 00078 00079 // replay upgrade step 2009042002 00080 if ($CFG->texteditors !== 'textarea') { 00081 $data['intro'] = text_to_html($data['intro'], false, false, true); 00082 $data['introformat'] = FORMAT_HTML; 00083 } 00084 00085 // get a fresh new file manager for this instance 00086 $this->fileman = $this->converter->get_file_manager($contextid, 'mod_survey'); 00087 00088 // convert course files embedded into the intro 00089 $this->fileman->filearea = 'intro'; 00090 $this->fileman->itemid = 0; 00091 $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman); 00092 00093 // write survey.xml 00094 $this->open_xml_writer("activities/survey_{$this->moduleid}/survey.xml"); 00095 $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 00096 'modulename' => 'survey', 'contextid' => $contextid)); 00097 $this->xmlwriter->begin_tag('survey', array('id' => $instanceid)); 00098 00099 foreach ($data as $field => $value) { 00100 if ($field <> 'id') { 00101 $this->xmlwriter->full_tag($field, $value); 00102 } 00103 } 00104 00105 return $data; 00106 } 00107 00111 public function on_survey_end() { 00112 // finish survey.xml 00113 $this->xmlwriter->end_tag('survey'); 00114 $this->xmlwriter->end_tag('activity'); 00115 $this->close_xml_writer(); 00116 00117 // write inforef.xml 00118 $this->open_xml_writer("activities/survey_{$this->moduleid}/inforef.xml"); 00119 $this->xmlwriter->begin_tag('inforef'); 00120 $this->xmlwriter->begin_tag('fileref'); 00121 foreach ($this->fileman->get_fileids() as $fileid) { 00122 $this->write_xml('file', array('id' => $fileid)); 00123 } 00124 $this->xmlwriter->end_tag('fileref'); 00125 $this->xmlwriter->end_tag('inforef'); 00126 $this->close_xml_writer(); 00127 } 00128 }