|
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/>. 00022 require_once 'cc_general.php'; 00023 00024 class basicltil1_resurce_file extends general_cc_file { 00025 const deafultname = 'basiclti.xml'; 00026 00027 protected $rootns = 'xmlns'; 00028 protected $rootname = 'cartridge_basiclti_link'; 00029 protected $ccnamespaces = array('xmlns' => 'http://www.imsglobal.org/xsd/imslticc_v1p0', 00030 'blti' => 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0', 00031 'lticm' => 'http://www.imsglobal.org/xsd/imslticm_v1p0', 00032 'lticp' => 'http://www.imsglobal.org/xsd/imslticp_v1p0', 00033 'xsi' => 'http://www.w3.org/2001/XMLSchema-instance'); 00034 protected $ccnsnames = array('xmlns' => 'http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticc_v1p0.xsd', 00035 'blti' => 'http://www.imsglobal.org/xsd/lti/ltiv1p0/imsbasiclti_v1p0p1.xsd', 00036 'lticm' => 'http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticm_v1p0.xsd', 00037 'lticp' => 'http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticp_v1p0.xsd'); 00038 00039 protected $title = 'Untitled'; 00040 protected $description = 'description'; 00041 protected $custom_properties = array(); 00042 protected $extension_properties = array(); 00043 protected $extension_platform = null; 00044 protected $launch_url = null; 00045 protected $secure_launch_url = null; 00046 protected $icon = null; 00047 protected $secure_icon = null; 00048 protected $vendor = false; 00049 protected $vendor_code = 'I'; 00050 protected $vendor_name = null; 00051 protected $vendor_description = null; 00052 protected $vendor_url = null; 00053 protected $vendor_contact = null; 00054 protected $cartridge_bundle = null; 00055 protected $cartridge_icon = null; 00056 00057 public function set_title($title) { 00058 $this->title = self::safexml($title); 00059 } 00060 public function set_description($description) { 00061 $this->description = self::safexml($description); 00062 } 00063 public function set_launch_url ($url) { 00064 $this->launch_url = $url; 00065 } 00066 public function set_secure_launch_url ($url) { 00067 $this->secure_launch_url = $url; 00068 } 00069 public function set_launch_icon ($icon) { 00070 $this->icon = $icon; 00071 } 00072 public function set_secure_launch_icon ($icon) { 00073 $this->secure_icon = $icon; 00074 } 00075 public function set_vendor_code ($code) { 00076 $this->vendor_code = $code; 00077 $this->vendor = true; 00078 } 00079 public function set_vendor_name ($name) { 00080 $this->vendor_name = self::safexml($name); 00081 $this->vendor = true; 00082 } 00083 public function set_vendor_description ($desc) { 00084 $this->vendor_description = self::safexml($desc); 00085 $this->vendor = true; 00086 } 00087 public function set_vendor_url ($url) { 00088 $this->vendor_url = $url; 00089 $this->vendor = true; 00090 } 00091 public function set_vendor_contact ($email) { 00092 $this->vendor_contact = array('email' => $email); 00093 $this->vendor = true; 00094 } 00095 public function add_custom_property ($property, $value) { 00096 $this->custom_properties[$property] = $value; 00097 } 00098 public function add_extension ($extension, $value) { 00099 $this->extension_properties[$extension] = $value; 00100 } 00101 public function set_extension_platform ($value) { 00102 $this->extension_platform = $value; 00103 } 00104 00105 public function set_cartridge_bundle($value) { 00106 $this->cartridge_bundle = $value; 00107 } 00108 00109 public function set_cartridge_icon($value) { 00110 $this->cartridge_icon = $value; 00111 } 00112 00113 protected function on_save() { 00114 //this has to be done like this since order of apearance of the tags is also mandatory 00115 //and specified in basiclti schema files 00116 00117 //main items 00118 $rns = $this->ccnamespaces['blti']; 00119 $this->append_new_element_ns($this->root, $rns, 'title' , $this->title ); 00120 $this->append_new_element_ns($this->root, $rns, 'description', $this->description); 00121 00122 //custom properties 00123 if (!empty($this->custom_properties)) { 00124 $custom = $this->append_new_element_ns($this->root, $rns, 'custom'); 00125 foreach ($this->custom_properties as $property => $value) { 00126 $node = $this->append_new_element_ns($custom, $this->ccnamespaces['lticm'], 'property' , $value); 00127 $this->append_new_attribute_ns($node, $this->ccnamespaces['xmlns'],'name', $property); 00128 } 00129 } 00130 00131 //extension properties 00132 if (!empty($this->extension_properties)) { 00133 $extension = $this->append_new_element_ns($this->root, $rns, 'extensions'); 00134 if (!empty($this->extension_platform)) { 00135 $this->append_new_attribute_ns($extension, $this->ccnamespaces['xmlns'], 'platform', $this->extension_platform); 00136 } 00137 foreach ($this->extension_properties as $property => $value) { 00138 $node = $this->append_new_element_ns($extension, $this->ccnamespaces['lticm'], 'property' , $value); 00139 $this->append_new_attribute_ns($node, $this->ccnamespaces['xmlns'], 'name', $property); 00140 } 00141 } 00142 00143 $this->append_new_element_ns($this->root, $rns, 'launch_url' , $this->launch_url ); 00144 if (!empty($this->secure_launch_url)) { 00145 $this->append_new_element_ns($this->root, $rns, 'secure_launch_url' , $this->secure_launch_url); 00146 } 00147 $this->append_new_element_ns($this->root, $rns, 'icon' , $this->icon ); 00148 if (!empty($this->secure_icon)) { 00149 $this->append_new_element_ns($this->root, $rns, 'secure_icon' , $this->secure_icon); 00150 } 00151 00152 //vendor info 00153 $vendor = $this->append_new_element_ns($this->root, $rns, 'vendor'); 00154 $vcode = empty($this->vendor_code) ? 'I' : $this->vendor_code; 00155 $this->append_new_element_ns($vendor, $this->ccnamespaces['lticp'], 'code', $vcode); 00156 $this->append_new_element_ns($vendor, $this->ccnamespaces['lticp'], 'name', $this->vendor_name); 00157 if (!empty($this->vendor_description)) { 00158 $this->append_new_element_ns($vendor, $this->ccnamespaces['lticp'], 'description', $this->vendor_description); 00159 } 00160 if (!empty($this->vendor_url)) { 00161 $this->append_new_element_ns($vendor, $this->ccnamespaces['lticp'], 'url', $this->vendor_url); 00162 } 00163 if (!empty($this->vendor_contact)) { 00164 $vcontact = $this->append_new_element_ns($vendor, $this->ccnamespaces['lticp'], 'contact'); 00165 $this->append_new_element_ns($vcontact, $this->ccnamespaces['lticp'], 'email', $this->vendor_contact['email']); 00166 } 00167 00168 //cartridge bundle and icon 00169 if (!empty($this->cartridge_bundle)) { 00170 $cbundle = $this->append_new_element_ns($this->root, $this->ccnamespaces['xmlns'], 'cartridge_bundle'); 00171 $this->append_new_attribute_ns($cbundle, $this->ccnamespaces['xmlns'], 'identifierref', $this->cartridge_bundle); 00172 } 00173 if (!empty($this->cartridge_icon)) { 00174 $cicon = $this->append_new_element_ns($this->root, $this->ccnamespaces['xmlns'], 'cartridge_icon'); 00175 $this->append_new_attribute_ns($cicon, $this->ccnamespaces['xmlns'], 'identifierref', $this->cartridge_icon); 00176 } 00177 00178 return true; 00179 } 00180 00181 }