scormResource.class.php 5.2 KB

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