Adding learnpath::getLpFromSession() function instead to call manually.

1.9.x
Julio Montoya 11 years ago
parent 07a5baa4e0
commit fc8d42552b
  1. 41
      main/newscorm/learnpath.class.php
  2. 45
      main/newscorm/learnpathItem.class.php
  3. 22
      main/newscorm/lp_ajax_initialize.php
  4. 17
      main/newscorm/lp_ajax_last_update_status.php
  5. 35
      main/newscorm/lp_ajax_save_item.php
  6. 16
      main/newscorm/lp_ajax_save_objectives.php
  7. 24
      main/newscorm/lp_ajax_switch_item.php
  8. 22
      main/newscorm/lp_ajax_switch_item_toc.php
  9. 58
      main/newscorm/lp_comm.server.php

@ -1,5 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
use \ChamiloSession as Session;
/**
* This class defines the parent attributes and methods for Chamilo learnpaths and SCORM
* learnpaths. It is used by the scorm class.
@ -8,11 +11,6 @@
* @author Yannick Warnier <ywarnier@beeznest.org>
* @author Julio Montoya <gugli100@gmail.com> 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')) {

@ -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 " .

@ -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);

@ -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) {

@ -8,9 +8,6 @@
* @package chamilo.learnpath
* @author Yannick Warnier <ywarnier@beeznest.org>
*/
/**
* 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') {

@ -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){

@ -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':

@ -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']);
echo switch_item_toc($_POST['lid'], $_POST['uid'], $_POST['vid'], $_POST['iid'], $_POST['next']);

@ -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':

Loading…
Cancel
Save