scormItem.class.php 9.7 KB

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