diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 41d8f067f6..ba1248c7d0 100755 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -1,5 +1,8 @@ * @author Julio Montoya Several improvements and fixes */ -/** - * Defines the learnpath parent class - * @package chamilo.learnpath - */ - class learnpath { public $attempt = 0; // The number for the current ID view. @@ -4039,8 +4037,16 @@ class learnpath $item_id = $this->get_current_item_id(); } if (isset($this->items[$item_id]) && is_object($this->items[$item_id])) { - if ($debug) { error_log('Object exists'); } - $res = $this->items[$item_id]->save($from_outside, $this->prerequisites_match($item_id)); + if ($debug) { + error_log('Object exists'); + } + + // Saving the item. + $res = $this->items[$item_id]->save( + $from_outside, + $this->prerequisites_match($item_id) + ); + if ($debug) { error_log('update_queue before:'); error_log(print_r($this->update_queue,1)); @@ -4063,7 +4069,8 @@ class learnpath /** * Saves the last item seen's ID only in case */ - public function save_last() { + public function save_last() + { $course_id = api_get_course_int_id(); if ($this->debug > 0) { error_log('New LP - In learnpath::save_last()', 0); @@ -9460,6 +9467,24 @@ EOD; { return str_replace(' ', '_', $in_type); } + + /** + * @return \learnpath + */ + public static function getLpFromSession($courseCode, $lp_id, $user_id) + { + $lpObject = Session::read('lpobject'); + $learnPath = null; + if (isset($lpObject)) { + $learnPath = unserialize($lpObject); + } + + if (!is_object($learnPath)) { + $learnPath = new learnpath($courseCode, $lp_id, $user_id); + } + + return $learnPath; + } } if (!function_exists('trim_value')) { diff --git a/main/newscorm/learnpathItem.class.php b/main/newscorm/learnpathItem.class.php index 355f511461..0c80d165fe 100755 --- a/main/newscorm/learnpathItem.class.php +++ b/main/newscorm/learnpathItem.class.php @@ -3742,10 +3742,11 @@ class learnpathItem $item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW); $sql_verified = 'SELECT status FROM ' . $item_view_table . ' - WHERE c_id = ' . $course_id . ' - AND lp_item_id="' . $this->db_id . '" - AND lp_view_id="' . $this->view_id . '" - AND view_count="' . $this->get_attempt_id() . '" ;'; + WHERE + c_id = ' . $course_id . ' AND + lp_item_id="' . $this->db_id . '" AND + lp_view_id="' . $this->view_id . '" AND + view_count="' . $this->get_attempt_id() . '" ;'; $rs_verified = Database::query($sql_verified); $row_verified = Database::fetch_array($rs_verified); @@ -3754,7 +3755,7 @@ class learnpathItem 'passed', 'browsed', 'failed' - ); // Added by Isaac Flores. + ); $save = true; @@ -3765,9 +3766,8 @@ class learnpathItem } if ((($save === false && $this->type == 'sco') || - ($this->type == 'sco' && - ($credit == 'no-credit' OR $mode == 'review' OR $mode == 'browse')) - ) && ($this->seriousgame_mode != 1 && $this->type == 'sco') + ($this->type == 'sco' && ($credit == 'no-credit' OR $mode == 'review' OR $mode == 'browse')) + ) && ($this->seriousgame_mode != 1 && $this->type == 'sco') ) { if (self::debug > 1) { error_log( @@ -3930,11 +3930,8 @@ class learnpathItem //is not multiple attempts if ($this->seriousgame_mode == 1 && $this->type == 'sco') { - $total_time = " total_time = total_time +" . $this->get_total_time( - ) . ", "; - $my_status = " status = '" . $this->get_status( - false - ) . "' ,"; + $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; + $my_status = " status = '" . $this->get_status(false) . "' ,"; } elseif ($this->get_prevent_reinit() == 1) { // Process of status verified into data base. $sql_verified = 'SELECT status FROM ' . $item_view_table . ' @@ -3947,17 +3944,13 @@ class learnpathItem // Get type lp: 1=lp dokeos and 2=scorm. // If not is completed or passed or browsed and learning path is scorm. - if (!in_array( - $this->get_status(false), - $case_completed - ) && $my_type_lp == 2 - ) { //&& $this->type!='dir' + if (!in_array($this->get_status(false), $case_completed) && + $my_type_lp == 2 + ) { $total_time = " total_time = total_time +" . $this->get_total_time() . ", "; - $my_status = " status = '" . $this->get_status( - false - ) . "' ,"; + $my_status = " status = '" . $this->get_status(false) . "' ,"; } else { - // Verified into data base. + // Verified into database. if (!in_array( $row_verified['status'], $case_completed @@ -4052,6 +4045,7 @@ class learnpathItem "WHERE c_id = $course_id AND lp_item_id = " . $this->db_id . " " . "AND lp_view_id = " . $this->view_id . " " . "AND view_count = " . $this->get_attempt_id(); + } else { $sql = "UPDATE $item_view_table " . "SET " . $total_time . @@ -4074,13 +4068,10 @@ class learnpathItem 0 ); } - $res = Database::query($sql); + Database::query($sql); } - if (is_array($this->interactions) && count( - $this->interactions - ) > 0 - ) { + if (is_array($this->interactions) && count($this->interactions) > 0) { // Save interactions. $tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW); $sql = "SELECT id FROM $tbl " . diff --git a/main/newscorm/lp_ajax_initialize.php b/main/newscorm/lp_ajax_initialize.php index c574312c9a..1a3e55fa7f 100755 --- a/main/newscorm/lp_ajax_initialize.php +++ b/main/newscorm/lp_ajax_initialize.php @@ -46,27 +46,7 @@ function initialize_item($lp_id, $user_id, $view_id, $next_item) { * -'last' * - a real item ID */ - - $mylp = ''; - - $lpobject = Session::read('lpobject'); - if (isset($lpobject)) { - $oLP = unserialize($lpobject); - if ($debug) error_log("lpobject was set"); - if (!is_object($oLP)) { - unset($oLP); - $code = api_get_course_id(); - $mylp = new learnpath($code, $lp_id, $user_id); - if ($debug) error_log("Creating learnpath"); - } else { - $mylp = $oLP; - if ($debug) error_log("Loading learnpath from unserialize"); - } - } else { - if ($debug) { - error_log("lpobject was not set"); - } - } + $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id); $mylp->set_current_item($next_item); if ($debug > 1) { error_log('In initialize_item() - new item is '.$next_item, 0); } $mylp->start_current_item(true); diff --git a/main/newscorm/lp_ajax_last_update_status.php b/main/newscorm/lp_ajax_last_update_status.php index f105619534..ffe4ad1775 100755 --- a/main/newscorm/lp_ajax_last_update_status.php +++ b/main/newscorm/lp_ajax_last_update_status.php @@ -49,22 +49,7 @@ function last_update_status($lp_id, $user_id, $view_id, $item_id) { require_once 'scorm.class.php'; require_once 'learnpathItem.class.php'; require_once 'scormItem.class.php'; - $mylp = ''; - if (isset($_SESSION['lpobject'])) { - if ($debug > 1) { error_log('$_SESSION[lpobject] is set', 0); } - $oLP = unserialize($_SESSION['lpobject']); - if (!is_object($oLP)) { - if ($debug > 2) { error_log(print_r($oLP, true), 0); } - if ($debug > 2) { error_log('Building new lp', 0); } - unset($oLP); - $code = api_get_course_id(); - $mylp = new learnpath($code,$lp_id,$user_id); - } else { - if ($debug > 2) { error_log('Reusing session lp', 0); } - $mylp = $oLP; - } - } - error_log(__LINE__); + $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id); // This function should only be used for SCORM paths. if ($mylp->get_type() != 2) { diff --git a/main/newscorm/lp_ajax_save_item.php b/main/newscorm/lp_ajax_save_item.php index f2cc740b93..4a1731c61d 100755 --- a/main/newscorm/lp_ajax_save_item.php +++ b/main/newscorm/lp_ajax_save_item.php @@ -8,9 +8,6 @@ * @package chamilo.learnpath * @author Yannick Warnier */ -/** - * Code - */ use \ChamiloSession as Session; @@ -71,33 +68,7 @@ function save_item( error_log("score: $score - max:$max - min: $min - status:$status - time:$time - suspend: $suspend - location: $location - core_exit: $core_exit"); } - $mylp = null; - $lpobject = Session::read('lpobject'); - /*if (!is_object($lpobject) && isset($sessionId) && isset($courseId)) { - $lpobject = new learnpathItem($lp_id, $user_id, $courseId); - }*/ - - if (isset($lpobject)) { - if (is_object($lpobject)) { - $mylp = $lpobject; - } else { - $oLP = unserialize($lpobject); - if ($debug) error_log("lpobject was set"); - if (!is_object($oLP)) { - unset($oLP); - $code = api_get_course_id(); - $mylp = new learnpath($code, $lp_id, $user_id); - if ($debug) error_log("Creating learnpath"); - } else { - $mylp = $oLP; - if ($debug) error_log("Loading learnpath from unserialize"); - } - } - } else { - if ($debug) { - error_log("lpobject was not set"); - } - } + $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id); if (!is_a($mylp, 'learnpath')) { if ($debug) { @@ -131,7 +102,6 @@ function save_item( } return $return; - } else { if ($debug > 1) { error_log('Prerequisites are OK'); } @@ -205,9 +175,8 @@ function save_item( } else { $time = $mylpi->get_total_time(); } - if (isset($suspend) && $suspend != '' && $suspend != 'undefined') { - $mylpi->current_data = $suspend; //escapetxt($suspend); + $mylpi->current_data = $suspend; } if (isset($location) && $location != '' && $location!='undefined') { diff --git a/main/newscorm/lp_ajax_save_objectives.php b/main/newscorm/lp_ajax_save_objectives.php index a6e4a36fa4..31b7396f53 100755 --- a/main/newscorm/lp_ajax_save_objectives.php +++ b/main/newscorm/lp_ajax_save_objectives.php @@ -38,21 +38,7 @@ function save_objectives($lp_id, $user_id, $view_id, $item_id, $objectives = arr require_once 'learnpathItem.class.php'; require_once 'scormItem.class.php'; require_once 'aiccItem.class.php'; - $mylp = ''; - if (isset($_SESSION['lpobject'])) { - if ($debug > 1) { error_log('$_SESSION[lpobject] is set', 0); } - $oLP =unserialize($_SESSION['lpobject']); - if (!is_object($oLP)) { - if ($debug > 2) { error_log(print_r($oLP,true), 0); } - if ($debug > 2) { error_log('Building new lp', 0); } - unset($oLP); - $code = api_get_course_id(); - $mylp = new learnpath($code, $lp_id, $user_id); - }else{ - if ($debug > 2) { error_log('Reusing session lp', 0); } - $mylp = $oLP; - } - } + $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id); $mylpi =& $mylp->items[$item_id]; //error_log(__FILE__.' '.__LINE__.' '.print_r($objectives,true), 0); if(is_array($objectives) && count($objectives)>0){ diff --git a/main/newscorm/lp_ajax_switch_item.php b/main/newscorm/lp_ajax_switch_item.php index 1e8427ea2b..7f628678e0 100755 --- a/main/newscorm/lp_ajax_switch_item.php +++ b/main/newscorm/lp_ajax_switch_item.php @@ -51,29 +51,7 @@ function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_it require_once 'learnpathItem.class.php'; require_once 'scormItem.class.php'; require_once 'aiccItem.class.php'; - $mylp = ''; - if (isset($_SESSION['lpobject'])) { - if ($debug > 1) { - error_log('$_SESSION[lpobject] is set', 0); - } - $oLP = unserialize($_SESSION['lpobject']); - if (!is_object($oLP)) { - if ($debug > 1) { - error_log(print_r($oLP, true), 0); - } - if ($debug > 2) { - error_log('Building new lp', 0); - } - unset($oLP); - $code = api_get_course_id(); - $mylp = new learnpath($code, $lp_id, $user_id); - } else { - if ($debug > 1) { - error_log('Reusing session lp', 0); - } - $mylp = $oLP; - } - } + $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id); $new_item_id = 0; switch ($next_item) { case 'next': diff --git a/main/newscorm/lp_ajax_switch_item_toc.php b/main/newscorm/lp_ajax_switch_item_toc.php index c636785240..a376053668 100755 --- a/main/newscorm/lp_ajax_switch_item_toc.php +++ b/main/newscorm/lp_ajax_switch_item_toc.php @@ -36,21 +36,7 @@ function switch_item_toc($lp_id, $user_id, $view_id, $current_item, $next_item) require_once 'learnpathItem.class.php'; require_once 'scormItem.class.php'; require_once 'aiccItem.class.php'; - $mylp = ''; - if (isset($_SESSION['lpobject'])) { - if ($debug > 1) { error_log('$_SESSION[lpobject] is set', 0); } - $oLP = unserialize($_SESSION['lpobject']); - if (!is_object($oLP)) { - if ($debug > 1) { error_log(print_r($oLP, true), 0); } - if ($debug > 2) { error_log('Building new lp', 0); } - unset($oLP); - $code = api_get_course_id(); - $mylp = new learnpath($code, $lp_id, $user_id); - } else { - if ($debug > 1) { error_log('Reusing session lp', 0); } - $mylp = $oLP; - } - } + $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id); $new_item_id = 0; switch ($next_item) { case 'next': @@ -87,7 +73,7 @@ function switch_item_toc($lp_id, $user_id, $view_id, $current_item, $next_item) $mylp->start_current_item(true); if ($mylp->force_commit) { $mylp->save_current(); - } + } if (is_object($mylp->items[$new_item_id])) { $mylpi = $mylp->items[$new_item_id]; } else { @@ -181,6 +167,6 @@ function switch_item_toc($lp_id, $user_id, $view_id, $current_item, $next_item) if ($debug > 1) { error_log('Prereq_match() returned '.htmlentities($mylp->error), 0); } $_SESSION['scorm_item_id'] = $new_item_id; // Save the new item ID for the exercise tool to use. $_SESSION['lpobject'] = serialize($mylp); - return $return; + return $return; } -echo switch_item_toc($_POST['lid'], $_POST['uid'], $_POST['vid'], $_POST['iid'], $_POST['next']); \ No newline at end of file +echo switch_item_toc($_POST['lid'], $_POST['uid'], $_POST['vid'], $_POST['iid'], $_POST['next']); diff --git a/main/newscorm/lp_comm.server.php b/main/newscorm/lp_comm.server.php index 2b58b20085..4557aea5bd 100755 --- a/main/newscorm/lp_comm.server.php +++ b/main/newscorm/lp_comm.server.php @@ -73,24 +73,7 @@ function save_item($lp_id, $user_id, $view_id, $item_id, $score = -1, $max = -1, require_once 'learnpathItem.class.php'; require_once 'scormItem.class.php'; require_once 'aiccItem.class.php'; - $mylp = ''; - if (isset($_SESSION['lpobject'])) { - if ($debug > 1) { error_log('$_SESSION[lpobject] is set', 0); } - $oLP = unserialize($_SESSION['lpobject']); - if (!is_object($oLP)) { - if ($debug > 2) { error_log(print_r($oLP, true), 0); } - if ($debug > 2) { error_log('Building new lp', 0); } - unset($oLP); - $code = api_get_course_id(); - $mylp = new learnpath($code, $lp_id, $user_id); - } else { - if ($debug > 2) { error_log('Reusing session lp', 0); } - $mylp = $oLP; - } - } - //$objResponse->addAlert(api_get_path(REL_CODE_PATH).'newscorm/learnpathItem.class.php'); - - + $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id); $prereq_check = $mylp->prerequisites_match($item_id); if ($prereq_check === true) { // Launch the prerequisites check and set error if needed. @@ -144,7 +127,7 @@ function save_item($lp_id, $user_id, $view_id, $item_id, $score = -1, $max = -1, $mycomplete = $mylp->get_complete_items_count(); $myprogress_mode = $mylp->get_progress_bar_mode(); $myprogress_mode = ($myprogress_mode == '' ? '%' : $myprogress_mode); - + //$mylpi->write_to_db(); $_SESSION['lpobject'] = serialize($mylp); if ($mylpi->get_type()!='sco'){ @@ -170,7 +153,7 @@ function save_item($lp_id, $user_id, $view_id, $item_id, $score = -1, $max = -1, $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); - $sql_last_connection = "SELECT login_id, login_date FROM $tbl_track_login + $sql_last_connection = "SELECT login_id, login_date FROM $tbl_track_login WHERE login_user_id='".api_get_user_id()."' ORDER BY login_date DESC LIMIT 0,1"; $q_last_connection = Database::query($sql_last_connection); @@ -205,24 +188,9 @@ function save_objectives($lp_id, $user_id, $view_id, $item_id, $objectives = arr require_once 'learnpathItem.class.php'; require_once 'scormItem.class.php'; require_once 'aiccItem.class.php'; - $mylp = ''; - if (isset($_SESSION['lpobject'])) { - if ($debug > 1) { error_log('$_SESSION[lpobject] is set', 0); } - $oLP = unserialize($_SESSION['lpobject']); - if (!is_object($oLP)) { - if ($debug > 2) { error_log(print_r($oLP, true), 0); } - if ($debug > 2) { error_log('Building new lp', 0); } - unset($oLP); - $code = api_get_course_id(); - $mylp = new learnpath($code,$lp_id,$user_id); - } else { - if ($debug > 2) { error_log('Reusing session lp', 0); } - $mylp = $oLP; - } - } + $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id); $mylpi =& $mylp->items[$item_id]; - //error_log(__FILE__.' '.__LINE__.' '.print_r($objectives,true), 0); - if(is_array($objectives) && count($objectives)>0){ + if (is_array($objectives) && count($objectives)>0){ foreach($objectives as $index=>$objective){ //error_log(__FILE__.' '.__LINE__.' '.$objectives[$index][0], 0); $mylpi->add_objective($index,$objectives[$index]); @@ -259,21 +227,7 @@ function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_it require_once 'learnpathItem.class.php'; require_once 'scormItem.class.php'; require_once 'aiccItem.class.php'; - $mylp = ''; - if (isset($_SESSION['lpobject'])) { - if ($debug > 1) { error_log('$_SESSION[lpobject] is set', 0); } - $oLP = unserialize($_SESSION['lpobject']); - if (!is_object($oLP)) { - if ($debug > 1) { error_log(print_r($oLP, true), 0); } - if ($debug > 2) { error_log('Building new lp', 0); } - unset($oLP); - $code = api_get_course_id(); - $mylp = new learnpath($code,$lp_id,$user_id); - } else { - if ($debug > 1) { error_log('Reusing session lp', 0); } - $mylp = $oLP; - } - } + $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id); $new_item_id = 0; switch ($next_item) { case 'next':