瀏覽代碼

[svn r12448] - Added management of SCORM cmi.core.exit value that needs to be kept in-database to allow for better follow-up of the students interruptions
- Fixed returned values for LMSSetValue() and LMSGetValue() in SCORM API, changed from JavaScript boolean to JavaScript strings ("true" and "false") as SCORM requires

Yannick Warnier 18 年之前
父節點
當前提交
70786d04f2

+ 3 - 1
main/inc/lib/add_course.lib.inc.php

@@ -981,7 +981,9 @@ function update_Db_course($courseDbName)
 		"score			float unsigned not null default 0," . //score returned by SCORM or other techs
 		"status			char(32) not null default 'Not attempted'," . //status for this item (SCORM)
 		"suspend_data	text null default ''," .
-		"lesson_location text null default '')";
+		"lesson_location text null default ''," .
+		"core_exit		varchar(32) not null default 'none'" .
+		")";
 	if(!api_sql_query($sql))
 	{
 		error_log($sql,0);

+ 2 - 1
main/install/migrate-db-1.8.0-1.8.1-pre.sql

@@ -43,4 +43,5 @@ ALTER TABLE lp_item_view ADD INDEX (lp_view_id);
 ALTER TABLE lp_iv_interaction ADD INDEX (lp_iv_id);
 ALTER TABLE quiz_question ADD INDEX (position); 
 ALTER TABLE forum_thread ADD INDEX (forum_id);
-ALTER TABLE forum_thread DROP INDEX thread_id; 
+ALTER TABLE forum_thread DROP INDEX thread_id;
+ALTER TABLE lp_item_view ADD core_exit varchar(32) NOT NULL DEFAULT 'none';

+ 31 - 1
main/newscorm/learnpathItem.class.php

@@ -221,6 +221,13 @@ class learnpathItem{
     	}
     	return $list;
     }
+    /**
+     * Gets the core_exit value from the database
+     */
+    function get_core_exit()
+    {
+    	return $this->core_exit;
+    }
     /**
      * Gets the credit information (rather scorm-stuff) based on current status and reinit
      * autorization. Credit tells the sco(content) if Dokeos will record the data it is sent (credit) or not (no-credit)
@@ -1321,7 +1328,11 @@ class learnpathItem{
 		     			case 'lesson_location':
 		     				$this->set_lesson_location($value);
 		     				if($this->debug>2){error_log('New LP - In learnpathItem::save() - setting lesson_location to '.$value,0);}
-		     				break;	
+		     				break;
+		     			case 'core_exit':
+		     				$this->set_core_exit($value);
+		     				if($this->debug>2){error_log('New LP - In learnpathItem::save() - setting core_exit to '.$value,0);}
+		     				break;
 		     			case 'interactions':
 		     				//$interactions = unserialize($value);
 		     				//foreach($interactions as $interaction){
@@ -1398,6 +1409,24 @@ class learnpathItem{
      	}
      	return false;
     }
+    /**
+     * Sets the core_exit value to the one given
+     */
+    function set_core_exit($value)
+    {
+    	switch($value){
+    		case '':
+    			$this->core_exit = '';
+    			break;
+    		case 'suspend':
+    			$this->core_exit = 'suspend';
+    			break;
+    		default:
+    			$this->core_exit = 'none';
+    			break;
+    	}
+    	return true;
+    }
     /**
      * Sets the item's description
      * @param	string	Description
@@ -1455,6 +1484,7 @@ class learnpathItem{
 				$this->current_start_time	= $row['start_time'];
 				$this->current_stop_time 	= $this->current_start_time + $row['total_time']; 
 				$this->lesson_location  = $row['lesson_location'];
+				$this->core_exit		= $row['core_exit'];
 		     	if($this->debug>2){error_log('New LP - In learnpathItem::set_lp_view() - Updated item object with database values',0);}
 
 		     	//now get the number of interactions for this little guy

+ 9 - 3
main/newscorm/lp_comm.server.php

@@ -54,11 +54,12 @@ function backup_item_details($lp_id,$user_id,$view_id,$item_id,$score=-1,$max=-1
  * @param	string	Session time
  * @param	string	Suspend data
  * @param	string	Lesson location
+ * @param	string	Core exit SCORM string
  */
