|
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_scorm_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('scorm', '/MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM', 00055 array( 00056 'newfields' => array( 00057 'whatgrade' => 0, 00058 'scormtype' => 'local', 00059 'sha1hash' => null, 00060 'revision' => '0', 00061 'forcecompleted' => 1, 00062 'forcenewattempt' => 0, 00063 'lastattemptlock' => 0, 00064 'displayattemptstatus' => 1, 00065 'displaycoursestructure' => 1, 00066 'timeopen' => '0', 00067 'timeclose' => '0', 00068 'introformat' => '0', 00069 ), 00070 'renamefields' => array( 00071 'summary' => 'intro' 00072 ) 00073 ) 00074 ), 00075 new convert_path('scorm_sco', '/MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM/SCOES/SCO') 00076 ); 00077 } 00078 00083 public function process_scorm($data) { 00084 global $CFG; 00085 00086 // get the course module id and context id 00087 $instanceid = $data['id']; 00088 $currentcminfo = $this->get_cminfo($instanceid); 00089 $this->moduleid = $currentcminfo['id']; 00090 $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid); 00091 00092 // conditionally migrate to html format in intro 00093 if ($CFG->texteditors !== 'textarea') { 00094 $data['intro'] = text_to_html($data['intro'], false, false, true); 00095 $data['introformat'] = FORMAT_HTML; 00096 } 00097 00098 // get a fresh new file manager for this instance 00099 $this->fileman = $this->converter->get_file_manager($contextid, 'mod_scorm'); 00100 00101 // convert course files embedded into the intro 00102 $this->fileman->filearea = 'intro'; 00103 $this->fileman->itemid = 0; 00104 $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman); 00105 00106 // check 1.9 version where backup was created 00107 $backupinfo = $this->converter->get_stash('backup_info'); 00108 if ($backupinfo['moodle_version'] < 2007110503) { 00109 // as we have no module version data, assume $currmodule->version <= $module->version 00110 // - fix data as the source 1.9 build hadn't yet at time of backing up. 00111 $data['grademethod'] = $data['grademethod']%10; 00112 } 00113 00114 // update scormtype (logic is consistent as done in scorm/db/upgrade.php) 00115 $ismanifest = preg_match('/imsmanifest\.xml$/', $data['reference']); 00116 $iszippif = preg_match('/.(zip|pif)$/', $data['reference']); 00117 $isurl = preg_match('/^((http|https):\/\/|www\.)/', $data['reference']); 00118 if ($isurl) { 00119 if ($ismanifest) { 00120 $data['scormtype'] = 'external'; 00121 } else if ($iszippif) { 00122 $data['scormtype'] = 'localtype'; 00123 } 00124 } 00125 00126 // migrate scorm package file 00127 $this->fileman->filearea = 'package'; 00128 $this->fileman->itemid = 0; 00129 $this->fileman->migrate_file('course_files/'.$data['reference']); 00130 00131 // start writing scorm.xml 00132 $this->open_xml_writer("activities/scorm_{$this->moduleid}/scorm.xml"); 00133 $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 00134 'modulename' => 'scorm', 'contextid' => $contextid)); 00135 $this->xmlwriter->begin_tag('scorm', array('id' => $instanceid)); 00136 00137 foreach ($data as $field => $value) { 00138 if ($field <> 'id') { 00139 $this->xmlwriter->full_tag($field, $value); 00140 } 00141 } 00142 00143 $this->xmlwriter->begin_tag('scoes'); 00144 00145 return $data; 00146 } 00147 00152 public function process_scorm_sco($data) { 00153 $this->write_xml('sco', $data, array('/sco/id')); 00154 } 00155 00159 public function on_scorm_end() { 00160 // close scorm.xml 00161 $this->xmlwriter->end_tag('scoes'); 00162 $this->xmlwriter->end_tag('scorm'); 00163 $this->xmlwriter->end_tag('activity'); 00164 $this->close_xml_writer(); 00165 00166 // write inforef.xml 00167 $this->open_xml_writer("activities/scorm_{$this->moduleid}/inforef.xml"); 00168 $this->xmlwriter->begin_tag('inforef'); 00169 $this->xmlwriter->begin_tag('fileref'); 00170 foreach ($this->fileman->get_fileids() as $fileid) { 00171 $this->write_xml('file', array('id' => $fileid)); 00172 } 00173 $this->xmlwriter->end_tag('fileref'); 00174 $this->xmlwriter->end_tag('inforef'); 00175 $this->close_xml_writer(); 00176 } 00177 }