scormOrganization.class.php 5.0 KB

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