[ Index ] |
PHP Cross Reference of Unnamed Project |
[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 * 1.9 to 2.0 backup format converter. (Also currently used in common cartridge import process) 19 * 20 * @package mod_lti 21 * @copyright Copyright (c) 2011 Moodlerooms Inc. (http://www.moodlerooms.com) 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 * @author Darko Miletic 24 */ 25 26 defined('MOODLE_INTERNAL') || die(); 27 28 class moodle1_mod_lti_handler extends moodle1_mod_handler { 29 30 /** @var moodle1_file_manager */ 31 protected $fileman = null; 32 33 /** @var int cmid */ 34 protected $moduleid = null; 35 36 /** 37 * Declare the paths in moodle.xml we are able to convert 38 * 39 * The method returns list of {@link convert_path} instances. 40 * For each path returned, the corresponding conversion method must be 41 * defined. 42 * 43 * Note that the path /MOODLE_BACKUP/COURSE/MODULES/MOD/LTI does not 44 * actually exist in the file. The last element with the module name was 45 * appended by the moodle1_converter class. 46 * 47 * @return array of {@link convert_path} instances 48 */ 49 public function get_paths() { 50 51 return array( 52 new convert_path( 53 'basiclti', '/MOODLE_BACKUP/COURSE/MODULES/MOD/LTI' 54 ) 55 ); 56 57 } 58 59 /** 60 * This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/LTI 61 * data available 62 */ 63 public function process_basiclti($data) { 64 global $DB; 65 66 // Get the course module id and context id. 67 $instanceid = $data['id']; 68 $cminfo = $this->get_cminfo($instanceid); 69 $this->moduleid = $cminfo['id']; 70 $contextid = $this->converter->get_contextid(CONTEXT_MODULE, $this->moduleid); 71 72 // Get a fresh new file manager for this instance. 73 $this->fileman = $this->converter->get_file_manager($contextid, 'mod_lti'); 74 75 // Convert course files embedded into the intro. 76 $this->fileman->filearea = 'intro'; 77 $this->fileman->itemid = 0; 78 $data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $this->fileman); 79 80 // Start writing assignment.xml. 81 $this->open_xml_writer("activities/lti_{$this->moduleid}/lti.xml"); 82 $this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $this->moduleid, 83 'modulename' => 'lti', 'contextid' => $contextid)); 84 $this->xmlwriter->begin_tag('lti', array('id' => $instanceid)); 85 86 $ignorefields = array('id', 'modtype'); 87 if (!$DB->record_exists('lti_types', array('id' => $data['typeid']))) { 88 $ntypeid = $DB->get_field('lti_types_config', 89 'typeid', 90 array('name' => 'toolurl', 'value' => $data['toolurl']), 91 IGNORE_MULTIPLE); 92 if ($ntypeid === false) { 93 $ntypeid = $DB->get_field('lti_types_config', 94 'typeid', 95 array(), 96 IGNORE_MULTIPLE); 97 98 } 99 if ($ntypeid === false) { 100 $ntypeid = 0; 101 } 102 $data['typeid'] = $ntypeid; 103 } 104 if (empty($data['servicesalt'])) { 105 $data['servicesalt'] = uniqid('', true); 106 } 107 foreach ($data as $field => $value) { 108 if (!in_array($field, $ignorefields)) { 109 $this->xmlwriter->full_tag($field, $value); 110 } 111 } 112 113 return $data; 114 } 115 116 /** 117 * This is executed when we reach the closing </MOD> tag of our 'lti' path 118 */ 119 public function on_basiclti_end() { 120 // Finish writing basiclti.xml. 121 $this->xmlwriter->end_tag('lti'); 122 $this->xmlwriter->end_tag('activity'); 123 $this->close_xml_writer(); 124 125 // Write inforef.xml. 126 $this->open_xml_writer("activities/lti_{$this->moduleid}/inforef.xml"); 127 $this->xmlwriter->begin_tag('inforef'); 128 $this->xmlwriter->begin_tag('fileref'); 129 foreach ($this->fileman->get_fileids() as $fileid) { 130 $this->write_xml('file', array('id' => $fileid)); 131 } 132 $this->xmlwriter->end_tag('fileref'); 133 $this->xmlwriter->end_tag('inforef'); 134 $this->close_xml_writer(); 135 } 136 137 } 138
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |