Partial fix for sessions tracking bugs in learning paths (see BT#1414)

skala
Yannick Warnier 16 years ago
parent 2fb45f80e6
commit 87de42e390
  1. 5
      main/inc/lib/tracking.lib.php
  2. 8
      main/mySpace/myStudents.php
  3. 16
      main/newscorm/learnpath.class.php
  4. 42
      main/newscorm/lp_stats.php

@ -816,7 +816,7 @@ class Tracking {
* @param int Learning path id
* @return int Total time
*/
public static function get_last_connection_time_in_lp($student_id, $course_code, $lp_id) {
public static function get_last_connection_time_in_lp($student_id, $course_code, $lp_id, $session_id=0) {
$course = CourseManager :: get_course_information($course_code);
$student_id = intval($student_id);
@ -841,7 +841,8 @@ class Tracking {
INNER JOIN ' . $t_lpv . ' AS view
ON item_view.lp_view_id = view.id
AND view.lp_id = '.$lp_id.'
AND view.user_id = '.$student_id;
AND view.user_id = '.$student_id.'
AND view.session_id = '.$session_id;
$rs = Database::query($sql);
if (Database :: num_rows($rs) > 0) {
$last_time = Database :: result($rs, 0, 0);

@ -632,7 +632,7 @@ if ($timezone !== null) {
$any_result = false;
// Get progress in lp
$progress = Tracking::get_avg_student_progress($student_id, $course_code, array($lp_id));
$progress = Tracking::get_avg_student_progress($student_id, $course_code, array($lp_id),$session_id);
if ($progress === null) {
$progress = '0%';
@ -641,15 +641,15 @@ if ($timezone !== null) {
}
// Get time in lp
$total_time = Tracking::get_time_spent_in_lp($student_id, $course_code, array($lp_id));
$total_time = Tracking::get_time_spent_in_lp($student_id, $course_code, array($lp_id),$session_id);
if (!empty($total_time)) $any_result = true;
// Get last connection time in lp
$start_time = Tracking::get_last_connection_time_in_lp($student_id, $course_code, $lp_id);
$start_time = Tracking::get_last_connection_time_in_lp($student_id, $course_code, $lp_id,$session_id);
if (!empty($total_time)) $any_result = true;
// Quizz in lp
$score = Tracking :: get_avg_student_score($student_id, $course_code, array($lp_id));
$score = Tracking :: get_avg_student_score($student_id, $course_code, array($lp_id),$session_id);
if ($i % 2 == 0) $css_class = "row_odd";
else $css_class = "row_even";

@ -168,16 +168,14 @@ class learnpath {
}
//end of variables checking
$session_id = api_get_session_id();
// get the session condition for learning paths of the base + session
$session = api_get_session_condition($session_id,true,true);
//now get the latest attempt from this user on this LP, if available, otherwise create a new one
$lp_table = Database::get_course_table(TABLE_LP_VIEW);
//selecting by view_count descending allows to get the highest view_count first
$session_id = api_get_session_id();
$session = api_get_session_condition($session_id);
$sql = "SELECT * FROM $lp_table WHERE lp_id = '$lp_id' AND user_id = '$user_id' $session ORDER BY view_count DESC";
if ($this->debug > 2) {
error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0);
}
//$res = Database::query($sql);
if ($this->debug > 2) {error_log('New LP - learnpath::__construct() ' . __LINE__ . ' - querying lp_view: ' . $sql, 0);}
$res = Database::query($sql);
$view_id = 0; //used later to query lp_item_view
if (Database :: num_rows($res) > 0) {
@ -1829,8 +1827,10 @@ class learnpath {
*/
public function get_db_progress($lp_id, $user_id, $mode = '%', $course_db = '', $sincere = false) {
//if($this->debug>0){error_log('New LP - In learnpath::get_db_progress()',0);}
$session_id = api_get_session_id();
$session_condition = api_get_session_condition($session_id);
$table = Database :: get_course_table(TABLE_LP_VIEW, $course_db);
$sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id";
$sql = "SELECT * FROM $table WHERE lp_id = $lp_id AND user_id = $user_id $session_condition";
$res = Database::query($sql);
$view_id = 0;
if (Database :: num_rows($res) > 0) {
@ -1978,7 +1978,7 @@ class learnpath {
* @return string HTML string containing the progress bar
*/
public function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) {
//if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar()',0);}
if($this->debug>0){error_log('New LP - In learnpath::get_progress_bar('.$mode.','.$percentage.','.$text_add.','.$from_lp.')',0);}
global $lp_theme_css;
// Setting up the CSS path of the current style if exists

@ -23,6 +23,10 @@ if(empty($_SESSION['_course']['id']) && isset($_GET['course'])) {
if (isset($_GET['student_id'])) {
$student_id = intval($_GET['student_id']);
}
$session_id = 0;
if (isset($_GET['session_id'])) {
$session_id = intval($_GET['session_id']);
}
//The two following variables have to be declared by the includer script
//$lp_id = $_SESSION['oLP']->get_id();
@ -72,7 +76,7 @@ if (!empty($_GET['fs']) && strcmp($_GET['fs'], 'true') == 0) {
$extend_all_link = '';
$extend_all = 0;
if ($origin == 'tracking') {
$url_suffix = '&course=' . Security::remove_XSS($_GET['course']) . '&student_id=' . $student_id . '&lp_id=' . Security::remove_XSS($_GET['lp_id']) . '&origin=' . Security::remove_XSS($_GET['origin']).$from_link;
$url_suffix = '&session_id='.$session_id.'&course=' . Security::remove_XSS($_GET['course']) . '&student_id=' . $student_id . '&lp_id=' . Security::remove_XSS($_GET['lp_id']) . '&origin=' . Security::remove_XSS($_GET['origin']).$from_link;
} else {
$url_suffix = '';
}
@ -98,7 +102,7 @@ $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_E
$tbl_stats_attempts= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
$tbl_quiz_questions= Database :: get_course_table(TABLE_QUIZ_QUESTION);
$sql = "SELECT max(view_count) FROM $TBL_LP_VIEW " .
"WHERE lp_id = $lp_id AND user_id = '" . $user_id . "'";
"WHERE lp_id = $lp_id AND user_id = '" . $user_id . "' AND session_id = $session_id";
$res = Database::query($sql);
$view = '';
$num = 0;
@ -134,9 +138,9 @@ if (isset($_GET['lp_id']) && isset($_GET['my_lp_id'])) {
if (Database::num_rows($res_path) > 0 ){
if ($origin != 'tracking') {
$sql_attempts = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . (int)$row_path['path'] . '" AND exe_user_id="' . (int)api_get_user_id() . '" AND orig_lp_id = "'.(int)$clean_lp_id.'" AND orig_lp_item_id = "'.(int)$clean_lp_item_id.'" AND exe_cours_id="' . $clean_course_code. '" AND status <> "incomplete" ORDER BY exe_date';
$sql_attempts = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . (int)$row_path['path'] . '" AND exe_user_id="' . (int)api_get_user_id() . '" AND orig_lp_id = "'.(int)$clean_lp_id.'" AND orig_lp_item_id = "'.(int)$clean_lp_item_id.'" AND exe_cours_id="' . $clean_course_code. '" AND status <> "incomplete" AND session_id = '.$session_id.' ORDER BY exe_date';
} else {
$sql_attempts = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . (int)$row_path['path'] . '" AND exe_user_id="' . $student_id . '" AND orig_lp_id = "'.(int)$clean_lp_id.'" AND orig_lp_item_id = "'.(int)$clean_lp_item_id.'" AND exe_cours_id="' . $clean_course_code. '" AND status <> "incomplete" ORDER BY exe_date';
$sql_attempts = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . (int)$row_path['path'] . '" AND exe_user_id="' . $student_id . '" AND orig_lp_id = "'.(int)$clean_lp_id.'" AND orig_lp_item_id = "'.(int)$clean_lp_item_id.'" AND exe_cours_id="' . $clean_course_code. '" AND status <> "incomplete" AND session_id = '.$session_id.' ORDER BY exe_date';
}
$sql_attempts;
}
@ -157,11 +161,11 @@ if (is_array($list) && count($list) > 0) {
if (!empty ($view)) {
$sql = "SELECT iv.status as mystatus, v.view_count as mycount, " .
"iv.score as myscore, iv.total_time as mytime, i.id as myid, i.lp_id as mylpid, iv.lp_view_id as mylpviewid, " .
"i.title as mytitle, i.max_score as mymaxscore, " .
"iv.max_score as myviewmaxscore, " .
"i.item_type as item_type, iv.view_count as iv_view_count, " .
"iv.id as iv_id, path as path" .
" iv.score as myscore, iv.total_time as mytime, i.id as myid, i.lp_id as mylpid, iv.lp_view_id as mylpviewid, " .
" i.title as mytitle, i.max_score as mymaxscore, " .
" iv.max_score as myviewmaxscore, " .
" i.item_type as item_type, iv.view_count as iv_view_count, " .
" iv.id as iv_id, path as path" .
" FROM $TBL_LP_ITEM as i, $TBL_LP_ITEM_VIEW as iv, $TBL_LP_VIEW as v" .
" WHERE i.id = iv.lp_item_id " .
" AND i.id = $my_item_id " .
@ -169,20 +173,22 @@ if (is_array($list) && count($list) > 0) {
" AND i.lp_id = $lp_id " .
" AND v.user_id = " . $user_id . " " .
" AND v.view_count = $view " .
" AND v.session_id = $session_id " .
" ORDER BY iv.view_count $qry_order ";
} else {
$sql = "SELECT iv.status as mystatus, v.view_count as mycount, " .
"iv.score as myscore, iv.total_time as mytime, i.id as myid, i.lp_id as mylpid, iv.lp_view_id as mylpviewid, " .
"i.title as mytitle, i.max_score as mymaxscore, " .
"iv.max_score as myviewmaxscore, " .
"i.item_type as item_type, iv.view_count as iv_view_count, " .
"iv.id as iv_id, path as path " .
" iv.score as myscore, iv.total_time as mytime, i.id as myid, i.lp_id as mylpid, iv.lp_view_id as mylpviewid, " .
" i.title as mytitle, i.max_score as mymaxscore, " .
" iv.max_score as myviewmaxscore, " .
" i.item_type as item_type, iv.view_count as iv_view_count, " .
" iv.id as iv_id, path as path " .
" FROM $TBL_LP_ITEM as i, $TBL_LP_ITEM_VIEW as iv, $TBL_LP_VIEW as v " .
" WHERE i.id = iv.lp_item_id " .
" AND i.id = $my_item_id " .
" AND iv.lp_view_id = v.id " .
" AND i.lp_id = $lp_id " .
" AND v.user_id = " . $user_id . " " .
" AND v.session_id = $session_id " .
" ORDER BY iv.view_count $qry_order ";
}
//$sql.'<br/>';
@ -443,9 +449,9 @@ if (is_array($list) && count($list) > 0) {
// selecting the exe_id from stats attempts tables in order to look the max score value
if ($origin != 'tracking') {
$sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . api_get_user_id() . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . $course_code . '" AND status <> "incomplete" ORDER BY exe_date DESC limit 1';
$sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . api_get_user_id() . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . $course_code . '" AND status <> "incomplete" AND session_id = '.$session_id.' ORDER BY exe_date DESC limit 1';
} else {
$sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . $student_id . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . $course_code . '" AND status <> "incomplete" ORDER BY exe_date DESC limit 1';
$sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . $student_id . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . $course_code . '" AND status <> "incomplete" AND session_id = '.$session_id.' ORDER BY exe_date DESC limit 1';
}
$resultLastAttempt = Database::query($sql_last_attempt);
@ -534,10 +540,10 @@ if (is_array($list) && count($list) > 0) {
$my_url_suffix ='';
if ($origin != 'tracking' && $origin != 'tracking_course') {
$my_url_suffix = '&course=' . api_get_course_id() . '&student_id=' . api_get_user_id() . '&lp_id=' . Security::remove_XSS($row['mylpid']);
$sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . api_get_user_id() . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . $course_code . '" AND status <> "incomplete" ORDER BY exe_date DESC ';
$sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . api_get_user_id() . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . $course_code . '" AND status <> "incomplete" AND session_id = '.$session_id.' ORDER BY exe_date DESC ';
} else {
$my_url_suffix = '&course=' . Security::remove_XSS($_GET['course']) . '&student_id=' . $student_id . '&lp_id=' . Security::remove_XSS($row['mylpid']).'&origin=' . Security::remove_XSS($_GET['origin'].$from_link);
$sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . $student_id . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . Database :: escape_string($_GET['course']) . '" AND status <> "incomplete" ORDER BY exe_date DESC ';
$sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . $student_id . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . Database :: escape_string($_GET['course']) . '" AND status <> "incomplete" AND session_id = '.$session_id.' ORDER BY exe_date DESC ';
}
$resultLastAttempt = Database::query($sql_last_attempt);

Loading…
Cancel
Save