1 |
efrain |
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 |
* @package backup-convert
|
|
|
18 |
* @copyright 2011 Darko Miletic <dmiletic@moodlerooms.com>
|
|
|
19 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
20 |
*/
|
|
|
21 |
|
|
|
22 |
require_once 'cc_general.php';
|
|
|
23 |
|
|
|
24 |
class basicltil1_resurce_file extends general_cc_file {
|
|
|
25 |
const deafultname = 'basiclti.xml';
|
|
|
26 |
|
|
|
27 |
protected $rootns = 'xmlns';
|
|
|
28 |
protected $rootname = 'cartridge_basiclti_link';
|
|
|
29 |
protected $ccnamespaces = array('xmlns' => 'http://www.imsglobal.org/xsd/imslticc_v1p0',
|
|
|
30 |
'blti' => 'http://www.imsglobal.org/xsd/imsbasiclti_v1p0',
|
|
|
31 |
'lticm' => 'http://www.imsglobal.org/xsd/imslticm_v1p0',
|
|
|
32 |
'lticp' => 'http://www.imsglobal.org/xsd/imslticp_v1p0',
|
|
|
33 |
'xsi' => 'http://www.w3.org/2001/XMLSchema-instance');
|
|
|
34 |
protected $ccnsnames = array('xmlns' => 'http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticc_v1p0.xsd',
|
|
|
35 |
'blti' => 'http://www.imsglobal.org/xsd/lti/ltiv1p0/imsbasiclti_v1p0p1.xsd',
|
|
|
36 |
'lticm' => 'http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticm_v1p0.xsd',
|
|
|
37 |
'lticp' => 'http://www.imsglobal.org/xsd/lti/ltiv1p0/imslticp_v1p0.xsd');
|
|
|
38 |
|
|
|
39 |
protected $title = 'Untitled';
|
|
|
40 |
protected $description = 'description';
|
|
|
41 |
protected $custom_properties = array();
|
|
|
42 |
protected $extension_properties = array();
|
|
|
43 |
protected $extension_platform = null;
|
|
|
44 |
protected $launch_url = null;
|
|
|
45 |
protected $secure_launch_url = null;
|
|
|
46 |
protected $icon = null;
|
|
|
47 |
protected $secure_icon = null;
|
|
|
48 |
protected $vendor = false;
|
|
|
49 |
protected $vendor_code = 'I';
|
|
|
50 |
protected $vendor_name = null;
|
|
|
51 |
protected $vendor_description = null;
|
|
|
52 |
protected $vendor_url = null;
|
|
|
53 |
protected $vendor_contact = null;
|
|
|
54 |
protected $cartridge_bundle = null;
|
|
|
55 |
protected $cartridge_icon = null;
|
|
|
56 |
|
|
|
57 |
public function set_title($title) {
|
|
|
58 |
$this->title = self::safexml($title);
|
|
|
59 |
}
|
|
|
60 |
public function set_description($description) {
|
|
|
61 |
$this->description = self::safexml($description);
|
|
|
62 |
}
|
|
|
63 |
public function set_launch_url($url) {
|
|
|
64 |
$this->launch_url = $url;
|
|
|
65 |
}
|
|
|
66 |
public function set_secure_launch_url($url) {
|
|
|
67 |
$this->secure_launch_url = $url;
|
|
|
68 |
}
|
|
|
69 |
public function set_launch_icon($icon) {
|
|
|
70 |
$this->icon = $icon;
|
|
|
71 |
}
|
|
|
72 |
public function set_secure_launch_icon($icon) {
|
|
|
73 |
$this->secure_icon = $icon;
|
|
|
74 |
}
|
|
|
75 |
public function set_vendor_code($code) {
|
|
|
76 |
$this->vendor_code = $code;
|
|
|
77 |
$this->vendor = true;
|
|
|
78 |
}
|
|
|
79 |
public function set_vendor_name($name) {
|
|
|
80 |
$this->vendor_name = self::safexml($name);
|
|
|
81 |
$this->vendor = true;
|
|
|
82 |
}
|
|
|
83 |
public function set_vendor_description($desc) {
|
|
|
84 |
$this->vendor_description = self::safexml($desc);
|
|
|
85 |
$this->vendor = true;
|
|
|
86 |
}
|
|
|
87 |
public function set_vendor_url($url) {
|
|
|
88 |
$this->vendor_url = $url;
|
|
|
89 |
$this->vendor = true;
|
|
|
90 |
}
|
|
|
91 |
public function set_vendor_contact($email) {
|
|
|
92 |
$this->vendor_contact = array('email' => $email);
|
|
|
93 |
$this->vendor = true;
|
|
|
94 |
}
|
|
|
95 |
public function add_custom_property($property, $value) {
|
|
|
96 |
$this->custom_properties[$property] = $value;
|
|
|
97 |
}
|
|
|
98 |
public function add_extension($extension, $value) {
|
|
|
99 |
$this->extension_properties[$extension] = $value;
|
|
|
100 |
}
|
|
|
101 |
public function set_extension_platform($value) {
|
|
|
102 |
$this->extension_platform = $value;
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
public function set_cartridge_bundle($value) {
|
|
|
106 |
$this->cartridge_bundle = $value;
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
public function set_cartridge_icon($value) {
|
|
|
110 |
$this->cartridge_icon = $value;
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
protected function on_save() {
|
|
|
114 |
//this has to be done like this since order of apearance of the tags is also mandatory
|
|
|
115 |
//and specified in basiclti schema files
|
|
|
116 |
|
|
|
117 |
//main items
|
|
|
118 |
$rns = $this->ccnamespaces['blti'];
|
|
|
119 |
$this->append_new_element_ns($this->root, $rns, 'title' , $this->title );
|
|
|
120 |
$this->append_new_element_ns($this->root, $rns, 'description', $this->description);
|
|
|
121 |
|
|
|
122 |
//custom properties
|
|
|
123 |
if (!empty($this->custom_properties)) {
|
|
|
124 |
$custom = $this->append_new_element_ns($this->root, $rns, 'custom');
|
|
|
125 |
foreach ($this->custom_properties as $property => $value) {
|
|
|
126 |
$node = $this->append_new_element_ns($custom, $this->ccnamespaces['lticm'], 'property' , $value);
|
|
|
127 |
$this->append_new_attribute_ns($node, $this->ccnamespaces['xmlns'],'name', $property);
|
|
|
128 |
}
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
//extension properties
|
|
|
132 |
if (!empty($this->extension_properties)) {
|
|
|
133 |
$extension = $this->append_new_element_ns($this->root, $rns, 'extensions');
|
|
|
134 |
if (!empty($this->extension_platform)) {
|
|
|
135 |
$this->append_new_attribute_ns($extension, $this->ccnamespaces['xmlns'], 'platform', $this->extension_platform);
|
|
|
136 |
}
|
|
|
137 |
foreach ($this->extension_properties as $property => $value) {
|
|
|
138 |
$node = $this->append_new_element_ns($extension, $this->ccnamespaces['lticm'], 'property' , $value);
|
|
|
139 |
$this->append_new_attribute_ns($node, $this->ccnamespaces['xmlns'], 'name', $property);
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
$this->append_new_element_ns($this->root, $rns, 'launch_url' , $this->launch_url );
|
|
|
144 |
if (!empty($this->secure_launch_url)) {
|
|
|
145 |
$this->append_new_element_ns($this->root, $rns, 'secure_launch_url' , $this->secure_launch_url);
|
|
|
146 |
}
|
|
|
147 |
$this->append_new_element_ns($this->root, $rns, 'icon' , $this->icon );
|
|
|
148 |
if (!empty($this->secure_icon)) {
|
|
|
149 |
$this->append_new_element_ns($this->root, $rns, 'secure_icon' , $this->secure_icon);
|
|
|
150 |
}
|
|
|
151 |
|
|
|
152 |
//vendor info
|
|
|
153 |
$vendor = $this->append_new_element_ns($this->root, $rns, 'vendor');
|
|
|
154 |
$vcode = empty($this->vendor_code) ? 'I' : $this->vendor_code;
|
|
|
155 |
$this->append_new_element_ns($vendor, $this->ccnamespaces['lticp'], 'code', $vcode);
|
|
|
156 |
$this->append_new_element_ns($vendor, $this->ccnamespaces['lticp'], 'name', $this->vendor_name);
|
|
|
157 |
if (!empty($this->vendor_description)) {
|
|
|
158 |
$this->append_new_element_ns($vendor, $this->ccnamespaces['lticp'], 'description', $this->vendor_description);
|
|
|
159 |
}
|
|
|
160 |
if (!empty($this->vendor_url)) {
|
|
|
161 |
$this->append_new_element_ns($vendor, $this->ccnamespaces['lticp'], 'url', $this->vendor_url);
|
|
|
162 |
}
|
|
|
163 |
if (!empty($this->vendor_contact)) {
|
|
|
164 |
$vcontact = $this->append_new_element_ns($vendor, $this->ccnamespaces['lticp'], 'contact');
|
|
|
165 |
$this->append_new_element_ns($vcontact, $this->ccnamespaces['lticp'], 'email', $this->vendor_contact['email']);
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
//cartridge bundle and icon
|
|
|
169 |
if (!empty($this->cartridge_bundle)) {
|
|
|
170 |
$cbundle = $this->append_new_element_ns($this->root, $this->ccnamespaces['xmlns'], 'cartridge_bundle');
|
|
|
171 |
$this->append_new_attribute_ns($cbundle, $this->ccnamespaces['xmlns'], 'identifierref', $this->cartridge_bundle);
|
|
|
172 |
}
|
|
|
173 |
if (!empty($this->cartridge_icon)) {
|
|
|
174 |
$cicon = $this->append_new_element_ns($this->root, $this->ccnamespaces['xmlns'], 'cartridge_icon');
|
|
|
175 |
$this->append_new_attribute_ns($cicon, $this->ccnamespaces['xmlns'], 'identifierref', $this->cartridge_icon);
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
return true;
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
}
|