From b668f7c3f5ec71856a645ea5d6a15cdf8f765b91 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 7 Aug 2009 16:10:55 -0500 Subject: [PATCH] Fixing scorm results + multiple attempts by iflores see DT#4444 --- main/newscorm/learnpathItem.class.php | 43 ++++++++++++++++++--------- main/newscorm/lp_ajax_save_item.php | 2 +- main/newscorm/scorm_api.php | 9 ++---- 3 files changed, 32 insertions(+), 22 deletions(-) mode change 100644 => 100755 main/newscorm/lp_ajax_save_item.php diff --git a/main/newscorm/learnpathItem.class.php b/main/newscorm/learnpathItem.class.php index 0707beada6..acc49e371c 100755 --- a/main/newscorm/learnpathItem.class.php +++ b/main/newscorm/learnpathItem.class.php @@ -1006,36 +1006,34 @@ class learnpathItem{ * @param boolean Do or don't update the local attribute value with what's been found in DB * @return string Current status or 'Nnot attempted' if no status set yet */ - function get_status($check_db=true,$update_local=false) - { + function get_status($check_db=true,$update_local=false) { if($this->debug>0){error_log('New LP - In learnpathItem::get_status() on item '.$this->db_id,0);} - if($check_db) - { + if($check_db) { if($this->debug>2){error_log('New LP - In learnpathItem::get_status(): checking db',0);} $table = Database::get_course_table('lp_item_view'); $sql = "SELECT * FROM $table WHERE id = '".$this->db_item_view_id."' AND view_count = '".$this->get_attempt_id()."'"; if($this->debug>2){error_log('New LP - In learnpathItem::get_status() - Checking DB: '.$sql,0);} - //error_log($sql); + $res = api_sql_query($sql); - if(Database::num_rows($res)==1){ + if (Database::num_rows($res)==1) { $row = Database::fetch_array($res); if($update_local==true){ $this->set_status($row['status']); } if($this->debug>2){error_log('New LP - In learnpathItem::get_status() - Returning db value '.$row['status'],0);} + error_log("status 1".$row['status']); return $row['status']; } - } - else - { + } else { if($this->debug>2){error_log('New LP - In learnpathItem::get_status() - in get_status: using attrib',0);} - if(!empty($this->status)) - { + if(!empty($this->status)) { if($this->debug>2){error_log('New LP - In learnpathItem::get_status() - Returning attrib: '.$this->status,0);} + error_log("status 2".$this->status); return $this->status; } } if($this->debug>2){error_log('New LP - In learnpathItem::get_status() - Returning default '.$this->possible_status[0],0);} + error_log("status 3".$this->possible_status[0]); return $this->possible_status[0]; } /** @@ -2188,7 +2186,7 @@ function get_terms() $rs_verified=api_sql_query($sql_verified,__FILE__,__LINE__); $row_verified=Database::fetch_array($rs_verified); - $my_case_completed=array('completed','passed','browsed'); + $my_case_completed=array('completed','passed','browsed','failed');//added by isaac flores if (in_array($sql_verified['status'],$my_case_completed)) { $save=false; } else { @@ -2254,6 +2252,7 @@ function get_terms() if ($this->type!=TOOL_QUIZ) { $my_status = $this->get_status(false); }*/ + $sql = "INSERT INTO $item_view_table " . "(total_time, " . "start_time, " . @@ -2355,20 +2354,36 @@ function get_terms() if (in_array($this->get_status(false),$case_completed) && $my_type_lp==2) { //reset zero new attempt ? $my_status = " status = '".$this->get_status(false)."' ,"; - } elseif (!in_array($this->get_status(false),$case_completed) && $my_type_lp==2){ + } elseif (!in_array($this->get_status(false),$case_completed) && $my_type_lp==2){ $total_time =" total_time = ".$this->get_total_time().", "; $my_status = " status = '".$this->get_status(false)."' ,"; } else { //is dokeos LP $total_time =" total_time = total_time +".$this->get_total_time().", "; $my_status = " status = '".$this->get_status(false)."' ,"; - } + } + + //code added by isaac flores + //this code line fix the problem of wrong status + if ( $my_type_lp==2) { + //verify current status in multiples attempts + $sql_status='SELECT status FROM '.$item_view_table.' WHERE lp_item_id="'.$this->db_id.'" AND lp_view_id="'.$this->view_id.'" AND view_count="'.$this->attempt_id.'" '; + $rs_status=Database::query($sql_status,__FILE__,__LINE__); + $current_status=Database::result($rs_status,0,'status'); + if (in_array($current_status,$case_completed)) { + $my_status=''; + $total_time=''; + } else { + $total_time =" total_time = total_time +".$this->get_total_time().", "; + } + } } /*if ($my_type_lp==1 && !in_array($row_verified['status'],$case_completed)) { $total_time =" total_time = total_time + ".$this->get_total_time().", "; }*/ } + $sql = "UPDATE $item_view_table " . "SET " .$total_time. " start_time = ".$this->get_current_start_time().", " . diff --git a/main/newscorm/lp_ajax_save_item.php b/main/newscorm/lp_ajax_save_item.php old mode 100644 new mode 100755 index 82e4fc4671..92a42cd1f2 --- a/main/newscorm/lp_ajax_save_item.php +++ b/main/newscorm/lp_ajax_save_item.php @@ -111,7 +111,7 @@ function save_item($lp_id,$user_id,$view_id,$item_id,$score=-1,$max=-1,$min=-1,$ foreach($interactions as $index=>$interaction){ //$mylpi->add_interaction($index,$interactions[$index]); //fix DT#4444 - $clean_interaction = str_replace('@@',',',$interactions[$index]); + $clean_interaction = str_replace('@.|@',',',$interactions[$index]); $mylpi->add_interaction($index,$clean_interaction); } } diff --git a/main/newscorm/scorm_api.php b/main/newscorm/scorm_api.php index f98b27d455..68da89547b 100755 --- a/main/newscorm/scorm_api.php +++ b/main/newscorm/scorm_api.php @@ -1275,11 +1275,6 @@ function switch_item(current_item, next_item) { xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item); status_info.push(lesson_status); - /*$my_new_old_item=$("#old_item").val(); - $my_new_current_item=$("#current_item_id").val();*/ - - $my_new_old_item=info_lms_item[0]; - $my_new_current_item=info_lms_item[1]; //current item @@ -1471,9 +1466,9 @@ function xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, for (j in interactions[i]) { temp = interactions[i][j]; temp = ''+temp; // if temp == 1 there are problems with indexOf and an integer number - //this fix when an interaction have ',' i.e: {a,b,c,d} is replace to {a@@b@@c@@d} see DT#4444 + //this fix when an interaction have ',' i.e: {a,b,c,d} is replace to {a@.|@b@.|@c@.|@d} see DT#4444 while(temp.indexOf(',') >= 0){ - temp = temp.replace(',','@@'); + temp = temp.replace(',','@.|@'); }; interact_temp +=temp+','; }