scormOrganization.class.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Container for the scormOrganization class
  5. * @package chamilo.learnpath.scorm
  6. * @author Yannick Warnier <ywarnier@beeznest.org>
  7. */
  8. /**
  9. * Class defining the <organization> tag in an imsmanifest.xml file
  10. */
  11. class scormOrganization
  12. {
  13. public $identifier = '';
  14. public $structure = '';
  15. public $title = '';
  16. public $items = array();
  17. public $metadata;
  18. /**
  19. * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormOrganization
  20. * object from database records or from the DOM element given as parameter
  21. * @param string Type of construction needed ('db' or 'manifest', default = 'manifest')
  22. * @param mixed Depending on the type given, DB id for the lp_item or reference to the DOM element
  23. */
  24. public function __construct($type = 'manifest', &$element, $scorm_charset = 'UTF-8')
  25. {
  26. if (isset($element)) {
  27. // Parsing using PHP5 DOMXML methods.
  28. switch ($type) {
  29. case 'db':
  30. // TODO: Implement this way of metadata object creation.
  31. return false;
  32. case 'manifest': // Do the same as the default.
  33. default:
  34. //if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
  35. $children = $element->childNodes;
  36. foreach ($children as $child) {
  37. switch ($child->nodeType) {
  38. case XML_ELEMENT_NODE:
  39. switch ($child->tagName) {
  40. case 'item':
  41. $oItem = new scormItem(
  42. 'manifest',
  43. $child
  44. );
  45. if ($oItem->identifier != '') {
  46. $this->items[$oItem->identifier] = $oItem;
  47. }
  48. break;
  49. case 'metadata':
  50. $this->metadata = new scormMetadata(
  51. 'manifest', $child
  52. );
  53. break;
  54. case 'title':
  55. $tmp_children = $child->childNodes;
  56. if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
  57. $this->title = api_utf8_decode(
  58. api_html_entity_decode(
  59. $child->firstChild->nodeValue,
  60. ENT_QUOTES,
  61. 'UTF-8'
  62. )
  63. );
  64. }
  65. break;
  66. }
  67. break;
  68. case XML_TEXT_NODE:
  69. break;
  70. }
  71. }
  72. if ($element->hasAttributes()) {
  73. $attributes = $element->attributes;
  74. //$keep_href = '';
  75. foreach ($attributes as $attrib) {
  76. switch ($attrib->name) {
  77. case 'identifier':
  78. $this->identifier = $attrib->value;
  79. break;
  80. case 'structure':
  81. $this->structure = $attrib->value;
  82. break;
  83. }
  84. }
  85. }
  86. return true;
  87. }
  88. // End parsing using PHP5 DOMXML methods.
  89. }
  90. return false;
  91. }
  92. /**
  93. * Get a flat list of items in the organization
  94. * @return array Array containing an ordered list of all items with their level and all information related to each item
  95. */
  96. public function get_flat_items_list()
  97. {
  98. $list = array();
  99. $i = 1;
  100. foreach ($this->items as $id => $dummy) {
  101. $abs_order = 0;
  102. // Passes the array as a pointer so it is modified in $list directly.
  103. $this->items[$id]->get_flat_list($list, $abs_order, $i, 0);
  104. $i++;
  105. }
  106. return $list;
  107. }
  108. /**
  109. * Name getter
  110. * @return string Name or empty string
  111. */
  112. public function get_name()
  113. {
  114. if (!empty($this->title)) {
  115. return Database::escape_string($this->title);
  116. } else {
  117. return '';
  118. }
  119. }
  120. /**
  121. * Reference identifier getter
  122. * @return string Identifier or empty string
  123. */
  124. public function get_ref()
  125. {
  126. if (!empty($this->identifier)) {
  127. return Database::escape_string($this->identifier);
  128. } else {
  129. return '';
  130. }
  131. }
  132. /**
  133. * Sets the title element
  134. * @param string $title New title to set
  135. */
  136. public function set_name($title)
  137. {
  138. if (!empty($title)) {
  139. $this->title = Database::escape_string($title);
  140. }
  141. }
  142. }