scormItem.class.php 9.6 KB

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