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