ILIAS  release_8 Revision v8.24
class.ilSCORM13MDImporter.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
27{
28 protected \DOMDocument $manifest_dom;
29 protected bool $metadata_found = false;
30 protected array $path = array();
31 protected string $title = ""; // overall title extracted from manifest
32 protected string $description = ""; // overall description extracted from manifest
33
34 public function __construct(\DOMDocument $a_manifest_dom, int $a_obj_id)
35 {
36 $this->manifest_dom = $a_manifest_dom;
37 $path = new DOMXpath($a_manifest_dom);
38 $path->registerNamespace("ims", "http://www.imsproject.org/xsd/imscp_rootv1p1p2");
39 $items = $path->query("//ims:manifest/ims:metadata");
40 if ($items->length == 1) {
41 foreach ($items as $i) {
42 //echo htmlentities($a_manifest_dom->saveXML($i)); exit;
43 parent::__construct($a_manifest_dom->saveXML($i), $a_obj_id, $a_obj_id, ilObject::_lookupType($a_obj_id));
44 $this->metadata_found = true;
45 }
46 }
47 }
48
49 public function setTitle(string $a_val): void
50 {
51 $this->title = ilUtil::stripSlashes($a_val);
52 }
53
54 public function getTitle(): string
55 {
56 return ilUtil::stripSlashes($this->title);
57 }
58
59 public function setDescription(string $a_val): void
60 {
61 $this->description = ilUtil::stripSlashes($a_val);
62 }
63
64 public function getDescription(): string
65 {
66 return ilUtil::stripSlashes($this->description);
67 }
68
69 public function import(): void
70 {
71 if ($this->metadata_found) {
72 $this->startParsing();
73 if ($this->getMDObject() !== null) {
74 $this->getMDObject()->update();
75 }
76 }
77 }
78
83 public function handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs): void
84 {
85 $this->path[] = $a_name;
86
87 if (!$this->getMDParsingStatus()) {
88 return;
89 }
90
91 switch ($a_name) {
92 case 'metadata':
93 $this->md_in_md = true;
94 $this->in_meta_data = true;
95 $this->__pushParent($this->md);
96 break;
97
98 case 'general':
99 $this->md_gen = $this->md->addGeneral();
100 $this->md_gen->save();
101 $this->__pushParent($this->md_gen);
102 break;
103
104 case 'identifier':
105 if ($this->in("general")) {
106 $par = $this->__getParent();
107 $this->md_ide = $par->addIdentifier();
108 $this->md_ide->save();
109 $this->__pushParent($this->md_ide);
110 }
111 break;
112
113 case 'title':
114 // nothing to do here
115 break;
116
117 case 'language':
118 if ($this->in("general")) {
119 $par = $this->__getParent();
120 $this->md_lan = $par->addLanguage();
121 $this->md_lan->save();
122 $this->__pushParent($this->md_lan);
123 }
124 break;
125
126 case 'description':
127 $par = $this->__getParent();
128
129 if (strtolower(get_class($par)) === 'ilmdrights' or
130 strtolower(get_class($par)) === 'ilmdannotation' or
131 strtolower(get_class($par)) === 'ilmdclassification') {
132 // todo
133 // $par->setDescriptionLanguage(new ilMDLanguageItem($a_attribs['Language']));
134 } elseif ($this->in("general")) {
135 $this->md_des = $par->addDescription();
136 $this->md_des->save();
137 $this->__pushParent($this->md_des);
138 }
139 break;
140
141 case 'keyword':
142 if ($this->in("general")) {
143 $par = $this->__getParent();
144 $this->md_key = $par->addKeyword();
145 $this->md_key->save();
146 $this->__pushParent($this->md_key);
147 }
148 break;
149
150 // todo
151 /*case 'Coverage':
152 $par =& $this->__getParent();
153 $par->setCoverageLanguage(new ilMDLanguageItem($a_attribs['Language']));
154 break;*/
155
156 case 'lifeCycle':
157 $par = $this->__getParent();
158 $this->md_lif = $par->addLifecycle();
159 //$this->md_lif->setStatus($a_attribs['Status']);
160 $this->md_lif->save();
161 $this->__pushParent($this->md_lif);
162 break;
163
164 case 'version':
165 // nothing to do here
166 break;
167
168 /*case 'metaMetadata':
169 $par = $this->__getParent();
170 $this->md_met = $par->addMetaMetadata();
171 $this->md_met->setMetaDataScheme($a_attribs['MetadataScheme']);
172 $this->md_met->setLanguage(new ilMDLanguageItem($a_attribs['Language']));
173 $this->md_met->save();
174 $this->__pushParent($this->md_met);
175 break;*/
176
177 // todo
178 /*case 'Contribute':
179 $par =& $this->__getParent();
180 $this->md_con =& $par->addContribute();
181 $this->md_con->setRole($a_attribs['Role']);
182 $this->md_con->save();
183 $this->__pushParent($this->md_con);
184 break;
185
186 case 'Entity':
187 $par =& $this->__getParent();
188
189 if(strtolower(get_class($par)) == 'ilmdcontribute')
190 {
191 $this->md_ent =& $par->addEntity();
192 $this->md_ent->save();
193 $this->__pushParent($this->md_ent);
194 break;
195 }
196 else
197 {
198 // single element in 'Annotation'
199 break;
200 }
201 case 'Date':
202 break;
203
204
205 case 'Technical':
206 $par =& $this->__getParent();
207 $this->md_tec =& $par->addTechnical();
208 $this->md_tec->save();
209 $this->__pushParent($this->md_tec);
210 break;
211
212 case 'Format':
213 $par =& $this->__getParent();
214 $this->md_for =& $par->addFormat();
215 $this->md_for->save();
216 $this->__pushParent($this->md_for);
217 break;
218
219 case 'Size':
220 break;
221
222 case 'Location':
223 $par =& $this->__getParent();
224 $this->md_loc =& $par->addLocation();
225 $this->md_loc->setLocationType($a_attribs['Type']);
226 $this->md_loc->save();
227 $this->__pushParent($this->md_loc);
228 break;
229
230 case 'Requirement':
231 $par =& $this->__getParent();
232 $this->md_req =& $par->addRequirement();
233 $this->md_req->save();
234 $this->__pushParent($this->md_req);
235 break;
236
237 case 'OrComposite':
238 $par =& $this->__getParent();
239 $this->md_orc =& $par->addOrComposite();
240 $this->__pushParent($this->md_orc);
241 break;
242
243 case 'Type':
244 break;
245
246 case 'OperatingSystem':
247 $par =& $this->__getParent();
248 $par->setOperatingSystemName($a_attribs['Name']);
249 $par->setOperatingSystemMinimumVersion($a_attribs['MinimumVersion']);
250 $par->setOperatingSystemMaximumVersion($a_attribs['MaximumVersion']);
251 break;
252
253 case 'Browser':
254 $par =& $this->__getParent();
255 $par->setBrowserName($a_attribs['Name']);
256 $par->setBrowserMinimumVersion($a_attribs['MinimumVersion']);
257 $par->setBrowserMaximumVersion($a_attribs['MaximumVersion']);
258 break;
259
260 case 'InstallationRemarks':
261 $par =& $this->__getParent();
262 $par->setInstallationRemarksLanguage(new ilMDLanguageItem($a_attribs['Language']));
263 break;
264
265 case 'OtherPlatformRequirements':
266 $par =& $this->__getParent();
267 $par->setOtherPlatformRequirementsLanguage(new ilMDLanguageItem($a_attribs['Language']));
268 break;
269
270 case 'Duration':
271 break;
272
273 case 'Educational':
274 $par =& $this->__getParent();
275 $this->md_edu =& $par->addEducational();
276 $this->md_edu->setInteractivityType($a_attribs['InteractivityType']);
277 $this->md_edu->setLearningResourceType($a_attribs['LearningResourceType']);
278 $this->md_edu->setInteractivityLevel($a_attribs['InteractivityLevel']);
279 $this->md_edu->setSemanticDensity($a_attribs['SemanticDensity']);
280 $this->md_edu->setIntendedEndUserRole($a_attribs['IntendedEndUserRole']);
281 $this->md_edu->setContext($a_attribs['Context']);
282 $this->md_edu->setDifficulty($a_attribs['Difficulty']);
283 $this->md_edu->save();
284 $this->__pushParent($this->md_edu);
285 break;
286
287 case 'TypicalAgeRange':
288 $par =& $this->__getParent();
289 $this->md_typ =& $par->addTypicalAgeRange();
290 $this->md_typ->setTypicalAgeRangeLanguage(new ilMDLanguageItem($a_attribs['Language']));
291 $this->md_typ->save();
292 $this->__pushParent($this->md_typ);
293 break;
294
295 case 'TypicalLearningTime':
296 break;
297
298 case 'Rights':
299 $par =& $this->__getParent();
300 $this->md_rig =& $par->addRights();
301 $this->md_rig->setCosts($a_attribs['Cost']);
302 $this->md_rig->setCopyrightAndOtherRestrictions($a_attribs['CopyrightAndOtherRestrictions']);
303 $this->md_rig->save();
304 $this->__pushParent($this->md_rig);
305 break;
306
307 case 'Relation':
308 $par =& $this->__getParent();
309 $this->md_rel =& $par->addRelation();
310 $this->md_rel->setKind($a_attribs['Kind']);
311 $this->md_rel->save();
312 $this->__pushParent($this->md_rel);
313 break;
314
315 case 'Resource':
316 break;
317
318 case 'Identifier_':
319 $par =& $this->__getParent();
320 $this->md_ide_ =& $par->addIdentifier_();
321 $this->md_ide_->setCatalog($a_attribs['Catalog']);
322 $this->md_ide_->setEntry($a_attribs['Entry']);
323 $this->md_ide_->save();
324 $this->__pushParent($this->md_ide_);
325 break;
326
327 case 'Annotation':
328 $par =& $this->__getParent();
329 $this->md_ann =& $par->addAnnotation();
330 $this->md_ann->save();
331 $this->__pushParent($this->md_ann);
332 break;
333
334 case 'Classification':
335 $par =& $this->__getParent();
336 $this->md_cla =& $par->addClassification();
337 $this->md_cla->setPurpose($a_attribs['Purpose']);
338 $this->md_cla->save();
339 $this->__pushParent($this->md_cla);
340 break;
341
342 case 'TaxonPath':
343 $par =& $this->__getParent();
344 $this->md_taxp =& $par->addTaxonPath();
345 $this->md_taxp->save();
346 $this->__pushParent($this->md_taxp);
347 break;
348
349 case 'Source':
350 $par =& $this->__getParent();
351 $par->setSourceLanguage(new ilMDLanguageItem($a_attribs['Language']));
352 break;
353
354 case 'Taxon':
355 $par =& $this->__getParent();
356 $this->md_tax =& $par->addTaxon();
357 $this->md_tax->setTaxonLanguage(new ilMDLanguageItem($a_attribs['Language']));
358 $this->md_tax->setTaxonId($a_attribs['Id']);
359 $this->md_tax->save();
360 $this->__pushParent($this->md_tax);
361 break;
362 */
363
364 case 'string':
365 $par = $this->__getParent();
366 if ($this->in("general")) {
367 if ($this->in("title")) {
368 $par->setTitleLanguage(new ilMDLanguageItem($a_attribs['language']));
369 $par->update();
370 } elseif ($this->in("description")) {
371 $this->md_des->setDescriptionLanguage(new ilMDLanguageItem($a_attribs['language']));
372 $this->md_des->update();
373 } elseif ($this->in("keyword")) {
374 $this->md_key->setKeywordLanguage(new ilMDLanguageItem($a_attribs['language']));
375 $this->md_key->update();
376 }
377 }
378 if ($this->in("lifeCycle")) {
379 if ($this->in("version")) {
380 $par->setVersionLanguage(new ilMDLanguageItem($a_attribs['language']));
381 }
382 }
383
384 break;
385
386 }
387 }
388
393 public function handlerEndTag($a_xml_parser, string $a_name): void
394 {
395 //echo "<br>End TAG: ".$a_name;
396 unset($this->path[count($this->path) - 1]);
397
398 if (!$this->getMDParsingStatus()) {
399 return;
400 }
401 switch ($a_name) {
402 case 'metadata':
403 $this->md_parent = array();
404 $this->md_in_md = false;
405 $this->in_meta_data = false;
406 break;
407
408 case 'general':
409 $par = $this->__getParent();
410 $par->update();
411 $this->__popParent();
412 break;
413
414 case 'identifier':
415 if ($this->in("general")) {
416 $par = $this->__getParent();
417 $par->update();
418 $this->__popParent();
419 }
420 break;
421
422 case 'title':
423 // nothing to do here
424 break;
425
426 case 'language':
427 if ($this->in("general")) {
428 $par = $this->__getParent();
429 $par->setLanguage(new ilMDLanguageItem($this->__getCharacterData()));
430 $par->update();
431 $this->__popParent();
432 }
433 break;
434
435 case 'description':
436 $par = $this->__getParent();
437 if (strtolower(get_class($par)) === 'ilmddescription') {
438 $this->__popParent();
439 break;
440 }
441
442 // todo
443 // $par->setDescription($this->__getCharacterData());
444 break;
445
446 case 'keyword':
447 if ($this->in("general")) {
448 $this->__popParent();
449 }
450 break;
451
452 // todo
453 /*case 'Coverage':
454 $par =& $this->__getParent();
455 $par->setCoverage($this->__getCharacterData());
456 break;*/
457
458 case 'lifeCycle':
459 $par = $this->__getParent();
460 $par->update();
461 $this->__popParent();
462 break;
463
464 case 'version':
465 // nothing to do here
466 break;
467
468
469 // todo
470 /*case 'Contribute':
471 $par =& $this->__getParent();
472 $par->update();
473 $this->__popParent();
474 break;
475
476 case 'Entity':
477 $par =& $this->__getParent();
478
479 if(strtolower(get_class($par)) == 'ilmdentity')
480 {
481 $par->setEntity($this->__getCharacterData());
482 $par->update();
483 $this->__popParent();
484 }
485 else
486 {
487 // Single element in 'Annotation'
488 $par->setEntity($this->__getCharacterData());
489 }
490 break;
491
492 case 'Date':
493 $par =& $this->__getParent();
494 $par->setDate($this->__getCharacterData());
495 break;
496
497 case 'Meta-Metadata':
498 $par =& $this->__getParent();
499 $par->update();
500 $this->__popParent();
501 break;
502
503 case 'Technical':
504 $par =& $this->__getParent();
505 $par->update();
506 $this->__popParent();
507 break;
508
509 case 'Format':
510 $par =& $this->__getParent();
511 $par->setFormat($this->__getCharacterData());
512 $par->update();
513 $this->__popParent();
514 break;
515
516 case 'Size':
517 $par =& $this->__getParent();
518 $par->setSize($this->__getCharacterData());
519 break;
520
521 case 'Location':
522 $par =& $this->__getParent();
523 $par->setLocation($this->__getCharacterData());
524 $par->update();
525 $this->__popParent();
526 break;
527
528 case 'Requirement':
529 $par =& $this->__getParent();
530 $par->update();
531 $this->__popParent();
532 break;
533
534 case 'OrComposite':
535 $this->__popParent();
536 break;
537
538 case 'Type':
539 break;
540
541 case 'OperatingSystem':
542 break;
543
544 case 'Browser':
545 break;
546
547 case 'InstallationRemarks':
548 $par =& $this->__getParent();
549 $par->setInstallationRemarks($this->__getCharacterData());
550 break;
551
552 case 'OtherPlatformRequirements':
553 $par =& $this->__getParent();
554 $par->setOtherPlatformRequirements($this->__getCharacterData());
555 break;
556
557 case 'Duration':
558 $par =& $this->__getParent();
559 $par->setDuration($this->__getCharacterData());
560 break;
561
562 case 'Educational':
563 $par =& $this->__getParent();
564 $par->update();
565 $this->__popParent();
566 break;
567
568 case 'TypicalAgeRange':
569 $par =& $this->__getParent();
570 $par->setTypicalAgeRange($this->__getCharacterData());
571 $par->update();
572 $this->__popParent();
573 break;
574
575 case 'TypicalLearningTime':
576 $par =& $this->__getParent();
577 $par->setTypicalLearningTime($this->__getCharacterData());
578 break;
579
580 case 'Rights':
581 $par =& $this->__getParent();
582 $par->update();
583 $this->__popParent();
584 break;
585
586 case 'Relation':
587 $par =& $this->__getParent();
588 $par->update();
589 $this->__popParent();
590 break;
591
592 case 'Resource':
593 break;
594
595 case 'Identifier_':
596 $par =& $this->__getParent();
597 $par->update();
598 $this->__popParent();
599 break;
600
601 case 'Annotation':
602 $par =& $this->__getParent();
603 $par->update();
604 $this->__popParent();
605 break;
606
607 case 'Classification':
608 $par =& $this->__getParent();
609 $par->update();
610 $this->__popParent();
611 break;
612
613 case 'TaxonPath':
614 $par =& $this->__getParent();
615 $par->update();
616 $this->__popParent();
617 break;
618
619 case 'Taxon':
620 $par =& $this->__getParent();
621 $par->setTaxon($this->__getCharacterData());
622 $par->update();
623 $this->__popParent();
624 break;
625
626 case 'Source':
627 $par =& $this->__getParent();
628 $par->setSource($this->__getCharacterData());
629 break;
630 */
631
632 case 'string':
633 $par = $this->__getParent();
634 if ($this->in("general")) {
635 if ($this->in("title")) {
636 // set packaget title to first title
637 if ($this->getTitle() == "") {
638 $this->setTitle($this->__getCharacterData());
639 }
640
641 // parent is General here
642 $par->setTitle($this->__getCharacterData());
643 $par->update();
644 //echo "<br>setTitle (".get_class($par)."): ".$this->__getCharacterData();
645 }
646 if ($this->in("description")) {
647 // set packaget title to first title
648 if ($this->getDescription() == "") {
649 $this->setDescription($this->__getCharacterData());
650 }
651
652 $this->md_des->setDescription($this->__getCharacterData());
653 $this->md_des->update();
654 }
655 if ($this->in("keyword")) {
656 $par->setKeyword($this->__getCharacterData());
657 $par->update();
658 }
659 }
660 if ($this->in("lifeCycle")) {
661 if ($this->in("version")) {
662 $par->setVersion($this->__getCharacterData());
663 }
664 }
665 break;
666
667 case 'value':
668 $par = $this->__getParent();
669 if ($this->in("general")) {
670 if ($this->in("structure")) {
671 $map = array(
672 "atomic" => "Atomic",
673 "collection" => "Collection",
674 "networked" => "Networked",
675 "linear" => "Linear",
676 "hierarchical" => "Hierarchical"
677 );
678 if (isset($map[$this->__getCharacterData()])) {
679 // parent is General here
680 $par->setStructure($map[$this->__getCharacterData()]);
681 $par->update();
682 }
683 }
684 }
685 if ($this->in("lifeCycle")) {
686 if ($this->in("status")) {
687 $map = array(
688 "draft" => "Draft",
689 "revised" => "Revised",
690 "unavailable" => "Unavailable",
691 "final" => "Final"
692 );
693 if (isset($map[$this->__getCharacterData()])) {
694 $this->md_lif->setStatus($map[$this->__getCharacterData()]);
695 $this->md_lif->update();
696 }
697 }
698 }
699 break;
700
701 case 'catalog':
702 if ($this->in("identifier")) {
703 $this->md_ide->setCatalog($this->__getCharacterData());
704 $this->md_ide->update();
705 }
706 break;
707
708 case 'entry':
709 if ($this->in("identifier")) {
710 $this->md_ide->setEntry($this->__getCharacterData());
711 $this->md_ide->update();
712 }
713 break;
714
715 }
716 $this->md_chr_data = '';
717 }
718
719 public function in(string $a_name): bool
720 {
721 // echo "<br>"; var_dump($this->path);
722 if (in_array($a_name, $this->path)) {
723 return true;
724 }
725 return false;
726 }
727}
__pushParent(object $md_obj)
startParsing()
stores xml data in array
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(\DOMDocument $a_manifest_dom, int $a_obj_id)
handlerEndTag($a_xml_parser, string $a_name)
handler for end of element
handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs)
handler for begin of element
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
$i
Definition: metadata.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc