scormResource.class.php 5.2 KB

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