From 4e410263ca4936107812c579fea3514d62e6838a Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Wed, 7 Nov 2012 20:23:26 +0100 Subject: [PATCH] Implements a Scorm constraint: If SCO_MasteryScore does not evaluate to a number, passed/failed status won't be set at all. see BT#5153 --- main/newscorm/lp_ajax_save_item.php | 35 +++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/main/newscorm/lp_ajax_save_item.php b/main/newscorm/lp_ajax_save_item.php index 6622e1f0f9..5871d9b613 100644 --- a/main/newscorm/lp_ajax_save_item.php +++ b/main/newscorm/lp_ajax_save_item.php @@ -70,7 +70,7 @@ function save_item($lp_id, $user_id, $view_id, $item_id, $score = -1, $max = -1, //This functions sets the $this->db_item_view_id variable needed in get_status() see BT#5069 $mylpi->set_lp_view($view_id); - if ($prereq_check === true) { + if ($prereq_check === true) { // Launch the prerequisites check and set error if needed //$mylpi =& $mylp->items[$item_id]; //$mylpi->set_lp_view($view_id); @@ -81,18 +81,45 @@ function save_item($lp_id, $user_id, $view_id, $item_id, $score = -1, $max = -1, if (isset($min) && $min != -1 && $min != 'undefined') { $mylpi->min_score = $min; } + if (isset($score) && $score != -1) { if ($debug > 1) { error_log('Calling set_score('.$score.') from xajax', 0); } $mylpi->set_score($score); if ($debug > 1) { error_log('Done calling set_score from xajax - now '.$mylpi->get_score(), 0); } } - if (isset($status) && $status != '' && $status != 'undefined') { + + //Default behaviour + /*if (isset($status) && $status != '' && $status != 'undefined') { if ($debug > 1) { error_log('Calling set_status('.$status.') from xajax', 0); } $mylpi->set_status($status); if ($debug > 1) { error_log('Done calling set_status from xajax - now '.$mylpi->get_status(false), 0); } } + */ + + //Implements scorm 1.2 constraint + /* If SCO_MasteryScore does not evaluate to a number, passed/failed status won't be set at all. */ + + if (isset($status) && $status != '' && $status != 'undefined') { + if ($debug > 1) { error_log('Calling set_status('.$status.') from xajax', 0); } + switch($status) { + case 'failed': + case 'passed': + if (isset($score)) { + //If score is not set then it means that the SCO_MasteryScore was not evaluated + $mylpi->set_status($status); + } + if ($debug > 1) { error_log('Score is not set and status is passed DO NOT update status'); } + break; + default: + if ($debug > 1) { error_log('Status was set'); } + $mylpi->set_status($status); + break; + } + if ($debug > 1) { error_log('Done calling set_status from xajax - now '.$mylpi->get_status(false), 0); } + } // Hack to set status to completed for hotpotatoes if score > 80%. $my_type = $mylpi->get_type(); + if ($my_type == 'hotpotatoes') { if ((empty($status) || $status == 'undefined' || $status == 'not attempted') && $max > 0) { if (($score/$max) > 0.8) { @@ -108,6 +135,7 @@ function save_item($lp_id, $user_id, $view_id, $item_id, $score = -1, $max = -1, if ($debug > 1) { error_log('Done calling set_status from xajax for hotpotatoes - now '.$mylpi->get_status(false), 0); } } } + if (isset($time) && $time!='' && $time!='undefined') { // If big integer, then it's a timestamp, otherwise it's normal scorm time. if ($debug > 1) { error_log('Calling set_time('.$time.') from xajax', 0); } @@ -124,12 +152,15 @@ function save_item($lp_id, $user_id, $view_id, $item_id, $score = -1, $max = -1, } else { $time = $mylpi->get_total_time(); } + if (isset($suspend) && $suspend != '' && $suspend != 'undefined') { $mylpi->current_data = $suspend; //escapetxt($suspend); } + if (isset($location) && $location != '' && $location!='undefined') { $mylpi->set_lesson_location($location); } + // Deal with interactions provided in arrays in the following format: // id(0), type(1), time(2), weighting(3), correct_responses(4), student_response(5), result(6), latency(7) if (is_array($interactions) && count($interactions) > 0) {