scormOrganization.class.php 5.5 KB

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