-function save_item($lp_id,$user_id,$view_id,$item_id,$score=-1,$max=-1,$min=-1,$status='',$time=0,$suspend='',$location='',$interactions=array())
+function save_item($lp_id,$user_id,$view_id,$item_id,$score=-1,$max=-1,$min=-1,$status='',$time=0,$suspend='',$location='',$interactions=array(),$core_exit='none')
 {
 	$debug=0;
-	if($debug>0){error_log('In xajax_save_item('.$lp_id.','.$user_id.','.$view_id.','.$item_id.','.$score.','.$max.','.$min.','.$status.','.$time.',"'.$suspend.'","'.$location.'","'.(count($interactions)>0?$interactions[0]:'').'")',0);}
+	if($debug>0){error_log('In xajax_save_item('.$lp_id.','.$user_id.','.$view_id.','.$item_id.','.$score.','.$max.','.$min.','.$status.','.$time.',"'.$suspend.'","'.$location.'","'.(count($interactions)>0?$interactions[0]:'').'","'.$core_exit.'")',0);}
 	$objResponse = new xajaxResponse();
 	require_once('learnpath.class.php');
 	require_once('scorm.class.php');
@@ -132,6 +133,7 @@ function save_item($lp_id,$user_id,$view_id,$item_id,$score=-1,$max=-1,$min=-1,$
 				$mylpi->add_interaction($index,$interactions[$index]);
 			}
 		}
+		$mylpi->set_core_exit($core_exit);
 		$mylp->save_item($item_id,false);
 	}
 	
@@ -280,7 +282,9 @@ function switch_item_details($lp_id,$user_id,$view_id,$current_item,$next_item)
 			"suspend_data='".$mysuspend_data."';" .
 			"lesson_location='".$mylesson_location."';" .
 			"total_time = '".$mytotal_time."';" .
-			"interactions = new Array();");
+			"interactions = new Array();" .
+			"G_lastError = 0;" .
+			"G_LastErrorMessage = 'No error';");
 	/*
 	 * and re-initialise the rest
 	 * -saved_lesson_status = 'not attempted'
@@ -307,6 +311,7 @@ function switch_item_details($lp_id,$user_id,$view_id,$current_item,$next_item)
 	$mycredit = $mylpi->get_credit();
 	$mylaunch_data = $mylpi->get_launch_data();
 	$myinteractions_count = $mylpi->get_interactions_count();
+	$mycore_exit = $mylpi->get_core_exit();
 	$objResponse->addScript(
 			"saved_lesson_status='not attempted';" .
 			"lms_lp_id=".$lp_id.";" .
@@ -327,6 +332,7 @@ function switch_item_details($lp_id,$user_id,$view_id,$current_item,$next_item)
 			"lms_item_lesson_mode = '".$mylesson_mode."';" .
 			"lms_item_launch_data = '".$mylaunch_data."';" .
 			"lms_item_interactions_count = '".$myinteractions_count."';" .
+			"lms_item_core_exit = '".$mycore_exit."'" .
 			"asset_timer = 0;"
 			);
 	$objResponse->addScript("update_toc('unhighlight','".$current_item."');");

+ 32 - 4
main/newscorm/scorm_api.php

@@ -154,6 +154,7 @@ var lms_item_credit = '<?php echo $oItem->get_credit();?>';
 var lms_item_lesson_mode = '<?php echo $oItem->get_lesson_mode();?>';
 var lms_item_launch_data = '<?php echo $oItem->get_launch_data();?>';
 var lms_item_interactions_count = '<?php echo $oItem->get_interactions_count(); ?>';
+var lms_item_core_exit = '<?php echo $oItem->get_core_exit();?>';
 var asset_timer = 0;
 
 //Backup for old values
@@ -192,7 +193,8 @@ function LMSInitialize() {  //this is the initialize function of all APIobjects
 		//msg_f.src = refresh_url;
 	}
 	*/
-	
+	G_LastError = G_NoError ;
+	G_LastErrorMessage = 'No error';	
 	lms_initialized=1;
 	return('true');
 }
