scormItem.class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <?php //$id:$
  2. /**
  3. * Container for the scormItem class that deals with <item> elements in an imsmanifest file
  4. * @package dokeos.learnpath
  5. * @author Yannick Warnier <ywarnier@beeznest.org>
  6. */
  7. /**
  8. * This class handles the <item> elements from an imsmanifest file.
  9. */
  10. require_once('learnpathItem.class.php');
  11. class scormItem extends learnpathItem{
  12. var $identifier = '';
  13. var $identifierref = '';
  14. var $isvisible = '';
  15. var $parameters = '';
  16. var $title = '';
  17. var $sub_items = array();
  18. var $metadata;
  19. //var $prerequisites = ''; - defined in learnpathItem.class.php
  20. var $max_time_allowed = ''; //should be something like HHHH:MM:SS.SS
  21. var $timelimitaction = '';
  22. var $datafromlms = '';
  23. var $mastery_score = '';
  24. var $scorm_contact;
  25. /**
  26. * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormItem
  27. * object from database records or from the DOM element given as parameter
  28. * @param string Type of construction needed ('db' or 'manifest', default = 'manifest')
  29. * @param mixed Depending on the type given, DB id for the lp_item or reference to the DOM element
  30. */
  31. function scormItem($type='manifest',&$element) {
  32. if(isset($element))
  33. {
  34. $v = substr(phpversion(),0,1);
  35. if($v == 4){
  36. switch($type){
  37. case 'db':
  38. parent::learnpathItem($element,api_get_user_id());
  39. $this->scorm_contact = false;
  40. //TODO implement this way of metadata object creation
  41. return false;
  42. case 'manifest': //do the same as the default
  43. default:
  44. //if($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function
  45. $children = $element->children();
  46. foreach($children as $a => $dummy)
  47. {
  48. $child =& $children[$a];
  49. switch($child->type)
  50. {
  51. case XML_ELEMENT_NODE:
  52. switch($child->tagname){
  53. case 'title':
  54. $tmp_children = $child->children();
  55. if(count($tmp_children)==1 and $tmp_children[0]->content!='' )
  56. {
  57. $this->title = $tmp_children[0]->content;
  58. }
  59. break;
  60. case 'maxtimeallowed':
  61. $tmp_children = $child->children();
  62. if(count($tmp_children)==1 and $tmp_children[0]->content!='' )
  63. {
  64. $this->max_time_allowed = $tmp_children[0]->content;
  65. }
  66. break;
  67. case 'prerequisites':
  68. $tmp_children = $child->children();
  69. if(count($tmp_children)==1 and $tmp_children[0]->content!='' )
  70. {
  71. $this->prereq_string = $tmp_children[0]->content;
  72. }
  73. break;
  74. case 'timelimitaction':
  75. $tmp_children = $child->children();
  76. if(count($tmp_children)==1 and $tmp_children[0]->content!='' )
  77. {
  78. $this->timelimitaction = $tmp_children[0]->content;
  79. }
  80. break;
  81. case 'datafromlms':
  82. $tmp_children = $child->children();
  83. if(count($tmp_children)==1 and $tmp_children[0]->content!='' )
  84. {
  85. $this->datafromlms = $tmp_children[0]->content;
  86. }
  87. break;
  88. case 'masteryscore':
  89. $tmp_children = $child->children();
  90. if(count($tmp_children)==1 and $tmp_children[0]->content!='' )
  91. {
  92. $this->mastery_score = $tmp_children[0]->content;
  93. }
  94. break;
  95. case 'item':
  96. $oItem = new scormItem('manifest',$child);
  97. if($oItem->identifier != ''){
  98. $this->sub_items[$oItem->identifier] = $oItem;
  99. }
  100. break;
  101. case 'metadata':
  102. $this->metadata = new scormMetadata('manifest',$child);
  103. break;
  104. }
  105. break;
  106. case XML_TEXT_NODE:
  107. //this case is actually treated by looking into ELEMENT_NODEs above
  108. break;
  109. }
  110. }
  111. $attributes = $element->attributes();
  112. //$keep_href = '';
  113. foreach($attributes as $a1 => $dummy)
  114. {
  115. $attrib =& $attributes[$a1];
  116. switch($attrib->name){
  117. case 'identifier':
  118. $this->identifier = $attrib->value;
  119. break;
  120. case 'identifierref':
  121. $this->identifierref = $attrib->value;
  122. break;
  123. case 'isvisible':
  124. $this->isvisible = $attrib->value;
  125. break;
  126. case 'parameters':
  127. $this->parameters = $attrib->value;
  128. break;
  129. }
  130. }
  131. return true;
  132. }
  133. }elseif($v == 5){
  134. //parsing using PHP5 DOMXML methods
  135. switch($type){
  136. case 'db':
  137. parent::learnpathItem($element,api_get_user_id());
  138. $this->scorm_contact = false;
  139. //TODO implement this way of metadata object creation
  140. return false;
  141. case 'manifest': //do the same as the default
  142. default:
  143. //if($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function
  144. $children = $element->childNodes;
  145. foreach($children as $child)
  146. {
  147. switch($child->nodeType)
  148. {
  149. case XML_ELEMENT_NODE:
  150. switch($child->tagName){
  151. case 'title':
  152. $tmp_children = $child->childNodes;
  153. //if(count($tmp_children)==1 and $tmp_children[0]->textContent!='' )
  154. if($tmp_children->length==1 and $child->firstChild->nodeValue!='' )
  155. {
  156. $this->title = $child->firstChild->nodeValue;
  157. }
  158. break;
  159. case 'maxtimeallowed':
  160. case 'adlcp:maxtimeallowed':
  161. $tmp_children = $child->childNodes;
  162. //if(count($tmp_children)==1 and $tmp_children[0]->textContent!='' )
  163. if($tmp_children->length==1 and $child->firstChild->nodeValue!='' )
  164. {
  165. $this->max_time_allowed = $child->firstChild->nodeValue;
  166. }
  167. break;
  168. case 'prerequisites':
  169. case 'adlcp:prerequisites':
  170. $tmp_children = $child->childNodes;
  171. //if(count($tmp_children)==1 and $tmp_children[0]->textContent!='' )
  172. if($tmp_children->length==1 and $child->firstChild->nodeValue!='' )
  173. {
  174. $this->prereq_string = $child->firstChild->nodeValue;
  175. }
  176. break;
  177. case 'timelimitaction':
  178. case 'adlcp:timelimitaction':
  179. $tmp_children = $child->childNodes;
  180. //if(count($tmp_children)==1 and $tmp_children[0]->textContent!='' )
  181. if($tmp_children->length==1 and $child->firstChild->nodeValue!='' )
  182. {
  183. $this->timelimitaction = $child->firstChild->nodeValue;
  184. }
  185. break;
  186. case 'datafromlms':
  187. case 'adlcp:datafromlms':
  188. case 'adlcp:launchdata': //in some cases (Wouters)
  189. $tmp_children = $child->childNodes;
  190. //if(count($tmp_children)==1 and $tmp_children[0]->textContent!='' )
  191. if($tmp_children->length==1 and $child->firstChild->nodeValue!='' )
  192. {
  193. $this->datafromlms = $child->firstChild->nodeValue;
  194. }
  195. break;
  196. case 'masteryscore':
  197. case 'adlcp:masteryscore':
  198. $tmp_children = $child->childNodes;
  199. //if(count($tmp_children)==1 and $tmp_children[0]->textContent!='' )
  200. if($tmp_children->length==1 and $child->firstChild->nodeValue!='' )
  201. {
  202. $this->mastery_score = $child->firstChild->nodeValue;
  203. }
  204. break;
  205. case 'item':
  206. $oItem = new scormItem('manifest',$child);
  207. if($oItem->identifier != ''){
  208. $this->sub_items[$oItem->identifier] = $oItem;
  209. }
  210. break;
  211. case 'metadata':
  212. $this->metadata = new scormMetadata('manifest',$child);
  213. break;
  214. }
  215. break;
  216. case XML_TEXT_NODE:
  217. //this case is actually treated by looking into ELEMENT_NODEs above
  218. break;
  219. }
  220. }
  221. if($element->hasAttributes()){
  222. $attributes = $element->attributes;
  223. //$keep_href = '';
  224. foreach($attributes as $attrib)
  225. {
  226. switch($attrib->name){
  227. case 'identifier':
  228. $this->identifier = $attrib->value;
  229. break;
  230. case 'identifierref':
  231. $this->identifierref = $attrib->value;
  232. break;
  233. case 'isvisible':
  234. $this->isvisible = $attrib->value;
  235. break;
  236. case 'parameters':
  237. $this->parameters = $attrib->value;
  238. break;
  239. }
  240. }
  241. }
  242. return true;
  243. }
  244. }else{
  245. //cannot parse because not PHP4 nor PHP5... We should not even be here anyway...
  246. return false;
  247. }
  248. }
  249. return false;
  250. }
  251. /**
  252. * Builds a flat list with the current item and calls itself recursively on all children
  253. * @param array Reference to the array to complete with the current item
  254. * @param integer Optional absolute order (pointer) of the item in this learning path
  255. * @param integer Optional relative order of the item at this level
  256. * @param integer Optional level. If not given, assumes it's level 0
  257. */
  258. function get_flat_list(&$list,&$abs_order,$rel_order=1,$level=0)
  259. {
  260. $list[] = array(
  261. 'abs_order' => $abs_order,
  262. 'datafromlms' => $this->datafromlms,
  263. 'identifier' => $this->identifier,
  264. 'identifierref' => $this->identifierref,
  265. 'isvisible' => $this->isvisible,
  266. 'level' => $level,
  267. 'masteryscore' => $this->mastery_score,
  268. 'maxtimeallowed' => $this->max_time_allowed,
  269. 'metadata' => $this->metadata,
  270. 'parameters' => $this->parameters,
  271. 'prerequisites' => (!empty($this->prereq_string)?$this->prereq_string:''),
  272. 'rel_order' => $rel_order,
  273. 'timelimitaction' => $this->timelimitaction,
  274. 'title' => $this->title
  275. );
  276. $abs_order++;
  277. $i = 1;
  278. foreach($this->sub_items as $id => $dummy)
  279. {
  280. $oSubitem =& $this->sub_items[$id];
  281. $oSubitem->get_flat_list($list,$abs_order,$i,$level+1);
  282. $i++;
  283. }
  284. }
  285. /**
  286. * Save function. Uses the parent save function and adds a layer for SCORM.
  287. * @param boolean Save from URL params (1) or from object attributes (0)
  288. */
  289. function save($from_outside=true,$prereqs_complete=false)
  290. {
  291. parent::save($from_outside,$prereqs_complete);
  292. //under certain conditions, the scorm_contact should not be set, because no scorm signal was sent
  293. $this->scorm_contact = true;
  294. if(!$this->scorm_contact){
  295. //error_log('New LP - was expecting SCORM message but none received',0);
  296. }
  297. }
  298. }
  299. ?>