See Release Notes
Long Term Support Release
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 = false; 89 $toolurls = $DB->get_records_select( 90 'lti_types_config', 91 "name = 'toolurl' AND " . $DB->sql_compare_text('value', 256) . ' = ' . $DB->sql_compare_text('?', 256), 92 [$data['toolurl']], 93 '', 94 'id, value' 95 ); 96 foreach ($toolurls as $id => $value) { 97 if ($value == $data['toolurl']) { 98 $ntypeid = $id; 99 break; 100 } 101 } 102 if ($ntypeid === false) { 103 $ntypeid = $DB->get_field('lti_types_config', 104 'typeid', 105 array(), 106 IGNORE_MULTIPLE); 107 108 } 109 if ($ntypeid === false) { 110 $ntypeid = 0; 111 } 112 $data['typeid'] = $ntypeid; 113 } 114 if (empty($data['servicesalt'])) { 115 $data['servicesalt'] = uniqid('', true); 116 } 117 foreach ($data as $field => $value) { 118 if (!in_array($field, $ignorefields)) { 119 $this->xmlwriter->full_tag($field, $value); 120 } 121 } 122 123 return $data; 124 } 125 126 /** 127 * This is executed when we reach the closing </MOD> tag of our 'lti' path 128 */ 129 public function on_basiclti_end() { 130 // Finish writing basiclti.xml. 131 $this->xmlwriter->end_tag('lti'); 132 $this->xmlwriter->end_tag('activity'); 133 $this->close_xml_writer(); 134 135 // Write inforef.xml. 136 $this->open_xml_writer("activities/lti_{$this->moduleid}/inforef.xml"); 137 $this->xmlwriter->begin_tag('inforef'); 138 $this->xmlwriter->begin_tag('fileref'); 139 foreach ($this->fileman->get_fileids() as $fileid) { 140 $this->write_xml('file', array('id' => $fileid)); 141 } 142 $this->xmlwriter->end_tag('fileref'); 143 $this->xmlwriter->end_tag('inforef'); 144 $this->close_xml_writer(); 145 } 146 147 } 148
title
Description
Body
title
Description
Body
title
Description
Body
title
Body