@@ -204,13 +206,27 @@ function Initialize() {  //this is the initialize function of all APIobjects
 
 function LMSGetValue(param) {
 	//logit_scorm("LMSGetValue('"+param+"')",1);
+	G_LastError = G_NoError ;
+	G_LastErrorMessage = 'No error';	
 	var result='';
 	if(param=='cmi.core._children' || param=='cmi.core_children'){
 		result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time';
 	}else if(param == 'cmi.core.entry'){
-		result='';
+		if(lms_item_core_exit=='none')
+		{
+			result='ab-initio';
+		}
+		else if(lms_item_core_exit=='suspend')
+		{
+			result='resume';
+		}
+		else
+		{
+			result='';
+		}
 	}else if(param == 'cmi.core.exit'){
 		result='';
+		G_LastError = G_ElementIsWriteOnly;
 	}else if(param == 'cmi.core.lesson_status'){
 	    if(lesson_status != '') {
 	    	result=lesson_status;
@@ -351,6 +367,9 @@ function GetValue(param) {
 
 function LMSSetValue(param, val) {
 	logit_scorm("LMSSetValue\n\t('"+param+"','"+val+"')",0);
+	G_LastError = G_NoError ;
+	G_LastErrorMessage = 'No error';	
+	return_value = "true";
 	switch(param) {
 	case 'cmi.core.score.raw'		: score= val ;			break;
 	case 'cmi.core.score.max'		: max = val;			break;
@@ -368,6 +387,8 @@ function LMSSetValue(param, val) {
 	case 'cmi.score.scaled'			: score = val ;			break; //1.3
 	case 'cmi.success_status'		: success_status = val; break; //1.3
 	case 'cmi.suspend_data'			: suspend_data = val;   break;
+	case 'cmi.core.exit'			: lms_item_core_exit = val;		break;
+	case 'cmi.core.entry'			: return_value = "false"; G_LastError = G_ElementIsReadOnly; break;
 	default:
 		var myres = new Array();
 		if(myres = param.match(/cmi.interactions.(\d+).(id|time|type|correct_responses|weighting|student_response|result|latency)(.*)/)){
@@ -417,6 +438,7 @@ function LMSSetValue(param, val) {
 					break;
 			}  
 		}else{
+			return_value = "false";
 			G_lastError = G_NotImplementedError;
 			G_lastErrorString = 'Not implemented yet';
 		}
@@ -429,7 +451,7 @@ function LMSSetValue(param, val) {
 		echo "    var mycommit = LMSCommit('force');";
 	}
 	?>
-	return(true);
+	return(return_value);
 }
 
 function SetValue(param, val) {
@@ -452,13 +474,15 @@ function savedata(origin) { //origin can be 'commit', 'finish' or 'terminate'
     ?>/lp_controller.php?cidReq=<?php echo api_get_course_id();?>&action=save&lp_id=<?php echo $oLP->get_id();?>&" + param + "";
 	*/
 	logit_lms('saving data (status='+lesson_status+' - interactions: '+ interactions.length +')',1);
-	xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data, lesson_location, interactions);
+	xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data, lesson_location, interactions, lms_item_core_exit);
 	//xajax_update_pgs();
 	//xajax_update_toc();
 }
 
 function LMSCommit(val) {
 	logit_scorm('LMSCommit()',0);
+	G_LastError = G_NoError ;
+	G_LastErrorMessage = 'No error';	
     commit = true ;
 	savedata('commit');
 	return('true');
@@ -469,6 +493,8 @@ function Commit(val) {
 }
 
 function LMSFinish(val) {
+	G_LastError = G_NoError ;
+	G_LastErrorMessage = 'No error';	
 	if (( commit == false )) { 	
 		logit_scorm('LMSFinish() (no LMSCommit())',1); 
 	}
@@ -512,6 +538,8 @@ function GetDiagnostic(errCode){
 
 function Terminate(){
 	logit_scorm('Terminate()',0);
+	G_LastError = G_NoError ;
+	G_LastErrorMessage = 'No error';	
 	commit = true;
 	savedata('terminate');
 	return (true);