scormResource.class.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Container for the scormResource class.
  5. *
  6. * @package chamilo.learnpath.scorm
  7. *
  8. * @author Yannick Warnier <ywarnier@beeznest.org>
  9. */
  10. /**
  11. * Class defining the <resource> tag in an imsmanifest.xml file.
  12. */
  13. class scormResource
  14. {
  15. public $identifier = '';
  16. public $type = 'webcontent';
  17. //public $identifierref = '';
  18. public $scormtype = 'sco'; // Fix problems with ENI content where asset is not defined.
  19. public $base = '';
  20. public $href = '';
  21. public $metadata;
  22. //public $file_href;
  23. //public $file_metadata;
  24. public $files = [];
  25. public $dependencies = [];
  26. /**
  27. * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormResource
  28. * object from database records or from the DOM element given as parameter.
  29. *
  30. * @param string Type of construction needed ('db' or 'manifest', default = 'manifest')
  31. * @param mixed Depending on the type given, DB id for the lp_item or reference to the DOM element
  32. */
  33. public function __construct($type = 'manifest', &$element)
  34. {
  35. if (isset($element)) {
  36. // Parsing using PHP5 DOMXML methods.
  37. switch ($type) {
  38. case 'db':
  39. // TODO: Implement this way of metadata object creation.
  40. return false;
  41. case 'manifest': // Do the same as the default.
  42. default:
  43. //if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
  44. $children = $element->childNodes;
  45. if (is_array($children)) {
  46. foreach ($children as $child) {
  47. switch ($child->nodeType) {
  48. case XML_ELEMENT_NODE:
  49. switch ($child->tagName) {
  50. case 'file':
  51. //echo "Child is a file tag<br />\n";
  52. $this->files[] = $child->getAttribute('href');
  53. break;
  54. case 'metadata':
  55. //echo "Child is a metadata tag<br />\n";
  56. $this->metadata = new scormMetadata('manifest', $child);
  57. break;
  58. case 'dependency':
  59. // Need to get identifierref attribute inside dependency node.
  60. // dependencies[] array represents all <dependency identifierref='x'> tags united.
  61. $this->dependencies[] = $child->getAttribute('identifierref');
  62. break;
  63. }
  64. break;
  65. }
  66. }
  67. }
  68. //$keep_href = '';
  69. if ($element->hasAttributes()) { //in some cases we get here with an empty attributes array
  70. // TODO: Find when and why we get such a case (empty array).
  71. $attributes = $element->attributes;
  72. foreach ($attributes as $attrib) {
  73. switch ($attrib->name) {
  74. case 'identifier':
  75. $this->identifier = $attrib->value;
  76. break;
  77. case 'type':
  78. if (!empty($attrib->value)) {
  79. $this->type = $attrib->value;
  80. }
  81. break;
  82. case 'scormtype':
  83. if (!empty($attrib->value)) {
  84. $this->scormtype = $attrib->value;
  85. }
  86. break;
  87. case 'base':
  88. $this->base = $attrib->value;
  89. break;
  90. case 'href':
  91. $this->href = $attrib->value;
  92. break;
  93. }
  94. }
  95. }
  96. return true;
  97. }
  98. // End parsing using PHP5 DOMXML methods.
  99. }
  100. return false;
  101. }
  102. /**
  103. * Path getter.
  104. *
  105. * @return string Path for this resource
  106. */
  107. public function get_path()
  108. {
  109. if (!empty($this->href)) {
  110. return Database::escape_string($this->href);
  111. } else {
  112. return '';
  113. }
  114. }
  115. /**
  116. * Scorm type getter.
  117. *
  118. * @return string generally 'asset' or 'sco' as these are the only two values defined in SCORM 1.2
  119. */
  120. public function get_scorm_type()
  121. {
  122. if (!empty($this->scormtype)) {
  123. return Database::escape_string($this->scormtype);
  124. } else {
  125. return '';
  126. }
  127. }
  128. }