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