ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilSCORMResource.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24require_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMObject.php");
25require_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMResourceFile.php");
26require_once("./Modules/ScormAicc/classes/SCORM/class.ilSCORMResourceDependency.php");
27
37{
38 public $import_id;
40 public $scormtype;
41 public $href;
42 public $xml_base;
43 public $files;
45
46
53 public function __construct($a_id = 0)
54 {
55 $this->files = array();
56 $this->dependencies = array();
57 $this->setType("sre");
58 parent::__construct($a_id);
59 }
60
61 public function getImportId()
62 {
63 return $this->import_id;
64 }
65
66 public function setImportId($a_import_id)
67 {
68 $this->import_id = $a_import_id;
69 }
70
71 public function getResourceType()
72 {
74 }
75
76 public function setResourceType($a_type)
77 {
78 $this->resourcetype = $a_type;
79 }
80
81 public function getScormType()
82 {
83 return $this->scormtype;
84 }
85
86 public function setScormType($a_scormtype)
87 {
88 $this->scormtype = $a_scormtype;
89 }
90
91 public function getHRef()
92 {
93 return $this->href;
94 }
95
96 public function setHRef($a_href)
97 {
98 $this->href = $a_href;
99 $this->setTitle($a_href);
100 }
101
102 public function getXmlBase()
103 {
104 return $this->xml_base;
105 }
106
107 public function setXmlBase($a_xml_base)
108 {
109 $this->xml_base = $a_xml_base;
110 }
111
112 public function addFile(&$a_file_obj)
113 {
114 $this->files[] =&$a_file_obj;
115 }
116
117 public function &getFiles()
118 {
119 return $this->files;
120 }
121
122 public function addDependency(&$a_dependency)
123 {
124 $this->dependencies[] =&$a_dependency;
125 }
126
127 public function &getDependencies()
128 {
129 return $this->dependencies;
130 }
131
132 public function read()
133 {
134 global $ilDB;
135
136 parent::read();
137
138 $obj_set = $ilDB->queryF(
139 'SELECT * FROM sc_resource WHERE obj_id = %s',
140 array('integer'),
141 array($this->getId())
142 );
143 $obj_rec = $ilDB->fetchAssoc($obj_set);
144 $this->setImportId($obj_rec["import_id"]);
145 $this->setResourceType($obj_rec["resourcetype"]);
146 $this->setScormType($obj_rec["scormtype"]);
147 $this->setHRef($obj_rec["href"]);
148 $this->setXmlBase($obj_rec["xml_base"]);
149
150 // read files
151 $file_set = $ilDB->queryF(
152 'SELECT href FROM sc_resource_file WHERE res_id = %s ORDER BY nr',
153 array('integer'),
154 array($this->getId())
155 );
156 while ($file_rec =$ilDB->fetchAssoc($file_set)) {
157 $res_file = new ilSCORMResourceFile();
158 $res_file->setHref($file_rec["href"]);
159 $this->addFile($res_file);
160 }
161 // read dependencies
162
163 $dep_set = $ilDB->queryF(
164 'SELECT identifierref FROM sc_resource_dependen WHERE res_id = %s ORDER BY nr',
165 array('integer'),
166 array($this->getId())
167 );
168 while ($dep_rec =$ilDB->fetchAssoc($dep_set)) {
169 $res_dep = new ilSCORMResourceDependency();
170 $res_dep->setIdentifierRef($dep_rec["identifierref"]);
171 $this->addDependency($res_dep);
172 }
173 }
174
175 public function readByIdRef($a_id_ref, $a_slm_id)
176 {
177 global $ilBench, $ilDB;
178
179 $ilBench->start("SCORMResource", "readByIdRef_Query");
180
181 $id_set = $ilDB->queryF(
182 'SELECT ob.obj_id id FROM sc_resource res, scorm_object ob
183 WHERE ob.obj_id = res.obj_id
184 AND res.import_id = %s
185 AND ob.slm_id = %s',
186 array('text', 'integer'),
187 array($a_id_ref, $a_slm_id)
188 );
189
190 $ilBench->stop("SCORMResource", "readByIdRef_Query");
191
192 if ($id_rec = $ilDB->fetchAssoc($id_set)) {
193 $this->setId($id_rec["id"]);
194 $this->read();
195 }
196 }
197
198 public static function _lookupIdByIdRef($a_id_ref, $a_slm_id)
199 {
200 global $ilBench, $ilDB;
201
202 $id_set = $ilDB->queryF(
203 'SELECT ob.obj_id id FROM sc_resource res, scorm_object ob
204 WHERE ob.obj_id = res.obj_id
205 AND res.import_id = %s
206 AND ob.slm_id = %s',
207 array('text', 'integer'),
208 array($a_id_ref ,$a_slm_id)
209 );
210
211 if ($id_rec = $ilDB->fetchAssoc($id_set)) {
212 return $id_rec["id"];
213 }
214 return 0;
215 }
216
217 public static function _lookupScormType($a_obj_id)
218 {
219 global $ilDB;
220
221 $st_set = $ilDB->queryF(
222 'SELECT scormtype FROM sc_resource WHERE obj_id = %s',
223 array('integer'),
224 array($a_obj_id)
225 );
226 if ($st_rec = $ilDB->fetchAssoc($st_set)) {
227 return $st_rec["scormtype"];
228 }
229 return "";
230 }
231
232 public function create()
233 {
234 global $ilDB;
235
236 parent::create();
237
238 $ilDB->manipulateF(
239 '
240 INSERT INTO sc_resource
241 (obj_id, import_id, resourcetype, scormtype, href, xml_base)
242 VALUES(%s, %s, %s, %s, %s, %s)',
243 array('integer','text','text','text','text','text'),
244 array( $this->getId(),
245 $this->getImportId(),
246 $this->getResourceType(),
247 $this->getScormType(),
248 $this->getHref(),
249 $this->getXmlBase()
250 )
251 );
252
253 // save files
254 for ($i=0; $i<count($this->files); $i++) {
255 $nextId = $ilDB->nextId('sc_resource_file');
256
257 $ilDB->manipulateF(
258 '
259 INSERT INTO sc_resource_file (id,res_id, href, nr)
260 VALUES(%s, %s, %s, %s)',
261 array('integer', 'integer', 'text', 'integer'),
262 array($nextId, $this->getId(), $this->files[$i]->getHref(), ($i + 1))
263 );
264 }
265
266 // save dependencies
267 for ($i=0; $i<count($this->dependencies); $i++) {
268 $nextId = $ilDB->nextId('sc_resource_dependen');
269
270 $ilDB->manipulateF(
271 '
272 INSERT INTO sc_resource_dependen (id, res_id, identifierref, nr)
273 VALUES(%s, %s, %s, %s)',
274 array('integer', 'integer', 'text', 'integer'),
275 array($nextId, $this->getId(), $this->files[$i]->getHref(), ($i + 1))
276 );
277 }
278 }
279
280 public function update()
281 {
282 global $ilDB;
283
285
286 $ilDB->manipulateF(
287 '
288 UPDATE sc_resource
289 SET import_id = %s,
290 resourcetype = %s,
291 scormtype = %s,
292 href = %s,
293 xml_base = %s
294 WHERE obj_id = %s',
295 array('text', 'text', 'text', 'text', 'text', 'integer'),
296 array( $this->getImportId(),
297 $this->getResourceType(),
298 $this->getScormType(),
299 $this->getHRef(),
300 $this->getXmlBase(),
301 $this->getId())
302 );
303
304 // save files
305 $ilDB->manipulateF(
306 'DELETE FROM sc_resource_file WHERE res_id = %s',
307 array('integer'),
308 array($this->getId())
309 );
310
311 for ($i=0; $i<count($this->files); $i++) {
312 $nextId = $ilDB->nextId('sc_resource_file');
313
314 $ilDB->manipulateF(
315 'INSERT INTO sc_resource_file (id, res_id, href, nr)
316 VALUES (%s, %s, %s, %s)',
317 array('integer', 'integer', 'text', 'integer'),
318 array($nextId, $this->getId(), $this->files[$i]->getHref(), ($i + 1))
319 );
320 }
321
322 // save dependencies
323 $ilDB->manipulateF(
324 'DELETE FROM sc_resource_dependen WHERE res_id = %s',
325 array('integer'),
326 array($this->getId())
327 );
328
329 for ($i = 0; $i < count($this->dependencies); $i++) {
330 $nextId = $ilDB->nextId('sc_resource_dependen');
331
332 $ilDB->manipulateF(
333 '
334 INSERT INTO sc_resource_dependen (id, res_id, identifierref, nr) VALUES
335 (%s, %s, %s, %s) ',
336 array('integer', 'integer', 'text', 'integer'),
337 array($nextId, $this->getId(), $this->dependencies[$i]->getIdentifierRef(), ($i + 1))
338 );
339 }
340 }
341
342 public function delete()
343 {
344 global $ilDB;
345
346 parent::delete();
347
348 $ilDB->manipulateF(
349 'DELETE FROM sc_resource WHERE obj_id = %s',
350 array('integer'),
351 array($this->getId())
352 );
353
354 $ilDB->manipulateF(
355 'DELETE FROM sc_resource_file WHERE res_id = %s',
356 array('integer'),
357 array($this->getId())
358 );
359
360 $ilDB->manipulateF(
361 'DELETE FROM sc_resource_dependen WHERE res_id = %s',
362 array('integer'),
363 array($this->getId())
364 );
365 }
366}
An exception for terminatinating execution or to throw for unit testing.
Parent object for all SCORM objects, that are stored in table scorm_object.
SCORM Resource Dependency, DB accesses are done in ilSCORMResource.
SCORM Resource File, DB accesses are done in ilSCORMResource.
addDependency(&$a_dependency)
setImportId($a_import_id)
update()
Updates database record for SCORM object.
static _lookupIdByIdRef($a_id_ref, $a_slm_id)
static _lookupScormType($a_obj_id)
setScormType($a_scormtype)
readByIdRef($a_id_ref, $a_slm_id)
__construct($a_id=0)
Constructor.
create()
Create database record for SCORM object.
$i
Definition: disco.tpl.php:19
global $ilBench
Definition: ilias.php:18
update($pash, $contents, Config $config)
global $ilDB
$a_type
Definition: workflow.php:92