|
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_page_handler extends moodle1_resource_successor_handler { 00033 00035 protected $fileman = null; 00036 00041 public function process_legacy_resource(array $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 // convert the legacy data onto the new page record 00050 $page = array(); 00051 $page['id'] = $data['id']; 00052 $page['name'] = $data['name']; 00053 $page['intro'] = $data['intro']; 00054 $page['introformat'] = $data['introformat']; 00055 $page['content'] = $data['alltext']; 00056 $page['contentformat'] = (int)$data['reference']; 00057 00058 // this is unexpected but just in case (the same step applied during upgrade) 00059 if ($page['contentformat'] < 0 or $page['contentformat'] > 4) { 00060 $page['contentformat'] = FORMAT_MOODLE; 00061 } 00062 00063 $page['legacyfiles'] = RESOURCELIB_LEGACYFILES_ACTIVE; 00064 $page['legacyfileslast'] = null; 00065 $page['revision'] = 1; 00066 $page['timemodified'] = $data['timemodified']; 00067 00068 // populate display and displayoptions fields 00069 $options = array('printheading' => 0, 'printintro' => 0); 00070 if ($data['popup']) { 00071 $page['display'] = RESOURCELIB_DISPLAY_POPUP; 00072 $rawoptions = explode(',', $data['popup']); 00073 foreach ($rawoptions as $rawoption) { 00074 list($name, $value) = explode('=', trim($rawoption), 2); 00075 if ($value > 0 and ($name == 'width' or $name == 'height')) { 00076 $options['popup'.$name] = $value; 00077 continue; 00078 } 00079 } 00080 } else { 00081 $page['display'] = RESOURCELIB_DISPLAY_OPEN; 00082 } 00083 $page['displayoptions'] = serialize($options); 00084 00085 // get a fresh new file manager for this instance 00086 $this->fileman = $this->converter->get_file_manager($contextid, 'mod_page'); 00087 00088 // convert course files embedded into the intro 00089 $this->fileman->filearea = 'intro'; 00090 $this->fileman->itemid = 0; 00091 $page['intro'] = moodle1_converter::migrate_referenced_files($page['intro'], $this->fileman); 00092 00093 // convert course files embedded into the content 00094 $this->fileman->filearea = 'content'; 00095 $this->fileman->itemid = 0; 00096 $page['content'] = moodle1_converter::migrate_referenced_files($page['content'], $this->fileman); 00097 00098 // write page.xml 00099 $this->open_xml_writer("activities/page_{$moduleid}/page.xml"); 00100 $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid, 00101 'modulename' => 'page', 'contextid' => $contextid)); 00102 $this->write_xml('page', $page, array('/page/id')); 00103 $this->xmlwriter->end_tag('activity'); 00104 $this->close_xml_writer(); 00105 00106 // write inforef.xml for migrated resource file. 00107 $this->open_xml_writer("activities/page_{$moduleid}/inforef.xml"); 00108 $this->xmlwriter->begin_tag('inforef'); 00109 $this->xmlwriter->begin_tag('fileref'); 00110 foreach ($this->fileman->get_fileids() as $fileid) { 00111 $this->write_xml('file', array('id' => $fileid)); 00112 } 00113 $this->xmlwriter->end_tag('fileref'); 00114 $this->xmlwriter->end_tag('inforef'); 00115 $this->close_xml_writer(); 00116 } 00117 }