ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilSCORMResource.php
Go to the documentation of this file.
1 <?php
2 
3 declare(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");
46  parent::__construct($a_id);
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  {
61  return $this->resourcetype;
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 
108  public function &getFiles(): array
109  {
110  return $this->files;
111  }
112 
113  public function addDependency(ilSCORMResourceDependency $a_dependency): void
114  {
115  $this->dependencies[] = &$a_dependency;
116  }
117 
121  public function &getDependencies(): array
122  {
123  return $this->dependencies;
124  }
125 
126  public function read(): void
127  {
128  global $DIC;
129  $ilDB = $DIC->database();
130 
131  parent::read();
132 
133  $obj_set = $ilDB->queryF(
134  'SELECT * FROM sc_resource WHERE obj_id = %s',
135  array('integer'),
136  array($this->getId())
137  );
138  $obj_rec = $ilDB->fetchAssoc($obj_set);
139  $this->setImportId($obj_rec["import_id"]);
140  $this->setResourceType($obj_rec["resourcetype"]);
141  $this->setScormType($obj_rec["scormtype"]);
142  $this->setHRef($obj_rec["href"]);
143  $this->setXmlBase($obj_rec["xml_base"]);
144 
145  // read files
146  $file_set = $ilDB->queryF(
147  'SELECT href FROM sc_resource_file WHERE res_id = %s ORDER BY nr',
148  array('integer'),
149  array($this->getId())
150  );
151  while ($file_rec = $ilDB->fetchAssoc($file_set)) {
152  $res_file = new ilSCORMResourceFile();
153  $res_file->setHref($file_rec["href"]);
154  $this->addFile($res_file);
155  }
156  // read dependencies
157 
158  $dep_set = $ilDB->queryF(
159  'SELECT identifierref FROM sc_resource_dependen WHERE res_id = %s ORDER BY nr',
160  array('integer'),
161  array($this->getId())
162  );
163  while ($dep_rec = $ilDB->fetchAssoc($dep_set)) {
164  $res_dep = new ilSCORMResourceDependency();
165  $res_dep->setIdentifierRef($dep_rec["identifierref"]);
166  $this->addDependency($res_dep);
167  }
168  }
169 
170  public function readByIdRef(string $a_id_ref, int $a_slm_id): void
171  {
172  global $DIC;
173  $ilBench = $DIC['ilBench'];
174  $ilDB = $DIC->database();
175 
176  $ilBench->start("SCORMResource", "readByIdRef_Query");
177 
178  $id_set = $ilDB->queryF(
179  'SELECT ob.obj_id id FROM sc_resource res, scorm_object ob
180  WHERE ob.obj_id = res.obj_id
181  AND res.import_id = %s
182  AND ob.slm_id = %s',
183  array('text', 'integer'),
184  array($a_id_ref, $a_slm_id)
185  );
186 
187  $ilBench->stop("SCORMResource", "readByIdRef_Query");
188 
189  if ($id_rec = $ilDB->fetchAssoc($id_set)) {
190  $this->setId($id_rec["id"]);
191  $this->read();
192  }
193  }
194 
195  public static function _lookupIdByIdRef(string $a_id_ref, int $a_slm_id): int
196  {
197  global $DIC;
198  $ilBench = $DIC['ilBench'];
199  $ilDB = $DIC->database();
200 
201  $id_set = $ilDB->queryF(
202  'SELECT ob.obj_id id FROM sc_resource res, scorm_object ob
203  WHERE ob.obj_id = res.obj_id
204  AND res.import_id = %s
205  AND ob.slm_id = %s',
206  array('text', 'integer'),
207  array($a_id_ref ,$a_slm_id)
208  );
209 
210  if ($id_rec = $ilDB->fetchAssoc($id_set)) {
211  return (int) $id_rec["id"];
212  }
213  return 0;
214  }
215 
216  public static function _lookupScormType(int $a_obj_id): string
217  {
218  global $DIC;
219  $ilDB = $DIC->database();
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 (string) $st_rec["scormtype"];//check UK usually null
228  }
229  return "";
230  }
231 
232  public function create(): void
233  {
234  global $DIC;
235  $ilDB = $DIC->database();
236 
237  parent::create();
238 
239  $ilDB->manipulateF(
240  '
241  INSERT INTO sc_resource
242  (obj_id, import_id, resourcetype, scormtype, href, xml_base)
243  VALUES(%s, %s, %s, %s, %s, %s)',
244  array('integer','text','text','text','text','text'),
245  array( $this->getId(),
246  $this->getImportId(),
247  $this->getResourceType(),
248  $this->getScormType(),
249  $this->getHref(),
250  $this->getXmlBase()
251  )
252  );
253 
254  // save files
255  foreach ($this->files as $i => $value) {
256  $nextId = $ilDB->nextId('sc_resource_file');
257 
258  $ilDB->manipulateF(
259  '
260  INSERT INTO sc_resource_file (id,res_id, href, nr)
261  VALUES(%s, %s, %s, %s)',
262  array('integer', 'integer', 'text', 'integer'),
263  array($nextId, $this->getId(), $value->getHref(), ($i + 1))
264  );
265  }
266 
267  // save dependencies
268  for ($i = 0, $max = count($this->dependencies); $i < $max; $i++) {
269  $nextId = $ilDB->nextId('sc_resource_dependen');
270 
271  $ilDB->manipulateF(
272  '
273  INSERT INTO sc_resource_dependen (id, res_id, identifierref, nr)
274  VALUES(%s, %s, %s, %s)',
275  array('integer', 'integer', 'text', 'integer'),
276  array($nextId, $this->getId(), $this->files[$i]->getHref(), ($i + 1))
277  );
278  }
279  }
280 
281  public function update(): void
282  {
283  global $DIC;
284  $ilDB = $DIC->database();
285 
286  parent::update();
287 
288  $ilDB->manipulateF(
289  '
290  UPDATE sc_resource
291  SET import_id = %s,
292  resourcetype = %s,
293  scormtype = %s,
294  href = %s,
295  xml_base = %s
296  WHERE obj_id = %s',
297  array('text', 'text', 'text', 'text', 'text', 'integer'),
298  array( $this->getImportId(),
299  $this->getResourceType(),
300  $this->getScormType(),
301  $this->getHRef(),
302  $this->getXmlBase(),
303  $this->getId())
304  );
305 
306  // save files
307  $ilDB->manipulateF(
308  'DELETE FROM sc_resource_file WHERE res_id = %s',
309  array('integer'),
310  array($this->getId())
311  );
312 
313  foreach ($this->files as $i => $value) {
314  $nextId = $ilDB->nextId('sc_resource_file');
315 
316  $ilDB->manipulateF(
317  'INSERT INTO sc_resource_file (id, res_id, href, nr)
318  VALUES (%s, %s, %s, %s)',
319  array('integer', 'integer', 'text', 'integer'),
320  array($nextId, $this->getId(), $value->getHref(), ($i + 1))
321  );
322  }
323 
324  // save dependencies
325  $ilDB->manipulateF(
326  'DELETE FROM sc_resource_dependen WHERE res_id = %s',
327  array('integer'),
328  array($this->getId())
329  );
330 
331  foreach ($this->dependencies as $i => $value) {
332  $nextId = $ilDB->nextId('sc_resource_dependen');
333 
334  $ilDB->manipulateF(
335  '
336  INSERT INTO sc_resource_dependen (id, res_id, identifierref, nr) VALUES
337  (%s, %s, %s, %s) ',
338  array('integer', 'integer', 'text', 'integer'),
339  array($nextId, $this->getId(), $value->getIdentifierRef(), ($i + 1))
340  );
341  }
342  }
343 
344  public function delete(): void
345  {
346  global $DIC;
347  $ilDB = $DIC->database();
348 
349  parent::delete();
350 
351  $ilDB->manipulateF(
352  'DELETE FROM sc_resource WHERE obj_id = %s',
353  array('integer'),
354  array($this->getId())
355  );
356 
357  $ilDB->manipulateF(
358  'DELETE FROM sc_resource_file WHERE res_id = %s',
359  array('integer'),
360  array($this->getId())
361  );
362 
363  $ilDB->manipulateF(
364  'DELETE FROM sc_resource_dependen WHERE res_id = %s',
365  array('integer'),
366  array($this->getId())
367  );
368  }
369 }
setType(?string $a_type)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setResourceType(string $a_type)
static _lookupScormType(int $a_obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addFile(ilSCORMResourceFile $a_file_obj)
global $DIC
Definition: feed.php:28
setHRef(?string $a_href)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setScormType(?string $a_scormtype)
setTitle(string $a_title)
addDependency(ilSCORMResourceDependency $a_dependency)
setXmlBase(?string $a_xml_base)
static _lookupIdByIdRef(string $a_id_ref, int $a_slm_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
readByIdRef(string $a_id_ref, int $a_slm_id)
setImportId(string $a_import_id)
$i
Definition: metadata.php:41