scormItem.class.php 9.7 KB

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