ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSCORMResource.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
29{
30 public string $import_id;
31 public string $resourcetype;
32 public ?string $scormtype = null;
33 public ?string $href = null;
34 public ?string $xml_base = null;
35 public array $files;
36 public array $dependencies;
37
41 public function __construct(int $a_id = 0)
42 {
43 $this->files = array();
44 $this->dependencies = array();
45 $this->setType("sre");
47 }
48
49 public function getImportId(): string
50 {
51 return $this->import_id;
52 }
53
54 public function setImportId(string $a_import_id): void
55 {
56 $this->import_id = $a_import_id;
57 }
58
59 public function getResourceType(): string
60 {
62 }
63
64 public function setResourceType(string $a_type): void
65 {
66 $this->resourcetype = $a_type;
67 }
68
69 public function getScormType(): ?string
70 {
71 return $this->scormtype;
72 }
73
74 public function setScormType(?string $a_scormtype): void
75 {
76 $this->scormtype = $a_scormtype;
77 }
78
79 public function getHRef(): ?string
80 {
81 return $this->href;
82 }
83
84 public function setHRef(?string $a_href): void
85 {
86 $this->href = $a_href;
87 $this->setTitle("" . $a_href);
88 }
89
90 public function getXmlBase(): ?string
91 {
92 return $this->xml_base;
93 }
94
95 public function setXmlBase(?string $a_xml_base): void
96 {
97 $this->xml_base = $a_xml_base;
98 }
99
100 public function addFile(ilSCORMResourceFile $a_file_obj): void
101 {
102 $this->files[] = &$a_file_obj;
103 }
104
105 public function &getFiles(): array
106 {
107 return $this->files;
108 }
109
110 public function addDependency(ilSCORMResourceDependency $a_dependency): void
111 {
112 $this->dependencies[] = &$a_dependency;
113 }
114
115 public function &getDependencies(): array
116 {
117 return $this->dependencies;
118 }
119
120 public function read(): void
121 {
122 global $DIC;
123 $ilDB = $DIC->database();
124
125 parent::read();
126
127 $obj_set = $ilDB->queryF(
128 'SELECT * FROM sc_resource WHERE obj_id = %s',
129 array('integer'),
130 array($this->getId())
131 );
132 $obj_rec = $ilDB->fetchAssoc($obj_set);
133 $this->setImportId($obj_rec["import_id"]);
134 $this->setResourceType($obj_rec["resourcetype"]);
135 $this->setScormType($obj_rec["scormtype"]);
136 $this->setHRef($obj_rec["href"]);
137 $this->setXmlBase($obj_rec["xml_base"]);
138
139 // read files
140 $file_set = $ilDB->queryF(
141 'SELECT href FROM sc_resource_file WHERE res_id = %s ORDER BY nr',
142 array('integer'),
143 array($this->getId())
144 );
145 while ($file_rec = $ilDB->fetchAssoc($file_set)) {
146 $res_file = new ilSCORMResourceFile();
147 $res_file->setHref($file_rec["href"]);
148 $this->addFile($res_file);
149 }
150 // read dependencies
151
152 $dep_set = $ilDB->queryF(
153 'SELECT identifierref FROM sc_resource_dependen WHERE res_id = %s ORDER BY nr',
154 array('integer'),
155 array($this->getId())
156 );
157 while ($dep_rec = $ilDB->fetchAssoc($dep_set)) {
158 $res_dep = new ilSCORMResourceDependency();
159 $res_dep->setIdentifierRef($dep_rec["identifierref"]);
160 $this->addDependency($res_dep);
161 }
162 }
163
164 public function readByIdRef(string $a_id_ref, int $a_slm_id): void
165 {
166 global $DIC;
167 $ilBench = $DIC['ilBench'];
168 $ilDB = $DIC->database();
169
170 $ilBench->start("SCORMResource", "readByIdRef_Query");
171
172 $id_set = $ilDB->queryF(
173 'SELECT ob.obj_id id FROM sc_resource res, scorm_object ob
174 WHERE ob.obj_id = res.obj_id
175 AND res.import_id = %s
176 AND ob.slm_id = %s',
177 array('text', 'integer'),
178 array($a_id_ref, $a_slm_id)
179 );
180
181 $ilBench->stop("SCORMResource", "readByIdRef_Query");
182
183 if ($id_rec = $ilDB->fetchAssoc($id_set)) {
184 $this->setId($id_rec["id"]);
185 $this->read();
186 }
187 }
188
189 public static function _lookupIdByIdRef(string $a_id_ref, int $a_slm_id): int
190 {
191 global $DIC;
192 $ilBench = $DIC['ilBench'];
193 $ilDB = $DIC->database();
194
195 $id_set = $ilDB->queryF(
196 'SELECT ob.obj_id id FROM sc_resource res, scorm_object ob
197 WHERE ob.obj_id = res.obj_id
198 AND res.import_id = %s
199 AND ob.slm_id = %s',
200 array('text', 'integer'),
201 array($a_id_ref ,$a_slm_id)
202 );
203
204 if ($id_rec = $ilDB->fetchAssoc($id_set)) {
205 return (int) $id_rec["id"];
206 }
207 return 0;
208 }
209
210 public static function _lookupScormType(int $a_obj_id): string
211 {
212 global $DIC;
213 $ilDB = $DIC->database();
214
215 $st_set = $ilDB->queryF(
216 'SELECT scormtype FROM sc_resource WHERE obj_id = %s',
217 array('integer'),
218 array($a_obj_id)
219 );
220 if ($st_rec = $ilDB->fetchAssoc($st_set)) {
221 return (string) $st_rec["scormtype"];//check UK usually null
222 }
223 return "";
224 }
225
226 public function create(): void
227 {
228 global $DIC;
229 $ilDB = $DIC->database();
230
231 parent::create();
232
233 $ilDB->manipulateF(
234 '
235 INSERT INTO sc_resource
236 (obj_id, import_id, resourcetype, scormtype, href, xml_base)
237 VALUES(%s, %s, %s, %s, %s, %s)',
238 array('integer','text','text','text','text','text'),
239 array( $this->getId(),
240 $this->getImportId(),
241 $this->getResourceType(),
242 $this->getScormType(),
243 $this->getHref(),
244 $this->getXmlBase()
245 )
246 );
247
248 // save files
249 foreach ($this->files as $i => $value) {
250 $nextId = $ilDB->nextId('sc_resource_file');
251
252 $ilDB->manipulateF(
253 '
254 INSERT INTO sc_resource_file (id,res_id, href, nr)
255 VALUES(%s, %s, %s, %s)',
256 array('integer', 'integer', 'text', 'integer'),
257 array($nextId, $this->getId(), $value->getHref(), ($i + 1))
258 );
259 }
260
261 // save dependencies
262 for ($i = 0, $max = count($this->dependencies); $i < $max; $i++) {
263 $nextId = $ilDB->nextId('sc_resource_dependen');
264
265 $ilDB->manipulateF(
266 '
267 INSERT INTO sc_resource_dependen (id, res_id, identifierref, nr)
268 VALUES(%s, %s, %s, %s)',
269 array('integer', 'integer', 'text', 'integer'),
270 array($nextId, $this->getId(), $this->files[$i]->getHref(), ($i + 1))
271 );
272 }
273 }
274
275 public function update(): void
276 {
277 global $DIC;
278 $ilDB = $DIC->database();
279
280 parent::update();
281
282 $ilDB->manipulateF(
283 '
284 UPDATE sc_resource
285 SET import_id = %s,
286 resourcetype = %s,
287 scormtype = %s,
288 href = %s,
289 xml_base = %s
290 WHERE obj_id = %s',
291 array('text', 'text', 'text', 'text', 'text', 'integer'),
292 array( $this->getImportId(),
293 $this->getResourceType(),
294 $this->getScormType(),
295 $this->getHRef(),
296 $this->getXmlBase(),
297 $this->getId())
298 );
299
300 // save files
301 $ilDB->manipulateF(
302 'DELETE FROM sc_resource_file WHERE res_id = %s',
303 array('integer'),
304 array($this->getId())
305 );
306
307 foreach ($this->files as $i => $value) {
308 $nextId = $ilDB->nextId('sc_resource_file');
309
310 $ilDB->manipulateF(
311 'INSERT INTO sc_resource_file (id, res_id, href, nr)
312 VALUES (%s, %s, %s, %s)',
313 array('integer', 'integer', 'text', 'integer'),
314 array($nextId, $this->getId(), $value->getHref(), ($i + 1))
315 );
316 }
317
318 // save dependencies
319 $ilDB->manipulateF(
320 'DELETE FROM sc_resource_dependen WHERE res_id = %s',
321 array('integer'),
322 array($this->getId())
323 );
324
325 foreach ($this->dependencies as $i => $value) {
326 $nextId = $ilDB->nextId('sc_resource_dependen');
327
328 $ilDB->manipulateF(
329 '
330 INSERT INTO sc_resource_dependen (id, res_id, identifierref, nr) VALUES
331 (%s, %s, %s, %s) ',
332 array('integer', 'integer', 'text', 'integer'),
333 array($nextId, $this->getId(), $value->getIdentifierRef(), ($i + 1))
334 );
335 }
336 }
337
338 public function delete(): void
339 {
340 global $DIC;
341 $ilDB = $DIC->database();
342
343 parent::delete();
344
345 $ilDB->manipulateF(
346 'DELETE FROM sc_resource WHERE obj_id = %s',
347 array('integer'),
348 array($this->getId())
349 );
350
351 $ilDB->manipulateF(
352 'DELETE FROM sc_resource_file WHERE res_id = %s',
353 array('integer'),
354 array($this->getId())
355 );
356
357 $ilDB->manipulateF(
358 'DELETE FROM sc_resource_dependen WHERE res_id = %s',
359 array('integer'),
360 array($this->getId())
361 );
362 }
363}
Parent object for all SCORM objects, that are stored in table scorm_object.
setTitle(string $a_title)
setType(?string $a_type)
SCORM Resource Dependency, DB accesses are done in ilSCORMResource.
SCORM Resource File, DB accesses are done in ilSCORMResource.
setImportId(string $a_import_id)
addFile(ilSCORMResourceFile $a_file_obj)
static _lookupIdByIdRef(string $a_id_ref, int $a_slm_id)
readByIdRef(string $a_id_ref, int $a_slm_id)
setScormType(?string $a_scormtype)
setXmlBase(?string $a_xml_base)
update()
Updates database record for SCORM object.
setHRef(?string $a_href)
addDependency(ilSCORMResourceDependency $a_dependency)
static _lookupScormType(int $a_obj_id)
setResourceType(string $a_type)
create()
Create database record for SCORM object.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26