scormOrganization.class.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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('manifest', $child);
  42. if ($oItem->identifier != '') {
  43. $this->items[$oItem->identifier] = $oItem;
  44. }
  45. break;
  46. case 'metadata':
  47. $this->metadata = new scormMetadata('manifest', $child);
  48. break;
  49. case 'title':
  50. $tmp_children = $child->childNodes;
  51. if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
  52. $this->title = api_utf8_decode(api_html_entity_decode($child->firstChild->nodeValue, ENT_QUOTES, 'UTF-8'));
  53. }
  54. break;
  55. }
  56. break;
  57. case XML_TEXT_NODE:
  58. break;
  59. }
  60. }
  61. if ($element->hasAttributes()) {
  62. $attributes = $element->attributes;
  63. //$keep_href = '';
  64. foreach ($attributes as $attrib) {
  65. switch ($attrib->name) {
  66. case 'identifier':
  67. $this->identifier = $attrib->value;
  68. break;
  69. case 'structure':
  70. $this->structure = $attrib->value;
  71. break;
  72. }
  73. }
  74. }
  75. return true;
  76. }
  77. // End parsing using PHP5 DOMXML methods.
  78. }
  79. return false;
  80. }
  81. /**
  82. * Get a flat list of items in the organization
  83. * @return array Array containing an ordered list of all items with their level and all information related to each item
  84. */
  85. public function get_flat_items_list()
  86. {
  87. $list = array();
  88. $i = 1;
  89. foreach ($this->items as $id => $dummy) {
  90. $abs_order = 0;
  91. // Passes the array as a pointer so it is modified in $list directly.
  92. $this->items[$id]->get_flat_list($list,$abs_order, $i, 0);
  93. $i++;
  94. }
  95. return $list;
  96. }
  97. /**
  98. * Name getter
  99. * @return string Name or empty string
  100. */
  101. public function get_name()
  102. {
  103. if (!empty($this->title)) {
  104. return Database::escape_string($this->title);
  105. } else {
  106. return '';
  107. }
  108. }
  109. /**
  110. * Reference identifier getter
  111. * @return string Identifier or empty string
  112. */
  113. public function get_ref()
  114. {
  115. if (!empty($this->identifier)) {
  116. return Database::escape_string($this->identifier);
  117. } else {
  118. return '';
  119. }
  120. }
  121. /**
  122. * Sets the title element
  123. * @param string $title New title to set
  124. */
  125. public function set_name($title)
  126. {
  127. if (!empty($title)) {
  128. $this->title = Database::escape_string($title);
  129. }
  130. }
  131. }