scormMetadata.class.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Container for the scormMetadata class, setup to hold information about the <metadata> element in imsmanifest files.
  5. *
  6. * @package chamilo.learnpath.scorm
  7. */
  8. /**
  9. * scormMetadata class, handling each <metadata> element found in an imsmanifest file.
  10. */
  11. class scormMetadata
  12. {
  13. public $lom = '';
  14. public $schema = '';
  15. public $schemaversion = '';
  16. public $location = '';
  17. public $text = '';
  18. public $attribs = [];
  19. /**
  20. * Class constructor. Works in two different ways defined by the first element, being 'db' or 'manifest'.
  21. * If 'db', then it is built using the information available in the Chamilo database. If 'manifest', then it
  22. * is built using the element given as a parameter, expecting it to be a <metadata> element pointer from the
  23. * DOM parser.
  24. *
  25. * @param string Type of creation required. Can be 'db' or 'manifest' (default)
  26. * @param mixed Depending on the type, can be the DB ID of the learnpath item or
  27. * the pointer to the <metadata> element in the imsmanifest.xml file
  28. */
  29. public function __construct($type = 'manifest', &$element)
  30. {
  31. if (isset($element)) {
  32. // Parsing using PHP5 DOMXML methods.
  33. switch ($type) {
  34. case 'db':
  35. // TODO: Implement this way of metadata object creation.
  36. break;
  37. //break;
  38. case 'manifest': // Do the same as the default.
  39. $children = $element->childNodes;
  40. foreach ($children as $child) {
  41. switch ($child->nodeType) {
  42. case XML_ELEMENT_NODE:
  43. // Could be 'lom', 'schema', 'schemaversion' or 'location'.
  44. switch ($child->tagName) {
  45. case 'lom':
  46. $childchildren = $child->childNodes;
  47. foreach ($childchildren as $childchild) {
  48. $this->lom = $childchild->nodeValue;
  49. }
  50. break;
  51. case 'schema':
  52. $childchildren = $child->childNodes;
  53. foreach ($childchildren as $childchild) {
  54. // There is generally only one child here.
  55. $this->schema = $childchild->nodeValue;
  56. }
  57. break;
  58. case 'schemaversion':
  59. $childchildren = $child->childNodes;
  60. foreach ($childchildren as $childchild) {
  61. // There is generally only one child here.
  62. $this->schemaversion = $childchild->nodeValue;
  63. }
  64. break;
  65. case 'location':
  66. $childchildren = $child->childNodes;
  67. foreach ($childchildren as $childchild) {
  68. // There is generally only one child here.
  69. $this->location = $childchild->nodeValue;
  70. }
  71. break;
  72. }
  73. break;
  74. case XML_TEXT_NODE:
  75. if (trim($child->textContent) != '') {
  76. if (count($children == 1)) {
  77. // If this is the only child at this level and it is a content... save differently.
  78. $this->text = $child->textContent;
  79. } else {
  80. $this->text[$element->tagName] = $child->textContent;
  81. }
  82. }
  83. break;
  84. }
  85. }
  86. $attributes = $element->attributes;
  87. //$keep_href = '';
  88. if (is_array($attributes)) {
  89. foreach ($attributes as $attrib) {
  90. if (trim($attrib->value) != '') {
  91. $this->attribs[$attrib->name] = $attrib->value;
  92. }
  93. }
  94. }
  95. //break;
  96. }
  97. // End parsing using PHP5 DOMXML methods.
  98. }
  99. }
  100. }