|
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_url_handler extends moodle1_resource_successor_handler { 00033 00035 protected $fileman = null; 00036 00041 public function process_legacy_resource($data) { 00042 00043 // get the course module id and context id 00044 $instanceid = $data['id']; 00045 $cminfo = $this->get_cminfo($instanceid, 'resource'); 00046 $moduleid = $cminfo['id']; 00047 $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid); 00048 00049 // prepare the new url instance record 00050 $url = array(); 00051 $url['id'] = $data['id']; 00052 $url['name'] = $data['name']; 00053 $url['intro'] = $data['intro']; 00054 $url['introformat'] = $data['introformat']; 00055 $url['externalurl'] = $data['reference']; 00056 $url['timemodified'] = $data['timemodified']; 00057 00058 // populate display and displayoptions fields 00059 $options = array('printheading' => 0, 'printintro' => 1); 00060 if ($data['options'] == 'frame') { 00061 $url['display'] = RESOURCELIB_DISPLAY_FRAME; 00062 00063 } else if ($data['options'] == 'objectframe') { 00064 $url['display'] = RESOURCELIB_DISPLAY_EMBED; 00065 00066 } else if ($data['popup']) { 00067 $url['display'] = RESOURCELIB_DISPLAY_POPUP; 00068 $rawoptions = explode(',', $data['popup']); 00069 foreach ($rawoptions as $rawoption) { 00070 list($name, $value) = explode('=', trim($rawoption), 2); 00071 if ($value > 0 and ($name == 'width' or $name == 'height')) { 00072 $options['popup'.$name] = $value; 00073 continue; 00074 } 00075 } 00076 00077 } else { 00078 $url['display'] = RESOURCELIB_DISPLAY_AUTO; 00079 } 00080 $url['displayoptions'] = serialize($options); 00081 00082 // populate the parameters field 00083 $parameters = array(); 00084 if ($data['alltext']) { 00085 $rawoptions = explode(',', $data['alltext']); 00086 foreach ($rawoptions as $rawoption) { 00087 list($variable, $parameter) = explode('=', trim($rawoption), 2); 00088 $parameters[$parameter] = $variable; 00089 } 00090 } 00091 $url['parameters'] = serialize($parameters); 00092 00093 // convert course files embedded into the intro 00094 $this->fileman = $this->converter->get_file_manager($contextid, 'mod_url', 'intro'); 00095 $url['intro'] = moodle1_converter::migrate_referenced_files($url['intro'], $this->fileman); 00096 00097 // write url.xml 00098 $this->open_xml_writer("activities/url_{$moduleid}/url.xml"); 00099 $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid, 00100 'modulename' => 'url', 'contextid' => $contextid)); 00101 $this->write_xml('url', $url, array('/url/id')); 00102 $this->xmlwriter->end_tag('activity'); 00103 $this->close_xml_writer(); 00104 00105 // write inforef.xml 00106 $this->open_xml_writer("activities/url_{$moduleid}/inforef.xml"); 00107 $this->xmlwriter->begin_tag('inforef'); 00108 $this->xmlwriter->begin_tag('fileref'); 00109 foreach ($this->fileman->get_fileids() as $fileid) { 00110 $this->write_xml('file', array('id' => $fileid)); 00111 } 00112 $this->xmlwriter->end_tag('fileref'); 00113 $this->xmlwriter->end_tag('inforef'); 00114 $this->close_xml_writer(); 00115 } 00116 }