|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00024 defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.'); 00025 00026 class cc11_basiclti extends entities11 { 00027 00028 public function generate_node () { 00029 00030 cc2moodle::log_action('Creating BasicLTI mods'); 00031 00032 $response = ''; 00033 00034 if (!empty(cc2moodle::$instances['instances'][MOODLE_TYPE_BASICLTI])) { 00035 foreach (cc2moodle::$instances['instances'][MOODLE_TYPE_BASICLTI] as $instance) { 00036 $response .= $this->create_node_course_modules_mod_basiclti($instance); 00037 } 00038 } 00039 00040 return $response; 00041 } 00042 00043 private function create_node_course_modules_mod_basiclti ($instance) { 00044 00045 $sheet_mod_basiclti = cc112moodle::loadsheet(SHEET_COURSE_SECTIONS_SECTION_MODS_MOD_BASICLTI); 00046 00047 $topic_data = $this->get_basiclti_data($instance); 00048 00049 $result = ''; 00050 if (!empty($topic_data)) { 00051 00052 $find_tags = array('[#mod_instance#]' , 00053 '[#mod_basiclti_name#]' , 00054 '[#mod_basiclti_intro#]' , 00055 '[#mod_basiclti_timec#]' , 00056 '[#mod_basiclti_timem#]' , 00057 '[#mod_basiclti_toolurl#]', 00058 '[#mod_basiclti_orgid#]' , 00059 '[#mod_basiclti_orgurl#]' , 00060 '[#mod_basiclti_orgdesc#]' 00061 ); 00062 00063 $replace_values = array($instance['instance'], 00064 $topic_data['title'], 00065 $topic_data['description'], 00066 time(),time(), 00067 $topic_data['launchurl'], 00068 $topic_data['orgid'], 00069 $topic_data['orgurl'], 00070 $topic_data['orgdesc'] 00071 ); 00072 00073 $result = str_replace($find_tags, $replace_values, $sheet_mod_basiclti); 00074 00075 } 00076 00077 return $result; 00078 } 00079 00080 protected function getValue($node, $default = '') { 00081 $result = $default; 00082 if (is_object($node) && ($node->length > 0) && !empty($node->item(0)->nodeValue)) { 00083 $result = htmlspecialchars(trim($node->item(0)->nodeValue), ENT_COMPAT, 'UTF-8', false); 00084 } 00085 return $result; 00086 } 00087 00088 public function get_basiclti_data($instance) { 00089 00090 $topic_data = ''; 00091 00092 $basiclti_file = $this->get_external_xml($instance['resource_indentifier']); 00093 00094 if (!empty($basiclti_file)) { 00095 $basiclti_file_path = cc2moodle::$path_to_manifest_folder . DIRECTORY_SEPARATOR . $basiclti_file; 00096 $basiclti_file_dir = dirname($basiclti_file_path); 00097 $basiclti = $this->load_xml_resource($basiclti_file_path); 00098 if (!empty($basiclti)) { 00099 $xpath = cc2moodle::newx_path($basiclti, cc112moodle::$basicltins); 00100 $topic_title = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:title'),'Untitled'); 00101 $blti_description = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:description')); 00102 $launch_url = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:launch_url')); 00103 $tool_raw = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:vendor/lticp:code'),null); 00104 $tool_url = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:vendor/lticp:url'),null); 00105 $tool_desc = $this->getValue($xpath->query('/xmlns:cartridge_basiclti_link/blti:vendor/lticp:description'),null); 00106 $topic_data['title' ] = $topic_title; 00107 $topic_data['description'] = $blti_description; 00108 $topic_data['launchurl' ] = $launch_url; 00109 $topic_data['orgid' ] = $tool_raw; 00110 $topic_data['orgurl' ] = $tool_url; 00111 $topic_data['orgdesc' ] = $tool_desc; 00112 } 00113 } 00114 00115 return $topic_data; 00116 } 00117 00118 } 00119