scormItem.class.php 11 KB

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