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