|
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/>. 00023 defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.'); 00024 00025 class cc11_lti extends entities11 { 00026 00027 public function generate_node () { 00028 00029 cc2moodle::log_action('Creating BasicLTI mods'); 00030 00031 $response = ''; 00032 00033 if (!empty(cc2moodle::$instances['instances'][MOODLE_TYPE_LTI])) { 00034 foreach (cc2moodle::$instances['instances'][MOODLE_TYPE_LTI] as $instance) { 00035 $response .= $this->create_node_course_modules_mod_basiclti($instance); 00036 } 00037 } 00038 00039 return $response; 00040 } 00041 00042 private function create_node_course_modules_mod_basiclti ($instance) { 00043 00044 $sheet_mod_basiclti = cc112moodle::loadsheet(SHEET_COURSE_SECTIONS_SECTION_MODS_MOD_LTI); 00045 00046 $topic_data = $this->get_basiclti_data($instance); 00047 00048 $result = ''; 00049 if (!empty($topic_data)) { 00050 00051 $find_tags = array('[#mod_instance#]' , 00052 '[#mod_basiclti_name#]' , 00053 '[#mod_basiclti_intro#]' , 00054 '[#mod_basiclti_timec#]' , 00055 '[#mod_basiclti_timem#]' , 00056 '[#mod_basiclti_toolurl#]', 00057 '[#mod_basiclti_icon#]' 00058 ); 00059 00060 $replace_values = array($instance['instance'], 00061 $topic_data['title'], 00062 $topic_data['description'], 00063 time(),time(), 00064 $topic_data['launchurl'], 00065 $topic_data['icon'] 00066 ); 00067 00068 $result = str_replace($find_tags, $replace_values, $sheet_mod_basiclti); 00069 00070 } 00071 00072 return $result; 00073 } 00074 00075 protected function getValue($node, $default = '') { 00076 $result = $default; 00077 if (is_object($node) && ($node->length > 0) && !empty($node->item(0)->nodeValue)) { 00078 $result = htmlspecialchars(trim($node->item(0)->nodeValue), ENT_COMPAT, 'UTF-8', false); 00079 } 00080 return $result; 00081 } 00082 00083 public function get_basiclti_data($instance) { 00084 00085 $topic_data = ''; 00086 00087 $basiclti_file = $this->get_external_xml($instance['resource_indentifier']); 00088 00089 if (!empty($basiclti_file)) { 00090 $basiclti_file_path = cc2moodle::$path_to_manifest_folder . DIRECTORY_SEPARATOR . $basiclti_file; 00091 $basiclti_file_dir = dirname($basiclti_file_path); 00092 $basiclti = $this->load_xml_resource($basiclti_file_path); 00093 if (!empty($basiclti)) { 00094 $xpath = cc2moodle::newx_path($basiclti, cc112moodle::$basicltins); 00095 $topic_title = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:title'),'Untitled'); 00096 $blti_description = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:description')); 00097 $launch_url = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:launch_url')); 00098 $launch_icon = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:icon')); 00099 $tool_raw = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:vendor/lticp:code'),null); 00100 $tool_url = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:vendor/lticp:url'),null); 00101 $tool_desc = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:vendor/lticp:description'),null); 00102 $topic_data['title' ] = $topic_title; 00103 $topic_data['description'] = $blti_description; 00104 $topic_data['launchurl' ] = $launch_url; 00105 $topic_data['icon' ] = $launch_icon; 00106 $topic_data['orgid' ] = $tool_raw; 00107 $topic_data['orgurl' ] = $tool_url; 00108 $topic_data['orgdesc' ] = $tool_desc; 00109 } 00110 } 00111 00112 return $topic_data; 00113 } 00114 00115 } 00116