scormResource.class.php 5.4 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. 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. echo "<pre>Analysing resource:<br />\n";
  33. var_dump($element);
  34. echo "</pre><br />\n";
  35. */
  36. if (isset($element)) {
  37. // Parsing using PHP5 DOMXML methods.
  38. switch ($type) {
  39. case 'db':
  40. // TODO: Implement this way of metadata object creation.
  41. return false;
  42. case 'manifest': // Do the same as the default.
  43. default:
  44. //if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
  45. $children = $element->childNodes;
  46. if (is_array($children)) {
  47. foreach ($children as $child) {
  48. switch ($child->nodeType) {
  49. case XML_ELEMENT_NODE:
  50. switch ($child->tagName) {
  51. case 'file':
  52. //echo "Child is a file tag<br />\n";
  53. $this->files[] = $child->getAttribute('href');
  54. break;
  55. case 'metadata':
  56. //echo "Child is a metadata tag<br />\n";
  57. $this->metadata = new scormMetadata('manifest', $child);
  58. break;
  59. case 'dependency':
  60. // Need to get identifierref attribute inside dependency node.
  61. // dependencies[] array represents all <dependency identifierref='x'> tags united.
  62. $this->dependencies[] = $child->getAttribute('identifierref');
  63. break;
  64. }
  65. break;
  66. }
  67. }
  68. }
  69. //$keep_href = '';
  70. if ($element->hasAttributes()){ //in some cases we get here with an empty attributes array
  71. // TODO: Find when and why we get such a case (empty array).
  72. $attributes = $element->attributes;
  73. foreach ($attributes as $attrib) {
  74. switch ($attrib->name) {
  75. case 'identifier':
  76. $this->identifier = $attrib->value;
  77. break;
  78. case 'type':
  79. if (!empty($attrib->value)) {
  80. $this->type = $attrib->value;
  81. }
  82. break;
  83. case 'scormtype':
  84. if (!empty($attrib->value)) {
  85. $this->scormtype = $attrib->value;
  86. }
  87. break;
  88. case 'base':
  89. $this->base = $attrib->value;
  90. break;
  91. case 'href':
  92. $this->href = $attrib->value;
  93. break;
  94. }
  95. }
  96. }
  97. return true;
  98. }
  99. // End parsing using PHP5 DOMXML methods.
  100. }
  101. return false;
  102. }
  103. /**
  104. * Path getter
  105. * @return string Path for this resource
  106. */
  107. public function get_path() {
  108. if (!empty($this->href)) {
  109. return Database::escape_string($this->href);
  110. } else {
  111. return '';
  112. }
  113. }
  114. /**
  115. * Scorm type getter
  116. * @return string generally 'asset' or 'sco' as these are the only two values defined in SCORM 1.2
  117. */
  118. public function get_scorm_type() {
  119. if (!empty($this->scormtype)) {
  120. return Database::escape_string($this->scormtype);
  121. } else {
  122. return '';
  123. }
  124. }
  125. }