[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Provides support for the conversion of moodle1 backup to the moodle2 format 19 * 20 * @package mod_scorm 21 * @copyright 2011 Aparup Banerjee <[email protected]> 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 defined('MOODLE_INTERNAL') || die(); 26 27 /** 28 * Scorm conversion handler 29 */ 30 class moodle1_mod_scorm_handler extends moodle1_mod_handler { 31 32 /** @var moodle1_file_manager */ 33 protected $fileman = null; 34 35 /** @var int cmid */ 36 protected $moduleid = null; 37 38 /** 39 * Declare the paths in moodle.xml we are able to convert 40 * 41 * The method returns list of {@link convert_path} instances. 42 * For each path returned, the corresponding conversion method must be 43 * defined. 44 * 45 * Note that the path /MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM does not 46 * actually exist in the file. The last element with the module name was 47 * appended by the moodle1_converter class. 48 * 49 * @return array of {@link convert_path} instances 50 */ 51 public function get_paths() { 52 return array( 53 new convert_path('scorm', '/MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM', 54 array( 55 'newfields' => array( 56 'whatgrade' => 0, 57 'scormtype' => 'local', 58 'sha1hash' => null, 59 'revision' => '0', 60 'forcecompleted' => 1, 61 'forcenewattempt' => 0, 62 'lastattemptlock' => 0, 63 'displayattemptstatus' => 1, 64 'displaycoursestructure' => 1, 65 'timeopen' => '0', 66 'timeclose' => '0', 67 'introformat' => '0', 68 ), 69 'renamefields' => array( 70 'summary' => 'intro' 71 ) 72 ) 73 ), 74 new convert_path('scorm_sco', '/MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM/SCOES/SCO') 75 ); 76 } 77 78 /** 79 * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM 80 * data available 81 */ 82 public function process_scorm($data) { 83 global $CFG; 84 85 // get the course module id and context id 86 $instanceid = $data['id']; 87 $currentcminfo = $this->get_cminfo($instanceid); 88 $this->moduleid = $currentcminfo['id']; 89 $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid); 90 91 // conditionally migrate to html format in intro 92 if ($CFG->texteditors !== 'textarea') { 93 $data['intro'] = text_to_html($data['intro'], false, false, true); 94 $data['introformat'] = FORMAT_HTML; 95 } 96 97 // get a fresh new file manager for this instance 98 $this->fileman = $this->converter->get_file_manager($contextid, 'mod_scorm'); 99 100 // convert course files embedded into the intro 101 $this->fileman->filearea = 'intro'; 102 $this->fileman->itemid = 0; 103 $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman); 104 105 // check 1.9 version where backup was created 106 $backupinfo = $this->converter->get_stash('backup_info'); 107 if ($backupinfo['moodle_version'] < 2007110503) { 108 // as we have no module version data, assume $currmodule->version <= $module->version 109 // - fix data as the source 1.9 build hadn't yet at time of backing up. 110 $data['grademethod'] = $data['grademethod']%10; 111 } 112 113 // update scormtype (logic is consistent as done in scorm/db/upgrade.php) 114 $ismanifest = preg_match('/imsmanifest\.xml$/', $data['reference']); 115 $iszippif = preg_match('/.(zip|pif)$/', $data['reference']); 116 $isurl = preg_match('/^((http|https):\/\/|www\.)/', $data['reference']); 117 if ($isurl) { 118 if ($ismanifest) { 119 $data['scormtype'] = 'external'; 120 } else if ($iszippif) { 121 $data['scormtype'] = 'localtype'; 122 } 123 } 124 125 // migrate scorm package file 126 $this->fileman->filearea = 'package'; 127 $this->fileman->itemid = 0; 128 $this->fileman->migrate_file('course_files/'.$data['reference']); 129 130 // start writing scorm.xml 131 $this->open_xml_writer("activities/scorm_{$this->moduleid}/scorm.xml"); 132 $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 133 'modulename' => 'scorm', 'contextid' => $contextid)); 134 $this->xmlwriter->begin_tag('scorm', array('id' => $instanceid)); 135 136 foreach ($data as $field => $value) { 137 if ($field <> 'id') { 138 $this->xmlwriter->full_tag($field, $value); 139 } 140 } 141 142 $this->xmlwriter->begin_tag('scoes'); 143 144 return $data; 145 } 146 147 /** 148 * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/SCORM/SCOES/SCO 149 * data available 150 */ 151 public function process_scorm_sco($data) { 152 $this->write_xml('sco', $data, array('/sco/id')); 153 } 154 155 /** 156 * This is executed when we reach the closing </MOD> tag of our 'scorm' path 157 */ 158 public function on_scorm_end() { 159 // close scorm.xml 160 $this->xmlwriter->end_tag('scoes'); 161 $this->xmlwriter->end_tag('scorm'); 162 $this->xmlwriter->end_tag('activity'); 163 $this->close_xml_writer(); 164 165 // write inforef.xml 166 $this->open_xml_writer("activities/scorm_{$this->moduleid}/inforef.xml"); 167 $this->xmlwriter->begin_tag('inforef'); 168 $this->xmlwriter->begin_tag('fileref'); 169 foreach ($this->fileman->get_fileids() as $fileid) { 170 $this->write_xml('file', array('id' => $fileid)); 171 } 172 $this->xmlwriter->end_tag('fileref'); 173 $this->xmlwriter->end_tag('inforef'); 174 $this->close_xml_writer(); 175 } 176 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |