scormItem.class.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class scormItem
  5. * This class handles the <item> elements from an imsmanifest file.
  6. * Container for the scormItem class that deals with <item> elements in an imsmanifest file.
  7. *
  8. * @package chamilo.learnpath.scorm
  9. *
  10. * @author Yannick Warnier <ywarnier@beeznest.org>
  11. */
  12. class scormItem extends learnpathItem
  13. {
  14. public $identifier = '';
  15. public $identifierref = '';
  16. public $isvisible = '';
  17. public $parameters = '';
  18. public $title = '';
  19. public $sub_items = [];
  20. public $metadata;
  21. //public $prerequisites = ''; - defined in learnpathItem.class.php
  22. // Modified by Ivan Tcholakov, 06-FEB-2010.
  23. //public $max_time_allowed = ''; //should be something like HHHH:MM:SS.SS
  24. public $max_time_allowed = '00:00:00';
  25. public $timelimitaction = '';
  26. public $datafromlms = '';
  27. public $mastery_score = '';
  28. public $scorm_contact;
  29. /**
  30. * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormItem
  31. * object from database records or from the DOM element given as parameter.
  32. *
  33. * @param string $type Type of construction needed ('db' or 'manifest', default = 'manifest')
  34. * @param mixed $element Depending on the type given, DB id for the lp_item or reference to the DOM element
  35. * @param int $course_id
  36. */
  37. public function __construct($type = 'manifest', &$element, $course_id = 0)
  38. {
  39. if (isset($element)) {
  40. // Parsing using PHP5 DOMXML methods.
  41. switch ($type) {
  42. case 'db':
  43. parent::__construct($element, api_get_user_id(), $course_id);
  44. $this->scorm_contact = false;
  45. // TODO: Implement this way of metadata object creation.
  46. break;
  47. case 'manifest': // Do the same as the default.
  48. default:
  49. //if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function.
  50. $children = $element->childNodes;
  51. foreach ($children as $child) {
  52. switch ($child->nodeType) {
  53. case XML_ELEMENT_NODE:
  54. switch ($child->tagName) {
  55. case 'title':
  56. $tmp_children = $child->childNodes;
  57. if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
  58. $this->title = $child->firstChild->nodeValue;
  59. }
  60. break;
  61. case 'max_score':
  62. if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
  63. $this->max_score = $child->firstChild->nodeValue;
  64. }
  65. break;
  66. case 'maxtimeallowed':
  67. case 'adlcp:maxtimeallowed':
  68. $tmp_children = $child->childNodes;
  69. if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
  70. $this->max_time_allowed = $child->firstChild->nodeValue;
  71. }
  72. break;
  73. case 'prerequisites':
  74. case 'adlcp:prerequisites':
  75. $tmp_children = $child->childNodes;
  76. if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
  77. $this->prereq_string = $child->firstChild->nodeValue;
  78. }
  79. break;
  80. case 'timelimitaction':
  81. case 'adlcp:timelimitaction':
  82. $tmp_children = $child->childNodes;
  83. if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
  84. $this->timelimitaction = $child->firstChild->nodeValue;
  85. }
  86. break;
  87. case 'datafromlms':
  88. case 'adlcp:datafromlms':
  89. case 'adlcp:launchdata': //in some cases (Wouters)
  90. $tmp_children = $child->childNodes;
  91. if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
  92. $this->datafromlms = $child->firstChild->nodeValue;
  93. }
  94. break;
  95. case 'masteryscore':
  96. case 'adlcp:masteryscore':
  97. $tmp_children = $child->childNodes;
  98. if ($tmp_children->length == 1 && $child->firstChild->nodeValue != '') {
  99. $this->mastery_score = $child->firstChild->nodeValue;
  100. }
  101. break;
  102. case 'item':
  103. $oItem = new scormItem('manifest', $child);
  104. if ($oItem->identifier != '') {
  105. $this->sub_items[$oItem->identifier] = $oItem;
  106. }
  107. break;
  108. case 'metadata':
  109. $this->metadata = new scormMetadata('manifest', $child);
  110. break;
  111. }
  112. break;
  113. case XML_TEXT_NODE:
  114. // This case is actually treated by looking into ELEMENT_NODEs above.
  115. break;
  116. }
  117. }
  118. if ($element->hasAttributes()) {
  119. $attributes = $element->attributes;
  120. //$keep_href = '';
  121. foreach ($attributes as $attrib) {
  122. switch ($attrib->name) {
  123. case 'identifier':
  124. $this->identifier = $attrib->value;
  125. break;
  126. case 'identifierref':
  127. $this->identifierref = $attrib->value;
  128. break;
  129. case 'isvisible':
  130. $this->isvisible = $attrib->value;
  131. break;
  132. case 'parameters':
  133. $this->parameters = $attrib->value;
  134. break;
  135. }
  136. }
  137. }
  138. }
  139. // End parsing using PHP5 DOMXML methods.
  140. }
  141. }
  142. /**
  143. * Builds a flat list with the current item and calls itself recursively on all children.
  144. *
  145. * @param array Reference to the array to complete with the current item
  146. * @param int Optional absolute order (pointer) of the item in this learning path
  147. * @param int Optional relative order of the item at this level
  148. * @param int Optional level. If not given, assumes it's level 0
  149. */
  150. public function get_flat_list(&$list, &$abs_order, $rel_order = 1, $level = 0)
  151. {
  152. $list[] = [
  153. 'abs_order' => $abs_order,
  154. 'datafromlms' => $this->datafromlms,
  155. 'identifier' => $this->identifier,
  156. 'identifierref' => $this->identifierref,
  157. 'isvisible' => $this->isvisible,
  158. 'level' => $level,
  159. 'masteryscore' => $this->mastery_score,
  160. 'maxtimeallowed' => $this->max_time_allowed,
  161. 'metadata' => $this->metadata,
  162. 'parameters' => $this->parameters,
  163. 'prerequisites' => (!empty($this->prereq_string) ? $this->prereq_string : ''),
  164. 'rel_order' => $rel_order,
  165. 'timelimitaction' => $this->timelimitaction,
  166. 'title' => $this->title,
  167. 'max_score' => $this->max_score,
  168. ];
  169. $abs_order++;
  170. $i = 1;
  171. foreach ($this->sub_items as $id => $dummy) {
  172. $oSubitem = &$this->sub_items[$id];
  173. $oSubitem->get_flat_list($list, $abs_order, $i, $level + 1);
  174. $i++;
  175. }
  176. }
  177. /**
  178. * Save function. Uses the parent save function and adds a layer for SCORM.
  179. *
  180. * @param bool Save from URL params (1) or from object attributes (0)
  181. */
  182. public function save($from_outside = true, $prereqs_complete = false)
  183. {
  184. parent::save($from_outside, $prereqs_complete);
  185. // Under certain conditions, the scorm_contact should not be set, because no scorm signal was sent.
  186. $this->scorm_contact = true;
  187. }
  188. }