scormMetadata.class.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. * @return boolean True on success, false on failure
  26. */
  27. public function __construct($type = 'manifest', &$element)
  28. {
  29. if (isset($element)) {
  30. // Parsing using PHP5 DOMXML methods.
  31. switch ($type) {
  32. case 'db':
  33. // TODO: Implement this way of metadata object creation.
  34. return false;
  35. //break;
  36. case 'manifest': // Do the same as the default.
  37. $children = $element->childNodes;
  38. foreach ($children as $child) {
  39. switch ($child->nodeType) {
  40. case XML_ELEMENT_NODE:
  41. // Could be 'lom', 'schema', 'schemaversion' or 'location'.
  42. switch ($child->tagName) {
  43. case 'lom':
  44. $childchildren = $child->childNodes;
  45. foreach ($childchildren as $childchild) {
  46. $this->lom = $childchild->nodeValue;
  47. }
  48. break;
  49. case 'schema':
  50. $childchildren = $child->childNodes;
  51. foreach ($childchildren as $childchild) {
  52. // There is generally only one child here.
  53. $this->schema = $childchild->nodeValue;
  54. }
  55. break;
  56. case 'schemaversion':
  57. $childchildren = $child->childNodes;
  58. foreach ($childchildren as $childchild) {
  59. // There is generally only one child here.
  60. $this->schemaversion = $childchild->nodeValue;
  61. }
  62. break;
  63. case 'location':
  64. $childchildren = $child->childNodes;
  65. foreach ($childchildren as $childchild) {
  66. // There is generally only one child here.
  67. $this->location = $childchild->nodeValue;
  68. }
  69. break;
  70. }
  71. break;
  72. case XML_TEXT_NODE:
  73. if (trim($child->textContent) != '') {
  74. if (count($children == 1)) {
  75. // If this is the only child at this level and it is a content... save differently.
  76. $this->text = $child->textContent;
  77. } else {
  78. $this->text[$element->tagName] = $child->textContent;
  79. }
  80. }
  81. break;
  82. }
  83. }
  84. $attributes = $element->attributes;
  85. //$keep_href = '';
  86. if (is_array($attributes)) {
  87. foreach ($attributes as $attrib) {
  88. if (trim($attrib->value) != ''){
  89. $this->attribs[$attrib->name] = $attrib->value;
  90. }
  91. }
  92. }
  93. return true;
  94. //break;
  95. }
  96. // End parsing using PHP5 DOMXML methods.
  97. }
  98. return false;
  99. }
  100. }