learnpathItem.class.php 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227
  1. <?php //$id:$
  2. /**
  3. * This file contains the lp_item class, that inherits from the learnpath class
  4. * @package dokeos.learnpath
  5. * @author Yannick Warnier <ywarnier@beeznest.org>
  6. * @license GNU/GPL - See Dokeos license directory for details
  7. */
  8. /**
  9. * lp_item defines items belonging to a learnpath. Each item has a name, a score, a use time and additional
  10. * information that enables tracking a user's progress in a learning path
  11. * @package dokeos.learnpath
  12. */
  13. class learnpathItem{
  14. var $attempt_id; //also called "objectives" SCORM-wise
  15. var $children = array(); //contains the ids of children items
  16. var $condition; //if this item has a special condition embedded
  17. var $current_score;
  18. var $current_start_time;
  19. var $current_stop_time;
  20. var $current_data = '';
  21. var $db_id;
  22. var $db_item_view_id = '';
  23. var $description = '';
  24. var $file;
  25. //at the moment, interactions are just an array of arrays with a structure of 8 text fields
  26. //id(0), type(1), time(2), weighting(3),correct_responses(4),student_response(5),result(6),latency(7)
  27. var $interactions = array();
  28. var $interactions_count = 0;
  29. var $objectives = array();
  30. var $objectives_count = 0;
  31. var $launch_data = '';
  32. var $lesson_location = '';
  33. var $level = 0;
  34. //var $location; //only set this for SCORM?
  35. var $lp_id;
  36. var $max_score;
  37. var $mastery_score;
  38. var $min_score;
  39. var $max_time_allowed = '';
  40. var $name;
  41. var $next;
  42. var $parent;
  43. var $path;
  44. var $possible_status = array('not attempted','incomplete','completed','passed','failed','browsed');
  45. var $prereq_string = '';
  46. var $prereq_alert = '';
  47. var $prereqs = array();
  48. var $previous;
  49. var $prevent_reinit = 1;
  50. var $ref;
  51. var $save_on_close = true;
  52. var $status;
  53. var $title;
  54. var $type; // this attribute can contain chapter|link|student_publication|module|quiz|document|forum|thread
  55. var $view_id;
  56. var $terms;
  57. var $search_did;
  58. var $debug = 0; //logging param
  59. /**
  60. * Class constructor. Prepares the learnpath_item for later launch
  61. *
  62. * Don't forget to use set_lp_view() if applicable after creating the item.
  63. * Setting an lp_view will finalise the item_view data collection
  64. * @param integer Learnpath item ID
  65. * @param integer User ID
  66. * @return boolean True on success, false on failure
  67. */
  68. function learnpathItem($db_id, $user_id) {
  69. //get items table
  70. if($this->debug>0){error_log('New LP - In learnpathItem constructor: '.$db_id.','.$user_id,0);}
  71. $items_table = Database::get_course_table('lp_item');
  72. $id = (int) $db_id;
  73. $sql = "SELECT * FROM $items_table WHERE id = $id";
  74. //error_log('New LP - Creating item object from DB: '.$sql,0);
  75. $res = @api_sql_query($sql);
  76. if(Database::num_rows($res)<1)
  77. {
  78. $this->error = "Could not find given learnpath item in learnpath_item table";
  79. //error_log('New LP - '.$this->error,0);
  80. return false;
  81. }
  82. $row = Database::fetch_array($res);
  83. $this->lp_id = $row['lp_id'];
  84. $this->max_score = $row['max_score'];
  85. $this->min_score = $row['min_score'];
  86. $this->name = $row['title'];
  87. $this->type = $row['item_type'];
  88. $this->ref = $row['ref'];
  89. $this->title = $row['title'];
  90. $this->description = $row['description'];
  91. $this->path = $row['path'];
  92. $this->mastery_score = $row['mastery_score'];
  93. $this->parent = $row['parent_item_id'];
  94. $this->next = $row['next_item_id'];
  95. $this->previous = $row['previous_item_id'];
  96. $this->display_order = $row['display_order'];
  97. $this->prereq_string = $row['prerequisite'];
  98. $this->max_time_allowed = $row['max_time_allowed'];
  99. if(isset($row['launch_data'])){
  100. $this->launch_data = $row['launch_data'];
  101. }
  102. $this->terms = $row['terms'];
  103. $this->search_did = $row['search_did'];
  104. $this->save_on_close = true;
  105. $this->db_id = $id;
  106. //error_log('New LP - End of learnpathItem constructor for item '.$id,0);
  107. return true;
  108. }
  109. /**
  110. * Adds a child to the current item
  111. */
  112. function add_child($item)
  113. {
  114. if($this->debug>0){error_log('New LP - In learnpathItem::add_child()',0);}
  115. if(!empty($item))
  116. {
  117. //do not check in DB as we expect the call to come from the learnpath class which should
  118. //be aware of any fake
  119. $this->children[] = $item;
  120. }
  121. }
  122. /**
  123. * Adds an interaction to the current item
  124. * @param int Index (order ID) of the interaction inside this item
  125. * @param array Array of parameters: id(0), type(1), time(2), weighting(3),correct_responses(4),student_response(5),result(6),latency(7)
  126. * @result void
  127. */
  128. function add_interaction($index,$params)
  129. {
  130. $this->interactions[$index] = $params;
  131. //take the current maximum index to generate the interactions_count
  132. if(($index+1)>$this->interactions_count){
  133. $this->interactions_count = $index+1;
  134. }
  135. /*
  136. if(is_array($this->interactions[$index]) && count($this->interactions[$index])>0){
  137. $this->interactions[$index] = $params;
  138. return false;
  139. }else{
  140. if(count($params)==8){//we rely on the calling script to provide parameters in the right order
  141. $this->interactions[$index] = $params;
  142. return true;
  143. }else{
  144. return false;
  145. }
  146. }
  147. */
  148. }
  149. /**
  150. * Adds an objective to the current item
  151. * @param array Array of parameters: id(0), status(1), score_raw(2), score_max(3), score_min(4)
  152. * @result void
  153. */
  154. function add_objective($index,$params)
  155. {
  156. if(empty($params[0])){return null;}
  157. $this->objectives[$index] = $params;
  158. //take the current maximum index to generate the objectives_count
  159. if((count($this->objectives)+1)>$this->objectives_count){
  160. $this->objectives_count = (count($this->objectives)+1);
  161. }
  162. }
  163. /**
  164. * Closes/stops the item viewing. Finalises runtime values. If required, save to DB.
  165. * @return boolean True on success, false otherwise
  166. */
  167. function close()
  168. {
  169. if($this->debug>0){error_log('New LP - In learnpathItem::close()',0);}
  170. $this->current_stop_time = time();
  171. $type = $this->get_type();
  172. if($type != 'sco'){
  173. if($type == TOOL_QUIZ or $type == TOOL_HOTPOTATOES)
  174. {
  175. $this->get_status(true,true);//update status (second option forces the update)
  176. }
  177. else
  178. {
  179. $this->status = $this->possible_status[2];
  180. }
  181. }
  182. if($this->save_on_close)
  183. {
  184. $this->save();
  185. }
  186. return true;
  187. }
  188. /**
  189. * Deletes all traces of this item in the database
  190. * @return boolean true. Doesn't check for errors yet.
  191. */
  192. function delete()
  193. {
  194. if($this->debug>0){error_log('New LP - In learnpath_item::delete() for item '.$this->db_id,0);}
  195. $lp_item_view = Database::get_course_table('lp_item_view');
  196. $lp_item = Database::get_course_table('lp_item');
  197. $sql_del_view = "DELETE FROM $lp_item_view WHERE item_id = ".$this->db_id;
  198. //error_log('New LP - Deleting from lp_item_view: '.$sql_del_view,0);
  199. $res_del_view = api_sql_query($sql_del_view);
  200. $sql_del_item = "DELETE FROM $lp_item WHERE id = ".$this->db_id;
  201. //error_log('New LP - Deleting from lp_item: '.$sql_del_view,0);
  202. $res_del_item = api_sql_query($sql_del_item);
  203. return true;
  204. }
  205. /**
  206. * Drops a child from the children array
  207. * @param string index of child item to drop
  208. * @return void
  209. */
  210. function drop_child($item)
  211. {
  212. if($this->debug>0){error_log('New LP - In learnpathItem::drop_child()',0);}
  213. if(!empty($item))
  214. {
  215. foreach($this->children as $index => $child)
  216. {
  217. if($child == $item){
  218. $this->children[$index] = null;
  219. }
  220. }
  221. }
  222. }
  223. /**
  224. * Gets the current attempt_id for this user on this item
  225. * @return integer The attempt_id for this item view by this user, or 1 if none defined
  226. */
  227. function get_attempt_id()
  228. {
  229. if($this->debug>0){error_log('New LP - In learnpathItem::get_attempt_id() on item '.$this->db_id,0);}
  230. $res = 1;
  231. if(!empty($this->attempt_id))
  232. {
  233. $res = $this->attempt_id;
  234. }
  235. if($this->debug>0){error_log('New LP - End of learnpathItem::get_attempt_id() on item '.$this->db_id.' - Returning '.$res,0);}
  236. return $res;
  237. }
  238. /**
  239. * Gets a list of the item's children
  240. * @return array Array of children items IDs
  241. */
  242. function get_children()
  243. {
  244. if($this->debug>0){error_log('New LP - In learnpathItem::get_children()',0);}
  245. $list = array();
  246. foreach($this->children as $child){
  247. if(!empty($child))
  248. {
  249. //error_log('New LP - Found '.$child,0);
  250. $list[] = $child;
  251. }
  252. }
  253. return $list;
  254. }
  255. /**
  256. * Gets the core_exit value from the database
  257. */
  258. function get_core_exit()
  259. {
  260. return $this->core_exit;
  261. }
  262. /**
  263. * Gets the credit information (rather scorm-stuff) based on current status and reinit
  264. * autorization. Credit tells the sco(content) if Dokeos will record the data it is sent (credit) or not (no-credit)
  265. * @return string 'credit' or 'no-credit'. Defaults to 'credit' because if we don't know enough about this item, it's probably because it was never used before.
  266. */
  267. function get_credit(){
  268. if(!empty($this->debug) && $this->debug>1){error_log('New LP - In learnpathItem::get_credit()',0);}
  269. $credit = 'credit';
  270. //now check the value of prevent_reinit (if it's 0, return credit as the default was)
  271. if($this->get_prevent_reinit() != 0){ //if prevent_reinit == 1 (or more)
  272. //if status is not attempted or incomplete, credit anyway. Otherwise:
  273. //check the status in the database rather than in the object, as checking in the object
  274. //would always return "no-credit" when we want to set it to completed
  275. $status = $this->get_status(true);
  276. if(!empty($this->debug) && $this->debug>2){error_log('New LP - In learnpathItem::get_credit() - get_prevent_reinit!=0 and status is '.$status,0);}
  277. if($status != $this->possible_status[0] AND $status != $this->possible_status[1]){
  278. $credit = 'no-credit';
  279. }
  280. }
  281. return $credit;
  282. }
  283. /**
  284. * Gets the current start time property
  285. * @return integer Current start time, or current time if none
  286. */
  287. function get_current_start_time()
  288. {
  289. if($this->debug>0){error_log('New LP - In learnpathItem::get_current_start_time()',0);}
  290. if(empty($this->current_start_time))
  291. {
  292. return time();
  293. }else{
  294. return $this->current_start_time;
  295. }
  296. }
  297. /**
  298. * Gets the item's description
  299. * @return string Description
  300. */
  301. function get_description(){
  302. if($this->debug>0){error_log('New LP - In learnpathItem::get_description()',0);}
  303. if(empty($this->description)){return '';}
  304. return $this->description;
  305. }
  306. /**
  307. * Gets the file path from the course's root directory, no matter what tool it is from.
  308. * @return string The file path, or an empty string if there is no file attached, or '-1' if the file must be replaced by an error page
  309. */
  310. function get_file_path($path_to_scorm_dir=''){
  311. if($this->debug>0){error_log('New LP - In learnpathItem::get_file_path()',0);}
  312. $path = $this->get_path();
  313. $type = $this->get_type();
  314. if(empty($path))
  315. {
  316. if($type == 'dokeos_chapter' OR $type=='chapter' OR $type == 'dir')
  317. {
  318. return '';
  319. }
  320. else
  321. {
  322. return '-1';
  323. }
  324. }elseif($path == strval(intval($path))){
  325. //the path is numeric, so it is a reference to a Dokeos object
  326. switch($type)
  327. {
  328. case 'dokeos_chapter':
  329. case 'dir':
  330. case 'chapter':
  331. return '';
  332. case TOOL_DOCUMENT:
  333. $table_doc = Database::get_course_table(TABLE_DOCUMENT);
  334. $sql = 'SELECT path FROM '.$table_doc.' WHERE id = '.$path;
  335. $res = api_sql_query($sql,__FILE__,__LINE__);
  336. $row = Database::fetch_array($res);
  337. $real_path = 'document'.$row['path'];
  338. return $real_path;
  339. case TOOL_STUDENTPUBLICATION:
  340. case TOOL_QUIZ:
  341. case TOOL_FORUM:
  342. case TOOL_THREAD:
  343. case TOOL_LINK:
  344. default:
  345. return '-1';
  346. }
  347. }else{
  348. if(!empty($path_to_scorm_dir))
  349. {
  350. $path = $path_to_scorm_dir.$path;
  351. }
  352. return $path;
  353. }
  354. }
  355. /**
  356. * Gets the DB ID
  357. * @return integer Database ID for the current item
  358. */
  359. function get_id(){
  360. if($this->debug>1){error_log('New LP - In learnpathItem::get_id()',0);}
  361. if(!empty($this->db_id))
  362. {
  363. return $this->db_id;
  364. }
  365. //TODO check this return value is valid for children classes (SCORM?)
  366. return 0;
  367. }
  368. /**
  369. * Gets the current count of interactions recorded in the database
  370. * @return int The current number of interactions recorder
  371. */
  372. function get_interactions_count()
  373. {
  374. if($this->debug>1){error_log('New LP - In learnpathItem::get_interactions_count()',0);}
  375. $res = 0;
  376. if(!empty($this->interactions_count)){
  377. $res = $this->interactions_count;
  378. }
  379. return $res;
  380. }
  381. /**
  382. * Gets the current count of objectives recorded in the database
  383. * @return int The current number of objectives recorder
  384. */
  385. function get_objectives_count()
  386. {
  387. if($this->debug>1){error_log('New LP - In learnpathItem::get_objectives_count()',0);}
  388. $res = 0;
  389. if(!empty($this->objectives_count)){
  390. $res = $this->objectives_count;
  391. }
  392. return $res;
  393. }
  394. /**
  395. * Gets the launch_data field found in imsmanifests (this is SCORM- or AICC-related, really)
  396. * @return string Launch data as found in imsmanifest and stored in Dokeos (read only). Defaults to ''.
  397. */
  398. function get_launch_data(){
  399. if($this->debug>0){error_log('New LP - In learnpathItem::get_launch_data()',0);}
  400. if(!empty($this->launch_data)){
  401. return $this->launch_data;
  402. }
  403. return '';
  404. }
  405. /**
  406. * Gets the lesson location
  407. * @return string lesson location as recorded by the SCORM and AICC elements. Defaults to ''
  408. */
  409. function get_lesson_location(){
  410. if($this->debug>0){error_log('New LP - In learnpathItem::get_lesson_location()',0);}
  411. if(!empty($this->lesson_location)){return $this->lesson_location;}else{return '';}
  412. }
  413. /**
  414. * Gets the lesson_mode (scorm feature, but might be used by aicc as well as dokeos paths)
  415. *
  416. * The "browse" mode is not supported yet (because there is no such way of seeing a sco in Dokeos)
  417. * @return string 'browse','normal' or 'review'. Defaults to 'normal'
  418. */
  419. function get_lesson_mode(){
  420. $mode = 'normal';
  421. if($this->get_prevent_reinit() != 0){ //if prevent_reinit == 0
  422. $my_status = $this->get_status();
  423. if($my_status != $this->possible_status[0] AND $my_status != $this->possible_status[1]){
  424. $mode = 'review';
  425. }
  426. }
  427. return $mode;
  428. }
  429. /**
  430. * Gets the depth level
  431. * @return int Level. Defaults to 0
  432. */
  433. function get_level(){
  434. if($this->debug>0){error_log('New LP - In learnpathItem::get_level()',0);}
  435. if(empty($this->level)){return 0;}
  436. return $this->level;
  437. }
  438. /**
  439. * Gets the mastery score
  440. */
  441. function get_mastery_score()
  442. {
  443. if($this->debug>0){error_log('New LP - In learnpathItem::get_mastery_score()',0);}
  444. if(isset($this->mastery_score)){return $this->mastery_score;}else{return -1;}
  445. }
  446. /**
  447. * Gets the maximum (score)
  448. * @return int Maximum score. Defaults to 100 if nothing else is defined
  449. */
  450. function get_max(){
  451. if($this->debug>0){error_log('New LP - In learnpathItem::get_max()',0);}
  452. if($this->type == 'sco')
  453. {
  454. if(!empty($this->view_max_score) and $this->view_max_score>0)
  455. {
  456. return $this->view_max_score;
  457. }
  458. elseif($this->view_max_score === '')
  459. {
  460. return $this->view_max_score;
  461. }
  462. else
  463. {
  464. if(!empty($this->max_score)){return $this->max_score;}else{return 100;}
  465. }
  466. }
  467. else
  468. {
  469. if(!empty($this->max_score)){return $this->max_score;}else{return 100;}
  470. }
  471. }
  472. /**
  473. * Gets the maximum time allowed for this user in this attempt on this item
  474. * @return string Time string in SCORM format (HH:MM:SS or HH:MM:SS.SS or HHHH:MM:SS.SS)
  475. */
  476. function get_max_time_allowed()
  477. {
  478. if($this->debug>0){error_log('New LP - In learnpathItem::get_max_time_allowed()',0);}
  479. if(!empty($this->max_time_allowed)){return $this->max_time_allowed;}else{return '';}
  480. }
  481. /**
  482. * Gets the minimum (score)
  483. * @return int Minimum score. Defaults to 0
  484. */
  485. function get_min(){
  486. if($this->debug>0){error_log('New LP - In learnpathItem::get_min()',0);}
  487. if(!empty($this->min_score)){return $this->min_score;}else{return 0;}
  488. }
  489. /**
  490. * Gets the parent ID
  491. * @return int Parent ID. Defaults to null
  492. */
  493. function get_parent(){
  494. if($this->debug>0){error_log('New LP - In learnpathItem::get_parent()',0);}
  495. if(!empty($this->parent))
  496. {
  497. return $this->parent;
  498. }
  499. //TODO check this return value is valid for children classes (SCORM?)
  500. return null;
  501. }
  502. /**
  503. * Gets the path attribute.
  504. * @return string Path. Defaults to ''
  505. */
  506. function get_path(){
  507. if($this->debug>0){error_log('New LP - In learnpathItem::get_path()',0);}
  508. if(empty($this->path)){return '';}
  509. return $this->path;
  510. }
  511. /**
  512. * Gets the prerequisites string
  513. * @return string Empty string or prerequisites string if defined. Defaults to
  514. */
  515. function get_prereq_string()
  516. {
  517. if($this->debug>0){error_log('New LP - In learnpathItem::get_prereq_string()',0);}
  518. if(!empty($this->prereq_string))
  519. {
  520. return $this->prereq_string;
  521. }else{
  522. return '';
  523. }
  524. }
  525. /**
  526. * Gets the prevent_reinit attribute value (and sets it if not set already)
  527. * @return int 1 or 0 (defaults to 1)
  528. */
  529. function get_prevent_reinit(){
  530. if($this->debug>2){error_log('New LP - In learnpathItem::get_prevent_reinit()',0);}
  531. if(!isset($this->prevent_reinit)){
  532. if(!empty($this->lp_id)){
  533. $db = Database::get_course_table('lp');
  534. $sql = "SELECT * FROM $db WHERE id = ".$this->lp_id;
  535. $res = @api_sql_query($sql);
  536. if(Database::num_rows($res)<1)
  537. {
  538. $this->error = "Could not find parent learnpath in learnpath table";
  539. if($this->debug>2){error_log('New LP - End of learnpathItem::get_prevent_reinit() - Returning false',0);}
  540. return false;
  541. }else{
  542. $row = Database::fetch_array($res);
  543. $this->prevent_reinit = $row['prevent_reinit'];
  544. }
  545. }else{
  546. $this->prevent_reinit = 1;//prevent reinit is always 1 by default - see learnpath.class.php
  547. }
  548. }
  549. if($this->debug>2){error_log('New LP - End of learnpathItem::get_prevent_reinit() - Returned '.$this->prevent_reinit,0);}
  550. return $this->prevent_reinit;
  551. }
  552. /**
  553. * Gets the item's reference column
  554. * @return string The item's reference field (generally used for SCORM identifiers)
  555. */
  556. function get_ref()
  557. {
  558. return $this->ref;
  559. }
  560. /**
  561. * Gets the list of included resources as a list of absolute or relative paths of
  562. * resources included in the current item. This allows for a better SCORM export.
  563. * The list will generally include pictures, flash objects, java applets, or any other
  564. * stuff included in the source of the current item. The current item is expected
  565. * to be an HTML file. If it is not, then the function will return and empty list.
  566. * @param string type (one of the Dokeos tools) - optional (otherwise takes the current item's type)
  567. * @param string path (absolute file path) - optional (otherwise takes the current item's path)
  568. * @param int level of recursivity we're in
  569. * @return array List of file paths. An additional field containing 'local' or 'remote' helps determine if the file should be copied into the zip or just linked
  570. */
  571. function get_resources_from_source($type=null,$abs_path=null, $recursivity=1)
  572. {
  573. $max = 5;
  574. if($recursivity > $max)
  575. {
  576. return array();
  577. }
  578. if(!isset($type))
  579. {
  580. $type = $this->get_type();
  581. }
  582. if(!isset($abs_path))
  583. {
  584. $path = $this->get_file_path();
  585. $abs_path = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/'.$path;
  586. //echo "Abs path coming from item : ".$abs_path."<br/>\n";
  587. }
  588. /*
  589. else
  590. {
  591. echo "Abs path coming from param: ".$abs_path."<br/>\n";
  592. }
  593. */
  594. //error_log(str_repeat(' ',$recursivity).'Analyse file '.$abs_path,0);
  595. $files_list = array();
  596. $type = $this->get_type();
  597. switch($type)
  598. {
  599. case TOOL_DOCUMENT :
  600. case TOOL_QUIZ:
  601. case 'sco':
  602. //get the document and, if HTML, open it
  603. if(is_file($abs_path))
  604. {
  605. //for now, read the whole file in one go (that's gonna be a problem when the file is too big)
  606. $info = pathinfo($abs_path);
  607. $ext = $info['extension'];
  608. switch(strtolower($ext))
  609. {
  610. case 'html':
  611. case 'htm':
  612. case 'shtml':
  613. case 'css':
  614. $wanted_attributes = array('src','url','@import','href','value');
  615. //parse it for included resources
  616. $file_content = file_get_contents($abs_path);
  617. //get an array of attributes from the HTML source
  618. $attributes = learnpathItem::parse_HTML_attributes($file_content,$wanted_attributes);
  619. //look at 'src' attributes in this file
  620. foreach($wanted_attributes as $attr)
  621. {
  622. if(isset($attributes[$attr]))
  623. {
  624. //find which kind of path these are (local or remote)
  625. $sources = $attributes[$attr];
  626. foreach($sources as $source)
  627. {
  628. //skip what is obviously not a resource
  629. if(strpos($source,"+this.")) continue; //javascript code - will still work unaltered
  630. if(strpos($source,'.')=== false) continue; //no dot, should not be an external file anyway
  631. if(strpos($source,'mailto:')) continue; //mailto link
  632. if(strpos($source,';') && !strpos($source,'&amp;')) continue; //avoid code - that should help
  633. if($attr == 'value')
  634. {
  635. if(strpos($source , 'mp3file'))
  636. {
  637. $files_list[] = array(substr($source, 0, strpos($source , '.swf')+4),'local','abs');
  638. $mp3file = substr($source , strpos($source , 'mp3file=')+8);
  639. if(substr($mp3file,0,1) == '/')
  640. $files_list[] = array($mp3file,'local','abs');
  641. else
  642. $files_list[] = array($mp3file,'local','rel');
  643. }
  644. elseif(strpos($source, 'flv=')===0)
  645. {
  646. $source = substr($source, 4);
  647. if(strpos($source, '&')>0)
  648. {
  649. $source = substr($source,0,strpos($source, '&'));
  650. }
  651. if(strpos($source,'://')>0)
  652. {
  653. if(strpos($source,api_get_path(WEB_PATH))!==false)
  654. {
  655. //we found the current portal url
  656. $files_list[] = array($source,'local','url');
  657. }
  658. else
  659. {
  660. //we didn't find any trace of current portal
  661. $files_list[] = array($source,'remote','url');
  662. }
  663. }
  664. else
  665. {
  666. $files_list[] = array($source,'local','abs');
  667. }
  668. continue; //skipping anything else to avoid two entries (while the others can have sub-files in their url, flv's can't)
  669. }
  670. }
  671. if(strpos($source,'://') > 0)
  672. {
  673. //cut at '?' in a URL with params
  674. if(strpos($source,'?')>0)
  675. {
  676. $second_part = substr($source,strpos($source,'?'));
  677. if(strpos($second_part,'://')>0)
  678. {//if the second part of the url contains a url too, treat the second one before cutting
  679. $pos1 = strpos($second_part,'=');
  680. $pos2 = strpos($second_part,'&');
  681. $second_part = substr($second_part,$pos1+1,$pos2-($pos1+1));
  682. if(strpos($second_part,api_get_path(WEB_PATH))!==false)
  683. {
  684. //we found the current portal url
  685. $files_list[] = array($second_part,'local','url');
  686. $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$second_part,$recursivity+1);
  687. if(count($in_files_list)>0)
  688. {
  689. $files_list = array_merge($files_list,$in_files_list);
  690. }
  691. }
  692. else
  693. {
  694. //we didn't find any trace of current portal
  695. $files_list[] = array($second_part,'remote','url');
  696. }
  697. }
  698. elseif(strpos($second_part,'=')>0)
  699. {
  700. if(substr($second_part,0,1) === '/')
  701. { //link starts with a /, making it absolute (relative to DocumentRoot)
  702. $files_list[] = array($second_part,'local','abs');
  703. $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$second_part,$recursivity+1);
  704. if(count($in_files_list)>0)
  705. {
  706. $files_list = array_merge($files_list,$in_files_list);
  707. }
  708. }
  709. elseif(strstr($second_part,'..') === 0)
  710. { //link is relative but going back in the hierarchy
  711. $files_list[] = array($second_part,'local','rel');
  712. $dir = dirname($abs_path);
  713. $new_abs_path = realpath($dir.'/'.$second_part);
  714. $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$new_abs_path,$recursivity+1);
  715. if(count($in_files_list)>0)
  716. {
  717. $files_list = array_merge($files_list,$in_files_list);
  718. }
  719. }
  720. else
  721. { //no starting '/', making it relative to current document's path
  722. if(substr($second_part,0,2) == './')
  723. {
  724. $second_part = substr($second_part,2);
  725. }
  726. $files_list[] = array($second_part,'local','rel');
  727. $dir = dirname($abs_path);
  728. $new_abs_path = realpath($dir.'/'.$second_part);
  729. $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$new_abs_path,$recursivity+1);
  730. if(count($in_files_list)>0)
  731. {
  732. $files_list = array_merge($files_list,$in_files_list);
  733. }
  734. }
  735. }
  736. //leave that second part behind now
  737. $source = substr($source,0,strpos($source,'?'));
  738. if(strpos($source,'://') > 0)
  739. {
  740. if(strpos($source,api_get_path(WEB_PATH))!==false)
  741. {
  742. //we found the current portal url
  743. $files_list[] = array($source,'local','url');
  744. $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$source,$recursivity+1);
  745. if(count($in_files_list)>0)
  746. {
  747. $files_list = array_merge($files_list,$in_files_list);
  748. }
  749. }
  750. else
  751. {
  752. //we didn't find any trace of current portal
  753. $files_list[] = array($source,'remote','url');
  754. }
  755. }
  756. else
  757. {
  758. //no protocol found, make link local
  759. if(substr($source,0,1) === '/')
  760. { //link starts with a /, making it absolute (relative to DocumentRoot)
  761. $files_list[] = array($source,'local','abs');
  762. $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$source,$recursivity+1);
  763. if(count($in_files_list)>0)
  764. {
  765. $files_list = array_merge($files_list,$in_files_list);
  766. }
  767. }
  768. elseif(strstr($source,'..') === 0)
  769. { //link is relative but going back in the hierarchy
  770. $files_list[] = array($source,'local','rel');
  771. $dir = dirname($abs_path);
  772. $new_abs_path = realpath($dir.'/'.$source);
  773. $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$new_abs_path,$recursivity+1);
  774. if(count($in_files_list)>0)
  775. {
  776. $files_list = array_merge($files_list,$in_files_list);
  777. }
  778. }
  779. else
  780. { //no starting '/', making it relative to current document's path
  781. if(substr($source,0,2) == './')
  782. {
  783. $source = substr($source,2);
  784. }
  785. $files_list[] = array($source,'local','rel');
  786. $dir = dirname($abs_path);
  787. $new_abs_path = realpath($dir.'/'.$source);
  788. $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$new_abs_path,$recursivity+1);
  789. if(count($in_files_list)>0)
  790. {
  791. $files_list = array_merge($files_list,$in_files_list);
  792. }
  793. }
  794. }
  795. }
  796. //found some protocol there
  797. if(strpos($source,api_get_path(WEB_PATH))!==false)
  798. {
  799. //we found the current portal url
  800. $files_list[] = array($source,'local','url');
  801. $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$source,$recursivity+1);
  802. if(count($in_files_list)>0)
  803. {
  804. $files_list = array_merge($files_list,$in_files_list);
  805. }
  806. }
  807. else
  808. {
  809. //we didn't find any trace of current portal
  810. $files_list[] = array($source,'remote','url');
  811. }
  812. }
  813. else
  814. {
  815. //no protocol found, make link local
  816. if(substr($source,0,1) === '/')
  817. { //link starts with a /, making it absolute (relative to DocumentRoot)
  818. $files_list[] = array($source,'local','abs');
  819. $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$source,$recursivity+1);
  820. if(count($in_files_list)>0)
  821. {
  822. $files_list = array_merge($files_list,$in_files_list);
  823. }
  824. }
  825. elseif(strstr($source,'..') === 0)
  826. { //link is relative but going back in the hierarchy
  827. $files_list[] = array($source,'local','rel');
  828. $dir = dirname($abs_path);
  829. $new_abs_path = realpath($dir.'/'.$source);
  830. $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$new_abs_path,$recursivity+1);
  831. if(count($in_files_list)>0)
  832. {
  833. $files_list = array_merge($files_list,$in_files_list);
  834. }
  835. }
  836. else
  837. { //no starting '/', making it relative to current document's path
  838. if(substr($source,0,2) == './')
  839. {
  840. $source = substr($source,2);
  841. }
  842. $files_list[] = array($source,'local','rel');
  843. $dir = dirname($abs_path);
  844. $new_abs_path = realpath($dir.'/'.$source);
  845. $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT,$new_abs_path,$recursivity+1);
  846. if(count($in_files_list)>0)
  847. {
  848. $files_list = array_merge($files_list,$in_files_list);
  849. }
  850. }
  851. }
  852. }
  853. }
  854. }
  855. break;
  856. default:
  857. break;
  858. }
  859. }
  860. else
  861. {
  862. //the file could not be found
  863. return false;
  864. }
  865. break;
  866. default: //ignore
  867. break;
  868. }
  869. //error_log(str_repeat(' ',$recursivity),'found files '.print_r($files_list,true),0);
  870. //return $files_list;
  871. $checked_files_list = array();
  872. $checked_array_list = array();
  873. foreach($files_list as $idx => $file)
  874. {
  875. if(!empty($file[0]))
  876. {
  877. if(!in_array($file[0],$checked_files_list))
  878. {
  879. $checked_files_list[] = $files_list[$idx][0];
  880. $checked_array_list[] = $files_list[$idx];
  881. }
  882. }
  883. }
  884. return $checked_array_list;
  885. }
  886. /**
  887. * Gets the score
  888. * @return float The current score or 0 if no score set yet
  889. */
  890. function get_score(){
  891. if($this->debug>0){error_log('New LP - In learnpathItem::get_score()',0);}
  892. $res = 0;
  893. if(!empty($this->current_score))
  894. {
  895. $res = $this->current_score;
  896. }
  897. if($this->debug>1){error_log('New LP - Out of learnpathItem::get_score() - returning '.$res,0);}
  898. return $res;
  899. }
  900. /**
  901. * Gets the item status
  902. * @param boolean Do or don't check into the database for the latest value. Optional. Default is true
  903. * @param boolean Do or don't update the local attribute value with what's been found in DB
  904. * @return string Current status or 'Nnot attempted' if no status set yet
  905. */
  906. function get_status($check_db=true,$update_local=false)
  907. {
  908. if($this->debug>0){error_log('New LP - In learnpathItem::get_status() on item '.$this->db_id,0);}
  909. if($check_db)
  910. {
  911. if($this->debug>2){error_log('New LP - In learnpathItem::get_status(): checking db',0);}
  912. $table = Database::get_course_table('lp_item_view');
  913. $sql = "SELECT * FROM $table WHERE id = '".$this->db_item_view_id."' AND view_count = '".$this->get_attempt_id()."'";
  914. if($this->debug>2){error_log('New LP - In learnpathItem::get_status() - Checking DB: '.$sql,0);}
  915. $res = api_sql_query($sql);
  916. if(Database::num_rows($res)==1){
  917. $row = Database::fetch_array($res);
  918. if($update_local==true){
  919. $this->set_status($row['status']);
  920. }
  921. if($this->debug>2){error_log('New LP - In learnpathItem::get_status() - Returning db value '.$row['status'],0);}
  922. return $row['status'];
  923. }
  924. }
  925. else
  926. {
  927. if($this->debug>2){error_log('New LP - In learnpathItem::get_status() - in get_status: using attrib',0);}
  928. if(!empty($this->status))
  929. {
  930. if($this->debug>2){error_log('New LP - In learnpathItem::get_status() - Returning attrib: '.$this->status,0);}
  931. return $this->status;
  932. }
  933. }
  934. if($this->debug>2){error_log('New LP - In learnpathItem::get_status() - Returning default '.$this->possible_status[0],0);}
  935. return $this->possible_status[0];
  936. }
  937. /**
  938. * Gets the suspend data
  939. */
  940. function get_suspend_data()
  941. {
  942. if($this->debug>0){error_log('New LP - In learnpathItem::get_suspend_data()',0);}
  943. //TODO : improve cleaning of breaklines ... it works but is it really a beautiful way to do it ?
  944. if(!empty($this->current_data)){return str_replace(array("\r","\n"),array('\r','\n'),$this->current_data);}else{return '';}
  945. }
  946. /**
  947. * Gets the total time spent on this item view so far
  948. * @param string Origin of the request. If coming from PHP, send formatted as xxhxx'xx", otherwise use scorm format 00:00:00
  949. * @param integer Given time is a default time to return formatted
  950. */
  951. function get_scorm_time($origin='php',$given_time=null){
  952. //if($this->debug>0){error_log('New LP - In learnpathItem::get_scorm_time()',0);}
  953. $h = get_lang('h');
  954. if(!isset($given_time)){
  955. if(!empty($this->current_start_time) && is_object($this)){
  956. if(!empty($this->current_stop_time)){
  957. $time = $this->current_stop_time - $this->current_start_time;
  958. }else{
  959. $time = time() - $this->current_start_time;
  960. }
  961. }else{
  962. if($origin == 'js'){
  963. return '00:00:00';
  964. }else{
  965. return '00'.$h.'00\'00"';
  966. }
  967. }
  968. }else{
  969. $time = $given_time;
  970. }
  971. $hours = $time/3600;
  972. $mins = ($time%3600)/60;
  973. $secs = ($time%60);
  974. if($origin == 'js'){
  975. $scorm_time = trim(sprintf("%4d:%02d:%02d",$hours,$mins,$secs));
  976. }else{
  977. $scorm_time = trim(sprintf("%4d$h%02d'%02d\"",$hours,$mins,$secs));
  978. }
  979. return $scorm_time;
  980. }
  981. /**
  982. * Returns search index's internal ID
  983. * @return int The indexing engine's internal ID for this lp-item
  984. */
  985. function get_search_id() {
  986. return $this->search_did;
  987. }
  988. /**
  989. * Returns index terms
  990. * @return string Comma-separated list of index terms
  991. */
  992. function get_terms() {
  993. return $this->terms;
  994. }
  995. /**
  996. * Returns the item's title
  997. * @return string Title
  998. */
  999. function get_title(){
  1000. if($this->debug>0){error_log('New LP - In learnpathItem::get_title()',0);}
  1001. if(empty($this->title)){return '';}
  1002. return $this->title;
  1003. }
  1004. /**
  1005. * Returns the total time used to see that item
  1006. * @return integer Total time
  1007. */
  1008. function get_total_time(){
  1009. if($this->debug>0){error_log('New LP - In learnpathItem::get_total_time()',0);}
  1010. if($this->current_start_time == 0){ //shouldn't be necessary thanks to the open() method
  1011. $this->current_start_time = time();
  1012. }
  1013. $time = $this->current_stop_time - $this->current_start_time;
  1014. if($time < 0){
  1015. return 0;
  1016. }else{
  1017. if($this->debug>2){error_log('New LP - In learnpathItem::get_total_time() - Current stop time = '.$this->current_stop_time.', current start time = '.$this->current_start_time.' Returning '.$time,0);}
  1018. return $time;
  1019. }
  1020. }
  1021. /**
  1022. * Gets the item type
  1023. * @return string The item type (can be doc, dir, sco, asset)
  1024. */
  1025. function get_type()
  1026. {
  1027. $res = 'asset';
  1028. if($this->debug>0){error_log('New LP - In learnpathItem::get_type() on item '.$this->db_id,0);}
  1029. if(!empty($this->type))
  1030. {
  1031. //error_log('In item::get_type() - returning '.$this->type,0);
  1032. $res = $this->type;
  1033. }
  1034. if($this->debug>2){error_log('New LP - In learnpathItem::get_type() - Returning '.$res.' for item '.$this->db_id,0);}
  1035. return $res;
  1036. }
  1037. /**
  1038. * Gets the view count for this item
  1039. */
  1040. function get_view_count(){
  1041. if($this->debug>0){error_log('New LP - In learnpathItem::get_view_count()',0);}
  1042. if(!empty($this->attempt_id)){
  1043. return $this->attempt_id;
  1044. }else{
  1045. return 0;
  1046. }
  1047. }
  1048. /**
  1049. * Tells if an item is done ('completed','passed','succeeded') or not
  1050. * @return bool True if the item is done ('completed','passed','succeeded'), false otherwise
  1051. */
  1052. function is_done(){
  1053. if($this->status_is(array('completed','passed','succeeded'))){
  1054. if($this->debug>2){error_log('New LP - In learnpath::is_done() - Item '.$this->get_id().' is complete',0);}
  1055. return true;
  1056. }else{
  1057. if($this->debug>2){error_log('New LP - In learnpath::is_done() - Item '.$this->get_id().' is not complete',0);}
  1058. return false;
  1059. }
  1060. }
  1061. /**
  1062. * Tells if a restart is allowed (take it from $this->prevent_reinit and $this->status)
  1063. * @return integer -1 if retaking the sco another time for credit is not allowed,
  1064. * 0 if it is not allowed but the item has to be finished
  1065. * 1 if it is allowed. Defaults to 1
  1066. */
  1067. function is_restart_allowed()
  1068. {
  1069. if($this->debug>2){error_log('New LP - In learnpathItem::is_restart_allowed()',0);}
  1070. $restart = 1;
  1071. $mystatus = $this->get_status(true);
  1072. if($this->get_prevent_reinit() > 0){ //if prevent_reinit == 1 (or more)
  1073. //if status is not attempted or incomplete, authorize retaking (of the same) anyway. Otherwise:
  1074. if($mystatus != $this->possible_status[0] AND $mystatus != $this->possible_status[1]){
  1075. $restart = -1;
  1076. }else{
  1077. $restart = 0;
  1078. }
  1079. }else{
  1080. if($mystatus == $this->possible_status[0] OR $mystatus == $this->possible_status[1]){
  1081. $restart = -1;
  1082. }
  1083. }
  1084. if($this->debug>2){error_log('New LP - End of learnpathItem::is_restart_allowed() - Returning '.$restart,0);}
  1085. return $restart;
  1086. }
  1087. /**
  1088. * Opens/launches the item. Initialises runtime values.
  1089. * @return boolean True on success, false on failure.
  1090. */
  1091. function open($allow_new_attempt=false){
  1092. if($this->debug>0){error_log('New LP - In learnpathItem::open()',0);}
  1093. if($this->prevent_reinit == 0)
  1094. {
  1095. $this->current_score = 0;
  1096. $this->current_start_time = time();
  1097. //In this case, as we are opening the item, what is important to us
  1098. //is the database status, in order to know if this item has already
  1099. //been used in the past (rather than just loaded and modified by
  1100. //some javascript but not written in the database).
  1101. //If the database status is different from 'not attempted', we can
  1102. //consider this item has already been used, and as such we can
  1103. //open a new attempt. Otherwise, we'll just reuse the current
  1104. //attempt, which is generally created the first time the item is
  1105. //loaded (for example as part of the table of contents)
  1106. $stat = $this->get_status(true);
  1107. if($allow_new_attempt && isset($stat) && ($stat != $this->possible_status[0]))
  1108. {
  1109. $this->attempt_id = $this->attempt_id + 1; //open a new attempt
  1110. }
  1111. $this->status = $this->possible_status[1];
  1112. }
  1113. else
  1114. {
  1115. if($this->current_start_time == 0)
  1116. { //small exception for start time, to avoid amazing values
  1117. $this->current_start_time = time();
  1118. }
  1119. //error_log('New LP - reinit blocked by setting',0);
  1120. }
  1121. }
  1122. /**
  1123. * Outputs the item contents
  1124. * @return string HTML file (displayable in an <iframe>) or empty string if no path defined
  1125. */
  1126. function output()
  1127. {
  1128. if($this->debug>0){error_log('New LP - In learnpathItem::output()',0);}
  1129. if(!empty($this->path) and is_file($this->path))
  1130. {
  1131. $output = '';
  1132. $output .= file_get_contents($this->path);
  1133. return $output;
  1134. }
  1135. return '';
  1136. }
  1137. /**
  1138. * Parses the prerequisites string with the AICC logic language
  1139. * @param string The prerequisites string as it figures in imsmanifest.xml
  1140. * @param Array Array of items in the current learnpath object. Although we're in the learnpathItem object, it's necessary to have a list of all items to be able to check the current item's prerequisites
  1141. * @param Array List of references (the "ref" column in the lp_item table) that are strings used in the expression of prerequisites.
  1142. * @param integer The user ID. In some cases like Dokeos quizzes, it's necessary to have the user ID to query other tables (like the results of quizzes)
  1143. * @return boolean True if the list of prerequisites given is entirely satisfied, false otherwise
  1144. */
  1145. function parse_prereq($prereqs_string, $items, $refs_list,$user_id){
  1146. if($this->debug>0){error_log('New LP - In learnpathItem::parse_prereq() for learnpath '.$this->lp_id.' with string '.$prereqs_string,0);}
  1147. //deal with &, |, ~, =, <>, {}, ,, X*, () in reverse order
  1148. $this->prereq_alert = '';
  1149. // First parse all parenthesis by using a sequential loop (looking for less-inclusives first)
  1150. if($prereqs_string == '_true_'){return true;}
  1151. if($prereqs_string == '_false_'){
  1152. if(empty($this->prereq_alert)){
  1153. $this->prereq_alert = get_lang('_prereq_not_complete');
  1154. }
  1155. return false;
  1156. }
  1157. while(strpos($prereqs_string,'(')!==false){
  1158. //remove any () set and replace with its value
  1159. $matches = array();
  1160. $res = preg_match_all('/(\(([^\(\)]*)\))/',$prereqs_string,$matches);
  1161. if($res){
  1162. foreach($matches[2] as $id=>$match){
  1163. $str_res = $this->parse_prereq($match,$items,$refs_list,$user_id);
  1164. if($str_res){
  1165. $prereqs_string = str_replace($matches[1][$id],'_true_',$prereqs_string);
  1166. }else{
  1167. $prereqs_string = str_replace($matches[1][$id],'_false_',$prereqs_string);
  1168. }
  1169. }
  1170. }
  1171. }
  1172. //parenthesis removed, now look for ORs as it is the lesser-priority binary operator (= always uses one text operand)
  1173. if(strpos($prereqs_string,"|")===false){
  1174. if($this->debug>1){error_log('New LP - Didnt find any OR, looking for AND',0);}
  1175. if(strpos($prereqs_string,"&")!==false){
  1176. $list = split("&",$prereqs_string);
  1177. if(count($list)>1){
  1178. $andstatus = true;
  1179. foreach($list as $condition){
  1180. $andstatus = $andstatus && $this->parse_prereq($condition,$items,$refs_list,$user_id);
  1181. if($andstatus==false){
  1182. if($this->debug>1){error_log('New LP - One condition in AND was false, short-circuit',0);}
  1183. break;
  1184. }
  1185. }
  1186. if(empty($this->prereq_alert) && !$andstatus){
  1187. $this->prereq_alert = get_lang('_prereq_not_complete');
  1188. }
  1189. return $andstatus;
  1190. }else{
  1191. if(isset($items[$refs_list[$list[0]]])){
  1192. $status = $items[$refs_list[$list[0]]]->get_status(true);
  1193. $returnstatus = (($status == $this->possible_status[2]) OR ($status == $this->possible_status[3]));
  1194. if(empty($this->prereq_alert) && !$returnstatus){
  1195. $this->prereq_alert = get_lang('_prereq_not_complete');
  1196. }
  1197. return $returnstatus;
  1198. }
  1199. $this->prereq_alert = get_lang('_prereq_not_complete');
  1200. return false;
  1201. }
  1202. }else{
  1203. //no ORs found, now look for ANDs
  1204. if($this->debug>1){error_log('New LP - Didnt find any AND, looking for =',0);}
  1205. if(strpos($prereqs_string,"=")!==false){
  1206. if($this->debug>1){error_log('New LP - Found =, looking into it',0);}
  1207. //we assume '=' signs only appear when there's nothing else around
  1208. $params = split('=',$prereqs_string);
  1209. if(count($params) == 2){
  1210. //right number of operands
  1211. if(isset($items[$refs_list[$params[0]]])){
  1212. $status = $items[$refs_list[$params[0]]]->get_status(true);
  1213. $returnstatus = ($status == $params[1]);
  1214. if(empty($this->prereq_alert) && !$returnstatus){
  1215. $this->prereq_alert = get_lang('_prereq_not_complete');
  1216. }
  1217. return $returnstatus;
  1218. }
  1219. $this->prereq_alert = get_lang('_prereq_not_complete');
  1220. return false;
  1221. }
  1222. }else{
  1223. //No ANDs found, look for <>
  1224. if($this->debug>1){error_log('New LP - Didnt find any =, looking for <>',0);}
  1225. if(strpos($prereqs_string,"<>")!==false){
  1226. if($this->debug>1){error_log('New LP - Found <>, looking into it',0);}
  1227. //we assume '<>' signs only appear when there's nothing else around
  1228. $params = split('<>',$prereqs_string);
  1229. if(count($params) == 2){
  1230. //right number of operands
  1231. if(isset($items[$refs_list[$params[0]]])){
  1232. $status = $items[$refs_list[$params[0]]]->get_status(true);
  1233. $returnstatus = ($status != $params[1]);
  1234. if(empty($this->prereq_alert) && !$returnstatus){
  1235. $this->prereq_alert = get_lang('_prereq_not_complete');
  1236. }
  1237. return $returnstatus;
  1238. }
  1239. $this->prereq_alert = get_lang('_prereq_not_complete');
  1240. return false;
  1241. }
  1242. }else{
  1243. //No <> found, look for ~ (unary)
  1244. if($this->debug>1){error_log('New LP - Didnt find any =, looking for ~',0);}
  1245. //only remains: ~ and X*{}
  1246. if(strpos($prereqs_string,"~")!==false){
  1247. //found NOT
  1248. if($this->debug>1){error_log('New LP - Found ~, looking into it',0);}
  1249. $list = array();
  1250. $myres = preg_match('/~([^(\d+\*)\{]*)/',$prereqs_string,$list);
  1251. if($myres){
  1252. $returnstatus = !$this->parse_prereq($list[1],$items,$refs_list,$user_id);
  1253. if(empty($this->prereq_alert) && !$returnstatus){
  1254. $this->prereq_alert = get_lang('_prereq_not_complete');
  1255. }
  1256. return $returnstatus;
  1257. }else{
  1258. //strange...
  1259. if($this->debug>1){error_log('New LP - Found ~ but strange string: '.$prereqs_string,0);}
  1260. }
  1261. }else{
  1262. //Finally, look for sets/groups
  1263. if($this->debug>1){error_log('New LP - Didnt find any ~, looking for groups',0);}
  1264. //only groups here
  1265. $groups = array();
  1266. $groups_there = preg_match_all('/((\d+\*)?\{([^\}]+)\}+)/',$prereqs_string,$groups);
  1267. if($groups_there){
  1268. foreach($groups[1] as $gr) //only take the results that correspond to the big brackets-enclosed condition
  1269. {
  1270. if($this->debug>1){error_log('New LP - Dealing with group '.$gr,0);}
  1271. $multi = array();
  1272. $mycond = false;
  1273. if(preg_match('/(\d+)\*\{([^\}]+)\}/',$gr,$multi)){
  1274. if($this->debug>1){error_log('New LP - Found multiplier '.$multi[0],0);}
  1275. $count = $multi[1];
  1276. $list = split(',',$multi[2]);
  1277. $mytrue = 0;
  1278. foreach($list as $cond){
  1279. if(isset($items[$refs_list[$cond]])){
  1280. $status = $items[$refs_list[$cond]]->get_status(true);
  1281. if (($status == $this->possible_status[2]) OR ($status == $this->possible_status[3])){
  1282. $mytrue ++;
  1283. if($this->debug>1){error_log('New LP - Found true item, counting.. ('.($mytrue).')',0);}
  1284. }
  1285. }else{
  1286. if($this->debug>1){error_log('New LP - item '.$cond.' does not exist in items list',0);}
  1287. }
  1288. }
  1289. if($mytrue >= $count){
  1290. if($this->debug>1){error_log('New LP - Got enough true results, return true',0);}
  1291. $mycond = true;
  1292. }else{
  1293. if($this->debug>1){error_log('New LP - Not enough true results',0);}
  1294. }
  1295. }
  1296. else{
  1297. if($this->debug>1){error_log('New LP - No multiplier',0);}
  1298. $list = split(',',$gr);
  1299. $mycond = true;
  1300. foreach($list as $cond){
  1301. if(isset($items[$refs_list[$cond]])){
  1302. $status = $items[$refs_list[$cond]]->get_status(true);
  1303. if (($status == $this->possible_status[2]) OR ($status == $this->possible_status[3])){
  1304. $mycond = true;
  1305. if($this->debug>1){error_log('New LP - Found true item',0);}
  1306. }else{
  1307. if($this->debug>1){error_log('New LP - Found false item, the set is not true, return false',0);}
  1308. $mycond = false;
  1309. break;
  1310. }
  1311. }else{
  1312. if($this->debug>1){error_log('New LP - item '.$cond.' does not exist in items list',0);}
  1313. if($this->debug>1){error_log('New LP - Found false item, the set is not true, return false',0);}
  1314. $mycond = false;
  1315. break;
  1316. }
  1317. }
  1318. }
  1319. if(!$mycond && empty($this->prereq_alert)){
  1320. $this->prereq_alert = get_lang('_prereq_not_complete');
  1321. }
  1322. return $mycond;
  1323. }
  1324. }else{
  1325. //Nothing found there either. Now return the value of the corresponding resource completion status
  1326. if($this->debug>1){error_log('New LP - Didnt find any group, returning value for '.$prereqs_string,0);}
  1327. if(isset($items[$refs_list[$prereqs_string]])){
  1328. if($items[$refs_list[$prereqs_string]]->type == 'quiz')
  1329. {
  1330. $sql = 'SELECT exe_result, exe_weighting
  1331. FROM '.Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES).'
  1332. WHERE exe_exo_id = '.$items[$refs_list[$prereqs_string]]->path.'
  1333. AND exe_user_id = '.$user_id.'
  1334. ORDER BY exe_date DESC
  1335. LIMIT 0, 1';
  1336. $rs_quiz = api_sql_query($sql, __FILE__, __LINE__);
  1337. if($quiz = Database :: fetch_array($rs_quiz))
  1338. {
  1339. if($quiz['exe_result'] >= $items[$refs_list[$prereqs_string]]->get_mastery_score())
  1340. {
  1341. $returnstatus = true;
  1342. }
  1343. else
  1344. {
  1345. $this->prereq_alert = get_lang('_prereq_not_complete');
  1346. $returnstatus = false;
  1347. }
  1348. }
  1349. else
  1350. {
  1351. $this->prereq_alert = get_lang('_prereq_not_complete');
  1352. $returnstatus = false;
  1353. }
  1354. return $returnstatus;
  1355. }
  1356. else
  1357. {
  1358. $status = $items[$refs_list[$prereqs_string]]->get_status(true);
  1359. $returnstatus = (($status == $this->possible_status[2]) OR ($status == $this->possible_status[3]));
  1360. if(!$returnstatus && empty($this->prereq_alert)){
  1361. $this->prereq_alert = get_lang('_prereq_not_complete');
  1362. }
  1363. if(!$returnstatus){
  1364. if($this->debug>1){error_log('New LP - Prerequisite '.$prereqs_string.' not complete',0);}
  1365. }else{
  1366. if($this->debug>1){error_log('New LP - Prerequisite '.$prereqs_string.' complete',0);}
  1367. }
  1368. return $returnstatus;
  1369. }
  1370. }else{
  1371. if($this->debug>1){error_log('New LP - Could not find '.$prereqs_string.' in '.print_r($refs_list,true),0);}
  1372. }
  1373. }
  1374. }
  1375. }
  1376. }
  1377. }
  1378. }else{
  1379. $list = split("\|",$prereqs_string);
  1380. if(count($list)>1){
  1381. if($this->debug>1){error_log('New LP - Found OR, looking into it',0);}
  1382. $orstatus = false;
  1383. foreach($list as $condition){
  1384. if($this->debug>1){error_log('New LP - Found OR, adding it ('.$condition.')',0);}
  1385. $orstatus = $orstatus || $this->parse_prereq($condition,$items,$refs_list,$user_id);
  1386. if($orstatus == true){
  1387. //shortcircuit OR
  1388. if($this->debug>1){error_log('New LP - One condition in OR was true, short-circuit',0);}
  1389. break;
  1390. }
  1391. }
  1392. if(!$orstatus && empty($this->prereq_alert)){
  1393. $this->prereq_alert = get_lang('_prereq_not_complete');
  1394. }
  1395. return $orstatus;
  1396. }else{
  1397. if($this->debug>1){error_log('New LP - OR was found but only one elem present !?',0);}
  1398. if(isset($items[$refs_list[$list[0]]])){
  1399. $status = $items[$refs_list[$list[0]]]->get_status(true);
  1400. $returnstatus = (($status == 'completed') OR ($status == 'passed'));
  1401. if(!$returnstatus && empty($this->prereq_alert)){
  1402. $this->prereq_alert = get_lang('_prereq_not_complete');
  1403. }
  1404. return $returnstatus;
  1405. }
  1406. }
  1407. }
  1408. if(empty($this->prereq_alert)){
  1409. $this->prereq_alert = get_lang('_prereq_not_complete');
  1410. }
  1411. if($this->debug>1){error_log('New LP - End of parse_prereq. Error code is now '.$this->prereq_alert,0);}
  1412. return false;
  1413. }
  1414. /**
  1415. * Parses the HTML attributes given as string.
  1416. *
  1417. * @param string HTML attribute string
  1418. * @param array List of attributes that we want to get back
  1419. * @return array An associative array of attributes
  1420. * @author Based on a function from the HTML_Common2 PEAR module
  1421. */
  1422. function parse_HTML_attributes($attrString,$wanted=array())
  1423. {
  1424. $attributes = array();
  1425. $regs = array();
  1426. $reduced = false;
  1427. if(count($wanted)>0)
  1428. {
  1429. $reduced = true;
  1430. }
  1431. try {
  1432. //Find all occurences of something that looks like a URL
  1433. // The structure of this regexp is:
  1434. // (find protocol) then
  1435. // (optionally find some kind of space 1 or more times) then
  1436. // find (either an equal sign or a bracket) followed by an optional space
  1437. // followed by some text without quotes (between quotes itself or not)
  1438. // then possible closing brackets if we were in the opening bracket case
  1439. // OR something like @import()
  1440. $res = preg_match_all(
  1441. '/(((([A-Za-z_:])([A-Za-z0-9_:\.-]*))' .
  1442. // '/(((([A-Za-z_:])([A-Za-z0-9_:\.-]|[^\x00-\x7F])*)' . -> seems to be taking too much
  1443. // '/(((([A-Za-z_:])([^\x00-\x7F])*)' . -> takes only last letter of parameter name
  1444. '([ \n\t\r]+)?(' .
  1445. // '(=([ \n\t\r]+)?("[^"]+"|\'[^\']+\'|[^ \n\t\r]+))' . -> doesn't restrict close enough to the url itself
  1446. '(=([ \n\t\r]+)?("[^"\)]+"|\'[^\'\)]+\'|[^ \n\t\r\)]+))' .
  1447. '|' .
  1448. // '(\(([ \n\t\r]+)?("[^"]+"|\'[^\']+\'|[^ \n\t\r]+)\))' . -> doesn't restrict close enough to the url itself
  1449. '(\(([ \n\t\r]+)?("[^"\)]+"|\'[^\'\)]+\'|[^ \n\t\r\)]+)\))' .
  1450. '))' .
  1451. '|' .
  1452. // '(@import([ \n\t\r]+)?("[^"]+"|\'[^\']+\'|[^ \n\t\r]+)))?/', -> takes a lot (like 100's of thousands of empty possibilities)
  1453. '(@import([ \n\t\r]+)?("[^"]+"|\'[^\']+\'|[^ \n\t\r]+)))/',
  1454. $attrString,
  1455. $regs
  1456. );
  1457. } catch (Exception $e) {
  1458. error_log('Caught exception: '. $e->getMessage(),0) ;
  1459. }
  1460. if ($res) {
  1461. for ($i = 0; $i < count($regs[1]); $i++) {
  1462. $name = trim($regs[3][$i]);
  1463. $check = trim($regs[0][$i]);
  1464. $value = trim($regs[10][$i]);
  1465. if(empty($value) and !empty($regs[13][$i]))
  1466. {
  1467. $value = $regs[13][$i];
  1468. }
  1469. if(empty($name) && !empty($regs[16][$i]))
  1470. {
  1471. $name = '@import';
  1472. $value = trim($regs[16][$i]);
  1473. }
  1474. if(!empty($name))
  1475. {
  1476. if(!$reduced OR in_array(strtolower($name),$wanted))
  1477. {
  1478. if ($name == $check) {
  1479. $attributes[strtolower($name)][] = strtolower($name);
  1480. } else {
  1481. if (!empty($value) && ($value[0] == '\'' || $value[0] == '"')) {
  1482. $value = substr($value, 1, -1);
  1483. }
  1484. $attributes[strtolower($name)][] = $value;
  1485. }
  1486. }
  1487. }
  1488. }
  1489. }else{
  1490. error_log('preg_match did not find anything',0);
  1491. }
  1492. return $attributes;
  1493. }
  1494. /**
  1495. * Reinits all local values as the learnpath is restarted
  1496. * @return boolean True on success, false otherwise
  1497. */
  1498. function restart()
  1499. {
  1500. if($this->debug>0){error_log('New LP - In learnpathItem::restart()',0);}
  1501. $this->save();
  1502. $allowed = $this->is_restart_allowed();
  1503. if($allowed === -1){
  1504. //nothing allowed, do nothing
  1505. }elseif($allowed === 1){
  1506. //restart as new attempt is allowed, record a new attempt
  1507. $this->attempt_id = $this->attempt_id + 1; //simply reuse the previous attempt_id
  1508. $this->current_score = 0;
  1509. $this->current_start_time = 0;
  1510. $this->current_stop_time = 0;
  1511. $this->current_data = '';
  1512. $this->status = $this->possible_status[0];
  1513. $this->interactions_count = 0;
  1514. $this->interactions = array();
  1515. $this->objectives_count = 0;
  1516. $this->objectives = array();
  1517. $this->lesson_location = '';
  1518. $this->write_to_db();
  1519. }else{
  1520. //restart current element is allowed (because it's not finished yet),
  1521. // reinit current
  1522. $this->current_score = 0;
  1523. $this->current_start_time = 0;
  1524. $this->current_stop_time = 0;
  1525. $this->current_data = '';
  1526. $this->status = $this->possible_status[0];
  1527. }
  1528. return true;
  1529. }
  1530. /**
  1531. * Saves data in the database
  1532. * @param boolean Save from URL params (1) or from object attributes (0)
  1533. * @param boolean The results of a check on prerequisites for this item. True if prerequisites are completed, false otherwise. Defaults to false. Only used if not sco or au
  1534. * @return boolean True on success, false on failure
  1535. */
  1536. function save($from_outside=true,$prereqs_complete=false)
  1537. {
  1538. if($this->debug>0){error_log('New LP - In learnpathItem::save()',0);}
  1539. //$item_view_table = Database::get_course_table(COURSEID,LEARNPATH_ITEM_VIEW_TABLE);
  1540. $item_id = $this->get_id();
  1541. //first check if parameters passed via GET can be saved here
  1542. //in case it's a SCORM, we should get:
  1543. if($this->type == 'sco' || $this->type== 'au'){
  1544. $s = $this->get_status(true);
  1545. if($this->prevent_reinit == 1 AND
  1546. $s != $this->possible_status[0] AND $s != $this->possible_status[1]){
  1547. if($this->debug>1){error_log('New LP - In learnpathItem::save() - save reinit blocked by setting',0);}
  1548. //do nothing because the status has already been set. Don't allow it to change.
  1549. //TODO check there isn't a special circumstance where this should be saved
  1550. }else{
  1551. if($this->debug>1){error_log('New LP - In learnpathItem::save() - SCORM save request received',0);}
  1552. //get all new settings from the URL
  1553. if($from_outside==true){
  1554. if($this->debug>1){error_log('New LP - In learnpathItem::save() - Getting item data from outside',0);}
  1555. foreach($_GET as $param => $value)
  1556. {
  1557. $value = Database::escape_string($value);
  1558. switch($param){
  1559. case 'score':
  1560. $this->set_score($value);
  1561. if($this->debug>2){error_log('New LP - In learnpathItem::save() - setting score to '.$value,0);}
  1562. break;
  1563. case 'max':
  1564. $this->set_max_score($value);
  1565. if($this->debug>2){error_log('New LP - In learnpathItem::save() - setting view_max_score to '.$value,0);}
  1566. break;
  1567. case 'min':
  1568. $this->min_score = $value;
  1569. if($this->debug>2){error_log('New LP - In learnpathItem::save() - setting min_score to '.$value,0);}
  1570. break;
  1571. case 'lesson_status':
  1572. if(!empty($value)){
  1573. $this->set_status($value);
  1574. if($this->debug>2){error_log('New LP - In learnpathItem::save() - setting status to '.$value,0);}
  1575. }
  1576. break;
  1577. case 'time':
  1578. $this->set_time($value);
  1579. if($this->debug>2){error_log('New LP - In learnpathItem::save() - setting time to '.$value,0);}
  1580. break;
  1581. case 'suspend_data':
  1582. $this->current_data = $value;
  1583. if($this->debug>2){error_log('New LP - In learnpathItem::save() - setting suspend_data to '.$value,0);}
  1584. break;
  1585. case 'lesson_location':
  1586. $this->set_lesson_location($value);
  1587. if($this->debug>2){error_log('New LP - In learnpathItem::save() - setting lesson_location to '.$value,0);}
  1588. break;
  1589. case 'core_exit':
  1590. $this->set_core_exit($value);
  1591. if($this->debug>2){error_log('New LP - In learnpathItem::save() - setting core_exit to '.$value,0);}
  1592. break;
  1593. case 'interactions':
  1594. //$interactions = unserialize($value);
  1595. //foreach($interactions as $interaction){
  1596. // ;
  1597. //}
  1598. break;
  1599. case 'objectives':
  1600. break;
  1601. //case 'maxtimeallowed':
  1602. // $this->set_max_time_allowed($value);
  1603. // break;
  1604. /*
  1605. case 'objectives._count':
  1606. $this->attempt_id = $value;
  1607. break;
  1608. */
  1609. default:
  1610. //ignore
  1611. break;
  1612. }
  1613. }
  1614. }else{
  1615. if($this->debug>1){error_log('New LP - In learnpathItem::save() - Using inside item status',0);}
  1616. //do nothing, just let the local attributes be used
  1617. }
  1618. }
  1619. }else{ //if not SCO, such messages should not be expected
  1620. $type = strtolower($this->type);
  1621. switch($type){
  1622. case 'asset':
  1623. if($prereqs_complete)
  1624. {
  1625. $this->set_status($this->possible_status[2]);
  1626. }
  1627. break;
  1628. case TOOL_HOTPOTATOES:
  1629. case TOOL_QUIZ:
  1630. default:
  1631. //for now, everything that is not sco and not asset is set to
  1632. //completed when saved
  1633. if($prereqs_complete)
  1634. {
  1635. $this->set_status($this->possible_status[2]);
  1636. }
  1637. break;
  1638. }
  1639. }
  1640. //$time = $this->time
  1641. if($this->debug>1){error_log('New LP - End of learnpathItem::save() - Calling write_to_db()',0);}
  1642. return $this->write_to_db();
  1643. }
  1644. /**
  1645. * Sets the number of attempt_id to a given value
  1646. * @param integer The given value to set attempt_id to
  1647. * @return boolean TRUE on success, FALSE otherwise
  1648. */
  1649. function set_attempt_id($num)
  1650. {
  1651. if($this->debug>0){error_log('New LP - In learnpathItem::set_attempt_id()',0);}
  1652. if($num == strval(intval($num)) && $num>=0){
  1653. $this->attempt_id = $num;
  1654. return true;
  1655. }
  1656. return false;
  1657. }
  1658. /**
  1659. * Sets the core_exit value to the one given
  1660. */
  1661. function set_core_exit($value)
  1662. {
  1663. switch($value){
  1664. case '':
  1665. $this->core_exit = '';
  1666. break;
  1667. case 'suspend':
  1668. $this->core_exit = 'suspend';
  1669. break;
  1670. default:
  1671. $this->core_exit = 'none';
  1672. break;
  1673. }
  1674. return true;
  1675. }
  1676. /**
  1677. * Sets the item's description
  1678. * @param string Description
  1679. */
  1680. function set_description($string=''){
  1681. if($this->debug>0){error_log('New LP - In learnpathItem::set_description()',0);}
  1682. if(!empty($string)){$this->description = $string;}
  1683. }
  1684. /**
  1685. * Sets the lesson_location value
  1686. * @param string lesson_location as provided by the SCO
  1687. * @return boolean True on success, false otherwise
  1688. */
  1689. function set_lesson_location($location)
  1690. {
  1691. if($this->debug>0){error_log('New LP - In learnpathItem::set_lesson_location()',0);}
  1692. if(isset($location)){
  1693. $this->lesson_location = Database::escape_string($location);
  1694. return true;
  1695. }
  1696. return false;
  1697. }
  1698. /**
  1699. * Sets the item's depth level in the LP tree (0 is at root)
  1700. * @param integer Level
  1701. */
  1702. function set_level($int=0){
  1703. if($this->debug>0){error_log('New LP - In learnpathItem::set_level('.$int.')',0);}
  1704. if(!empty($int) AND $int == strval(intval($int))){$this->level = $int;}
  1705. }
  1706. /**
  1707. * Sets the lp_view id this item view is registered to
  1708. * @param integer lp_view DB ID
  1709. * @todo //todo insert into lp_item_view if lp_view not exists
  1710. */
  1711. function set_lp_view($lp_view_id)
  1712. {
  1713. if($this->debug>0){error_log('New LP - In learnpathItem::set_lp_view('.$lp_view_id.')',0);}
  1714. if(!empty($lp_view_id) and $lp_view_id = intval(strval($lp_view_id)))
  1715. {
  1716. $this->view_id = $lp_view_id;
  1717. $item_view_table = Database::get_course_table('lp_item_view');
  1718. //get the lp_item_view with the highest view_count
  1719. $sql = "SELECT * FROM $item_view_table WHERE lp_item_id = ".$this->get_id()." " .
  1720. " AND lp_view_id = ".$lp_view_id." ORDER BY view_count DESC";
  1721. if($this->debug>2){error_log('New LP - In learnpathItem::set_lp_view() - Querying lp_item_view: '.$sql,0);}
  1722. $res = api_sql_query($sql,__FILE__,__LINE__);
  1723. if(Database::num_rows($res)>0){
  1724. $row = Database::fetch_array($res);
  1725. $this->db_item_view_id = $row['id'];
  1726. $this->attempt_id = $row['view_count'];
  1727. $this->current_score = $row['score'];
  1728. $this->current_data = $row['suspend_data'];
  1729. $this->view_max_score = $row['max_score'];
  1730. //$this->view_min_score = $row['min_score'];
  1731. $this->status = $row['status'];
  1732. $this->current_start_time = $row['start_time'];
  1733. $this->current_stop_time = $this->current_start_time + $row['total_time'];
  1734. $this->lesson_location = $row['lesson_location'];
  1735. $this->core_exit = $row['core_exit'];
  1736. if($this->debug>2){error_log('New LP - In learnpathItem::set_lp_view() - Updated item object with database values',0);}
  1737. //now get the number of interactions for this little guy
  1738. $item_view_interaction_table = Database::get_course_table('lp_iv_interaction');
  1739. $sql = "SELECT * FROM $item_view_interaction_table WHERE lp_iv_id = '".$this->db_item_view_id."'";
  1740. $res = api_sql_query($sql,__FILE__,__LINE__);
  1741. if($res !== false){
  1742. $this->interactions_count = Database::num_rows($res);
  1743. }else{
  1744. $this->interactions_count = 0;
  1745. }
  1746. //now get the number of objectives for this little guy
  1747. $item_view_objective_table = Database::get_course_table('lp_iv_objective');
  1748. $sql = "SELECT * FROM $item_view_objective_table WHERE lp_iv_id = '".$this->db_item_view_id."'";
  1749. $res = api_sql_query($sql,__FILE__,__LINE__);
  1750. if($res !== false){
  1751. $this->objectives_count = Database::num_rows($res);
  1752. }else{
  1753. $this->objectives_count = 0;
  1754. }
  1755. }
  1756. }
  1757. //end
  1758. if($this->debug>2){error_log('New LP - End of learnpathItem::set_lp_view()',0);}
  1759. }
  1760. /**
  1761. * Sets the path
  1762. * @param string Path
  1763. */
  1764. function set_path($string=''){
  1765. if($this->debug>0){error_log('New LP - In learnpathItem::set_path()',0);}
  1766. if(!empty($string)){$this->path = $string;}
  1767. }
  1768. /**
  1769. * Sets the prevent_reinit attribute. This is based on the LP value and is set at creation time for
  1770. * each learnpathItem. It is a (bad?) way of avoiding a reference to the LP when saving an item.
  1771. * @param integer 1 for "prevent", 0 for "don't prevent" saving freshened values (new "not attempted" status etc)
  1772. */
  1773. function set_prevent_reinit($prevent){
  1774. if($this->debug>0){error_log('New LP - In learnpathItem::set_prevent_reinit()',0);}
  1775. if($prevent){
  1776. $this->prevent_reinit = 1;
  1777. }else{
  1778. $this->prevent_reinit = 0;
  1779. }
  1780. }
  1781. /**
  1782. * Sets the score value. If the mastery_score is set and the score reaches
  1783. * it, then set the status to 'passed'.
  1784. * @param float Score
  1785. * @return boolean True on success, false otherwise
  1786. */
  1787. function set_score($score)
  1788. {
  1789. if($this->debug>0){error_log('New LP - In learnpathItem::set_score('.$score.')',0);}
  1790. if(($this->max_score<=0 || $score <= $this->max_score) && ($score >= $this->min_score))
  1791. {
  1792. $this->current_score = $score;
  1793. $master = $this->get_mastery_score();
  1794. $current_status = $this->get_status(false);
  1795. //if mastery_score is set AND the current score reaches the mastery score AND the current status is different from 'completed', then set it to 'passed'
  1796. if($master != -1 && $this->current_score >= $master && $current_status != $this->possible_status[2])
  1797. {
  1798. $this->set_status($this->possible_status[3]);
  1799. }
  1800. elseif($master != -1 && $this->current_score<$master)
  1801. {
  1802. $this->set_status($this->possible_status[4]);
  1803. }
  1804. return true;
  1805. }
  1806. return false;
  1807. }
  1808. /**
  1809. * Sets the maximum score for this item
  1810. * @param int Maximum score - must be a decimal or an empty string
  1811. * @return boolean True on success, false on error
  1812. */
  1813. function set_max_score($score)
  1814. {
  1815. if($this->debug>0){error_log('New LP - In learnpathItem::set_max_score('.$score.')',0);}
  1816. if(is_int($score) or $score == '')
  1817. {
  1818. $this->view_max_score = Database::escape_string($score);
  1819. if($this->debug>1){error_log('New LP - In learnpathItem::set_max_score() - Updated object score of item '.$this->db_id.' to '.$this->view_max_score,0);}
  1820. return true;
  1821. }
  1822. return false;
  1823. }
  1824. /**
  1825. * Sets the status for this item
  1826. * @param string Status - must be one of the values defined in $this->possible_status
  1827. * @return boolean True on success, false on error
  1828. */
  1829. function set_status($status)
  1830. {
  1831. if($this->debug>0){error_log('New LP - In learnpathItem::set_status('.$status.')',0);}
  1832. $found = false;
  1833. foreach($this->possible_status as $possible){
  1834. if(preg_match('/^'.$possible.'$/i',$status)){
  1835. $found = true;
  1836. }
  1837. }
  1838. //if(in_array($status,$this->possible_status))
  1839. if($found)
  1840. {
  1841. $this->status = Database::escape_string($status);
  1842. if($this->debug>1){error_log('New LP - In learnpathItem::set_status() - Updated object status of item '.$this->db_id.' to '.$this->status,0);}
  1843. return true;
  1844. }
  1845. //error_log('New LP - '.$status.' was not in the possible status',0);
  1846. $this->status = $this->possible_status[0];
  1847. return false;
  1848. }
  1849. /**
  1850. * Sets new index terms for item
  1851. * @param string Comma-separated list of terms
  1852. * @return boolean False on error, true otherwise
  1853. */
  1854. function set_terms($terms) {
  1855. $lp_item = Database::get_course_table(TABLE_LP_ITEM);
  1856. require_once(api_get_path(LIBRARY_PATH).'search/DokeosIndexer.class.php');
  1857. $a_terms = split(',',$terms);
  1858. $i_terms = split(',',$this->get_terms());
  1859. foreach ( $i_terms as $term ) {
  1860. if ( !in_array($term,$a_terms) ) { array_push($a_terms,$term); }
  1861. }
  1862. $new_terms = $a_terms;
  1863. $new_terms_string = implode(',',$new_terms);
  1864. $terms_update_sql='';
  1865. //TODO: validate csv string
  1866. $terms_update_sql = "UPDATE $lp_item SET terms = '". Database::escape_string(htmlentities($new_terms_string)) . "' WHERE id=".$this->get_id();
  1867. $res = api_sql_query($terms_update_sql,__FILE__,__LINE__);
  1868. // save it to search engine
  1869. if (api_get_setting('search_enabled') == 'true') {
  1870. $di = new DokeosIndexer();
  1871. $di->update_terms($this->get_search_id(), $new_terms);
  1872. }
  1873. return true;
  1874. }
  1875. /**
  1876. * Sets the item viewing time in a usable form, given that SCORM packages often give it as 00:00:00.0000
  1877. * @param string Time as given by SCORM
  1878. */
  1879. function set_time($scorm_time,$format='scorm')
  1880. {
  1881. if($this->debug>0){error_log('New LP - In learnpathItem::set_time('.$scorm_time.')',0);}
  1882. if($scorm_time == 0 and ($this->type!='sco') and $this->current_start_time!=0){
  1883. $my_time = time() - $this->current_start_time;
  1884. if($my_time > 0){
  1885. $this->update_time($my_time);
  1886. if($this->debug>0){error_log('New LP - In learnpathItem::set_time('.$scorm_time.') - found asset - set time to '.$my_time,0);}
  1887. }
  1888. }else{
  1889. if($format == 'scorm'){
  1890. $res = array();
  1891. if(preg_match('/^(\d{1,4}):(\d{2}):(\d{2})(\.\d{1,4})?/',$scorm_time,$res)){
  1892. $time = time();
  1893. $hour = $res[1];
  1894. $min = $res[2];
  1895. $sec = $res[3];
  1896. //getting total number of seconds spent
  1897. $total_sec = $hour*3600 + $min*60 + $sec;
  1898. $this->update_time($total_sec);
  1899. }
  1900. }elseif($format == 'int'){
  1901. $this->update_time($scorm_time);
  1902. }
  1903. }
  1904. }
  1905. /**
  1906. * Sets the item's title
  1907. * @param string Title
  1908. */
  1909. function set_title($string=''){
  1910. if($this->debug>0){error_log('New LP - In learnpathItem::set_title()',0);}
  1911. if(!empty($string)){$this->title = $string;}
  1912. }
  1913. /**
  1914. * Sets the item's type
  1915. * @param string Type
  1916. */
  1917. function set_type($string=''){
  1918. if($this->debug>0){error_log('New LP - In learnpathItem::set_type()',0);}
  1919. if(!empty($string)){$this->type = $string;}
  1920. }
  1921. /**
  1922. * Checks if the current status is part of the list of status given
  1923. * @param strings_array An array of status to check for. If the current status is one of the strings, return true
  1924. * @return boolean True if the status was one of the given strings, false otherwise
  1925. */
  1926. function status_is($list=array())
  1927. {
  1928. if($this->debug>1){error_log('New LP - In learnpathItem::status_is('.print_r($list,true).') on item '.$this->db_id,0);}
  1929. $mystatus = $this->get_status(true);
  1930. if(empty($mystatus)){
  1931. return false;
  1932. }
  1933. $found = false;
  1934. foreach($list as $status)
  1935. {
  1936. if(preg_match('/^'.$status.'$/i',$mystatus))
  1937. {
  1938. if($this->debug>2){error_log('New LP - learnpathItem::status_is() - Found status '.$status.' corresponding to current status',0);}
  1939. $found = true;
  1940. return $found;
  1941. }
  1942. }
  1943. if($this->debug>2){error_log('New LP - learnpathItem::status_is() - Status '.$mystatus.' did not match request',0);}
  1944. return $found;
  1945. }
  1946. /**
  1947. * Updates the time info according to the given session_time
  1948. * @param integer Time in seconds
  1949. * //TODO @TODO make this method better by allowing better/multiple time slices
  1950. */
  1951. function update_time($total_sec=0){
  1952. if($this->debug>0){error_log('New LP - In learnpathItem::update_time('.$total_sec.')',0);}
  1953. if($total_sec>=0){
  1954. //getting start time from finish time. The only problem in the calculation is it might be
  1955. //modified by the scripts processing time
  1956. $now = time();
  1957. $start = $now-$total_sec;
  1958. $this->current_start_time = $start;
  1959. $this->current_stop_time = $now;
  1960. /*if(empty($this->current_start_time)){
  1961. $this->current_start_time = $start;
  1962. $this->current_stop_time = $now;
  1963. }else{
  1964. //if($this->current_stop_time != $this->current_start_time){
  1965. //if the stop time has already been set before to something else
  1966. //than the start time, add the given time to what's already been
  1967. //recorder.
  1968. //This is the SCORM way of doing things, because the time comes from
  1969. //core.session_time, not core.total_time
  1970. // UPDATE: adding time to previous time is only done on SCORM's finish()
  1971. // call, not normally, so for now ignore this section
  1972. // $this->current_stop_time = $this->current_stop_time + $stop;
  1973. // error_log('New LP - Adding '.$stop.' seconds - now '.$this->current_stop_time,0);
  1974. //}else{
  1975. //if no previous stop time set, use the one just calculated now from
  1976. //start time
  1977. //$this->current_start_time = $start;
  1978. //$this->current_stop_time = $now;
  1979. //error_log('New LP - Setting '.$stop.' seconds - now '.$this->current_stop_time,0);
  1980. //}
  1981. }*/
  1982. }
  1983. }
  1984. /**
  1985. * Write objectives to DB. This method is separate from write_to_db() because otherwise
  1986. * objectives are lost as a side effect to AJAX and session concurrent access
  1987. * @return boolean True or false on error
  1988. */
  1989. function write_objectives_to_db()
  1990. {
  1991. if($this->debug>0){error_log('New LP - In learnpathItem::write_objectives_to_db()',0);}
  1992. if(is_array($this->objectives) && count($this->objectives)>0){
  1993. //save objectives
  1994. $tbl = Database::get_course_table('lp_item_view');
  1995. $sql = "SELECT id FROM $tbl " .
  1996. "WHERE lp_item_id = ".$this->db_id." " .
  1997. "AND lp_view_id = ".$this->view_id." " .
  1998. "AND view_count = ".$this->attempt_id;
  1999. $res = api_sql_query($sql,__FILE__,__LINE__);
  2000. if(Database::num_rows($res)>0){
  2001. $row = Database::fetch_array($res);
  2002. $lp_iv_id = $row[0];
  2003. if($this->debug>2){error_log('New LP - In learnpathItem::write_to_db() - Got item_view_id '.$lp_iv_id.', now checking objectives ',0);}
  2004. foreach($this->objectives as $index => $objective){
  2005. $iva_table = Database::get_course_table('lp_iv_objective');
  2006. $iva_sql = "SELECT id FROM $iva_table " .
  2007. "WHERE lp_iv_id = $lp_iv_id " .
  2008. //"AND order_id = $index";
  2009. //also check for the objective ID as it must be unique for this SCO view
  2010. "AND objective_id = '".Database::escape_string($objective[0])."'";
  2011. $iva_res = api_sql_query($iva_sql,__FILE__,__LINE__);
  2012. //id(0), type(1), time(2), weighting(3),correct_responses(4),student_response(5),result(6),latency(7)
  2013. if(Database::num_rows($iva_res)>0){
  2014. //update (or don't)
  2015. $iva_row = Database::fetch_array($iva_res);
  2016. $iva_id = $iva_row[0];
  2017. $ivau_sql = "UPDATE $iva_table " .
  2018. "SET objective_id = '".Database::escape_string($objective[0])."'," .
  2019. "status = '".Database::escape_string($objective[1])."'," .
  2020. "score_raw = '".Database::escape_string($objective[2])."'," .
  2021. "score_min = '".Database::escape_string($objective[4])."'," .
  2022. "score_max = '".Database::escape_string($objective[3])."' " .
  2023. "WHERE id = $iva_id";
  2024. $ivau_res = api_sql_query($ivau_sql,__FILE__,__LINE__);
  2025. //error_log($ivau_sql,0);
  2026. }else{
  2027. //insert new one
  2028. $ivai_sql = "INSERT INTO $iva_table " .
  2029. "(lp_iv_id, order_id, objective_id, status, score_raw, score_min, score_max )" .
  2030. "VALUES" .
  2031. "(".$lp_iv_id.", ".$index.",'".Database::escape_string($objective[0])."','".Database::escape_string($objective[1])."'," .
  2032. "'".Database::escape_string($objective[2])."','".Database::escape_string($objective[4])."','".Database::escape_string($objective[3])."')";
  2033. $ivai_res = api_sql_query($ivai_sql,__FILE__,__LINE__);
  2034. //error_log($ivai_sql);
  2035. }
  2036. }
  2037. }
  2038. }
  2039. else
  2040. {
  2041. //error_log('no objective to save: '.print_r($this->objectives,1));
  2042. }
  2043. }
  2044. /**
  2045. * Writes the current data to the database
  2046. * @return boolean Query result
  2047. */
  2048. function write_to_db()
  2049. {
  2050. if($this->debug>0){error_log('New LP - In learnpathItem::write_to_db()',0);}
  2051. $mode = $this->get_lesson_mode();
  2052. $credit = $this->get_credit();
  2053. if(($this->type == 'sco') && ($credit == 'no-credit' OR $mode == 'review' OR $mode == 'browse'))
  2054. {
  2055. //this info shouldn't be saved as the credit or lesson mode info prevent it
  2056. if($this->debug>1){error_log('New LP - In learnpathItem::write_to_db() - credit('.$credit.') or lesson_mode('.$mode.') prevent recording!',0);}
  2057. }else{
  2058. //check the row exists
  2059. $item_view_table = Database::get_course_table('lp_item_view');
  2060. $check = "SELECT * FROM $item_view_table " .
  2061. "WHERE lp_item_id = ".$this->db_id. " " .
  2062. "AND lp_view_id = ".$this->view_id. " ".
  2063. "AND view_count = ".$this->get_attempt_id();
  2064. if($this->debug>2){error_log('New LP - In learnpathItem::write_to_db() - Querying item_view: '.$check,0);}
  2065. $check_res = api_sql_query($check);
  2066. //depending on what we want (really), we'll update or insert a new row
  2067. //now save into DB
  2068. $res = 0;
  2069. if(Database::num_rows($check_res)<1){
  2070. $sql = "INSERT INTO $item_view_table " .
  2071. "(total_time, " .
  2072. "start_time, " .
  2073. "score, " .
  2074. "status, " .
  2075. "max_score, ".
  2076. "lp_item_id, " .
  2077. "lp_view_id, " .
  2078. "view_count, " .
  2079. "suspend_data, " .
  2080. //"max_time_allowed," .
  2081. "lesson_location)" .
  2082. "VALUES" .
  2083. "(".$this->get_total_time()."," .
  2084. "".$this->current_start_time."," .
  2085. "".$this->get_score()."," .
  2086. "'".$this->get_status(false)."'," .
  2087. "'".$this->get_max()."'," .
  2088. "".$this->db_id."," .
  2089. "".$this->view_id."," .
  2090. "".$this->get_attempt_id()."," .
  2091. "'".Database::escape_string($this->current_data)."'," .
  2092. //"'".$this->get_max_time_allowed()."'," .
  2093. "'".$this->lesson_location."')";
  2094. if($this->debug>2){error_log('New LP - In learnpathItem::write_to_db() - Inserting into item_view: '.$sql,0);}
  2095. $res = api_sql_query($sql,__FILE__,__LINE__);
  2096. $this->db_item_view_id = Database::get_last_insert_id();
  2097. }else{
  2098. $sql = '';
  2099. if($this->type=='hotpotatoes')
  2100. { //make an exception for HotPotatoes, don't update the score
  2101. //because it has been saved outside of this tool
  2102. $sql = "UPDATE $item_view_table " .
  2103. "SET total_time = ".$this->get_total_time().", " .
  2104. " start_time = ".$this->get_current_start_time().", " .
  2105. " score = ".$this->get_score().", " .
  2106. " status = '".$this->get_status(false)."'," .
  2107. " max_score = '".$this->get_max()."'," .
  2108. " suspend_data = '".Database::escape_string($this->current_data)."'," .
  2109. " lesson_location = '".$this->lesson_location."' " .
  2110. "WHERE lp_item_id = ".$this->db_id." " .
  2111. "AND lp_view_id = ".$this->view_id." " .
  2112. "AND view_count = ".$this->attempt_id;
  2113. }
  2114. else
  2115. { //for all other content types...
  2116. $sql = "UPDATE $item_view_table " .
  2117. "SET total_time = ".$this->get_total_time().", " .
  2118. " start_time = ".$this->get_current_start_time().", " .
  2119. " score = ".$this->get_score().", " .
  2120. " status = '".$this->get_status(false)."'," .
  2121. " max_score = '".$this->get_max()."'," .
  2122. " suspend_data = '".Database::escape_string($this->current_data)."'," .
  2123. //" max_time_allowed = '".$this->get_max_time_allowed()."'," .
  2124. " lesson_location = '".$this->lesson_location."' " .
  2125. "WHERE lp_item_id = ".$this->db_id." " .
  2126. "AND lp_view_id = ".$this->view_id." " .
  2127. "AND view_count = ".$this->attempt_id;
  2128. }
  2129. if($this->debug>2){error_log('New LP - In learnpathItem::write_to_db() - Updating item_view: '.$sql,0);}
  2130. $res = api_sql_query($sql,__FILE__,__LINE__);
  2131. }
  2132. //if(!$res)
  2133. //{
  2134. // $this->error = 'Could not update item_view table...'.mysql_error();
  2135. //}
  2136. if(is_array($this->interactions) && count($this->interactions)>0){
  2137. //save interactions
  2138. $tbl = Database::get_course_table('lp_item_view');
  2139. $sql = "SELECT id FROM $tbl " .
  2140. "WHERE lp_item_id = ".$this->db_id." " .
  2141. "AND lp_view_id = ".$this->view_id." " .
  2142. "AND view_count = ".$this->attempt_id;
  2143. $res = api_sql_query($sql,__FILE__,__LINE__);
  2144. if(Database::num_rows($res)>0){
  2145. $row = Database::fetch_array($res);
  2146. $lp_iv_id = $row[0];
  2147. if($this->debug>2){error_log('New LP - In learnpathItem::write_to_db() - Got item_view_id '.$lp_iv_id.', now checking interactions ',0);}
  2148. foreach($this->interactions as $index => $interaction){
  2149. $correct_resp = '';
  2150. if(is_array($interaction[4]) && !empty($interaction[4][0]) ){
  2151. foreach($interaction[4] as $resp){
  2152. $correct_resp .= $resp.',';
  2153. }
  2154. $correct_resp = substr($correct_resp,0,strlen($correct_resp)-1);
  2155. }
  2156. $iva_table = Database::get_course_table('lp_iv_interaction');
  2157. $iva_sql = "SELECT id FROM $iva_table " .
  2158. "WHERE lp_iv_id = $lp_iv_id " .
  2159. // "AND order_id = $index";
  2160. //also check for the interaction ID as it must be unique for this SCO view
  2161. "AND (order_id = $index " .
  2162. "OR interaction_id = '".$interaction[0]."')";
  2163. $iva_res = api_sql_query($iva_sql,__FILE__,__LINE__);
  2164. //id(0), type(1), time(2), weighting(3),correct_responses(4),student_response(5),result(6),latency(7)
  2165. if(Database::num_rows($iva_res)>0){
  2166. //update (or don't)
  2167. $iva_row = Database::fetch_array($iva_res);
  2168. $iva_id = $iva_row[0];
  2169. $ivau_sql = "UPDATE $iva_table " .
  2170. "SET interaction_id = '".$interaction[0]."'," .
  2171. "interaction_type = '".$interaction[1]."'," .
  2172. "weighting = '".$interaction[3]."'," .
  2173. "completion_time = '".$interaction[2]."'," .
  2174. "correct_responses = '".$correct_resp."'," .
  2175. "student_response = '".$interaction[5]."'," .
  2176. "result = '".$interaction[6]."'," .
  2177. "latency = '".$interaction[7]."'" .
  2178. "WHERE id = $iva_id";
  2179. $ivau_res = api_sql_query($ivau_sql,__FILE__,__LINE__);
  2180. }else{
  2181. //insert new one
  2182. $ivai_sql = "INSERT INTO $iva_table " .
  2183. "(order_id, lp_iv_id, interaction_id, interaction_type, " .
  2184. "weighting, completion_time, correct_responses, " .
  2185. "student_response, result, latency)" .
  2186. "VALUES" .
  2187. "(".$index.",".$lp_iv_id.",'".$interaction[0]."','".$interaction[1]."'," .
  2188. "'".$interaction[3]."','".$interaction[2]."','".$correct_resp."'," .
  2189. "'".$interaction[5]."','".$interaction[6]."','".$interaction[7]."'" .
  2190. ")";
  2191. $ivai_res = api_sql_query($ivai_sql,__FILE__,__LINE__);
  2192. }
  2193. }
  2194. }
  2195. }
  2196. }
  2197. if($this->debug>2){error_log('New LP - End of learnpathItem::write_to_db()',0);}
  2198. return true;
  2199. }
  2200. }
  2201. ?>