Skip to content
Permalink
Browse files

Add table track_e_access_complete creation see BT#15020

Add conditions api_get_configuration_value('lp_minimum_time')
  • Loading branch information...
jmontoyaa committed Dec 5, 2018
1 parent 85e1093 commit 0d5b3441a862d996190bce5cd98ee78aa70db1b5
Showing with 255 additions and 71 deletions.
  1. +6 −1 main/inc/lib/events.lib.php
  2. +191 −63 main/inc/lib/tracking.lib.php
  3. +1 −0 main/install/configuration.dist.php
  4. +57 −7 main/lp/learnpathItem.class.php
@@ -2458,18 +2458,23 @@ public function portal_homepage_edited_event_send_mail_filter_func(&$values)
/**
* Register the logout of the course (usually when logging out of the platform)
* from the track_e_access_complete table
*
* @param array $logInfo Information stored by local.inc.php
*
* @return bool
*/
public static function registerLog($logInfo)
{
if (!api_get_configuration_value('lp_minimum_time')) {
return false;
}
$loginAs = (int) (Session::read('login_as') === true);
$logInfo['user_id'] = api_get_user_id();
$logInfo['c_id'] = api_get_course_int_id();
$logInfo['session_id'] = api_get_session_id();
$logInfo['url'] = $_SERVER['REQUEST_URI'];
$logInfo['ch_sid'] = $_REQUEST['ch_sid'];
$logInfo['ch_sid'] = session_id();
$logInfo['ip_user'] = api_get_real_ip();
$logInfo['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
$logInfo['login_as'] = $loginAs;
@@ -435,6 +435,16 @@ public static function getLpStats(
$lesson_status = $row['mystatus'];
$score = $row['myscore'];
$time_for_total = $row['mytime'];
// ## NSR sistema de tiempos nuevo
if (api_get_configuration_value('lp_minimum_time')) {
$timeCourse = self::getCalculateTime($user_id, $session_id);
$_SESSION['trackTimeCourse'] = $timeCourse;
$lp_time = $timeCourse[TOOL_LEARNPATH];
$lpTime = (int) $lp_time[$lp_id];
$time_for_total = $lpTime;
}
$time = learnpathItem::getScormTimeFromParameter('js', $row['mytime']);
if ($score == 0) {
@@ -1649,6 +1659,28 @@ public static function get_time_spent_on_the_course(
$rs = Database::query($sql);
$row = Database::fetch_array($rs);
if (api_get_configuration_value('lp_minimum_time')) {
$courseInfo = api_get_course_info_by_id($courseId);
$course_code = $courseInfo['code'];
$sql = "SELECT * FROM c_lp WHERE c_id = $courseId";
$rs = Database::query($sql);
$dataLp = array();
while ($aux = Database::fetch_assoc($rs)) {
$dataLp[] = $aux['id'];
}
$lpTime = Tracking::get_time_spent_in_lp(
$user_id,
$course_code,
$dataLp, //array($_SESSION['oLP']->lp_id),
$session_id
);
if ($row['nb_seconds'] > $lpTime) {
return $row['nb_seconds'];
} else {
return $lpTime;
}
}
return $row['nb_seconds'];
}
@@ -1791,29 +1823,54 @@ public static function get_first_connection_date_on_the_course(
$session_id = 0,
$convert_date = true
) {
$student_id = intval($student_id);
$courseId = intval($courseId);
$session_id = intval($session_id);
$student_id = (int) $student_id;
$courseId = (int) $courseId;
$session_id = (int) $session_id;
$tbl_track_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
$sql = 'SELECT login_course_date
FROM '.$tbl_track_login.'
WHERE
user_id = '.$student_id.' AND
c_id = '.$courseId.' AND
session_id = '.$session_id.'
ORDER BY login_course_date ASC
LIMIT 0,1';
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
if ($first_login_date = Database::result($rs, 0, 0)) {
if ($convert_date) {
return api_convert_and_format_date(
$first_login_date,
DATE_FORMAT_SHORT
);
} else {
return $first_login_date;
if (api_get_configuration_value('lp_minimum_time')) {
$tbl_track_e_access = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
$sql = 'SELECT access_date
FROM '.$tbl_track_e_access.'
WHERE access_user_id = '.$student_id.' AND
c_id = "'.$courseId.'" AND
access_session_id = '.$session_id.'
ORDER BY access_date ASC
LIMIT 0,1';
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
if ($last_login_date = Database::result($rs, 0, 0)) {
if (empty($last_login_date)) {
return false;
}
if ($convert_date) {
return api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT);
} else {
return $last_login_date;
}
}
}
} else {
$tbl_track_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
$sql = 'SELECT login_course_date
FROM '.$tbl_track_login.'
WHERE
user_id = '.$student_id.' AND
c_id = '.$courseId.' AND
session_id = '.$session_id.'
ORDER BY login_course_date ASC
LIMIT 0,1';
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
if ($first_login_date = Database::result($rs, 0, 0)) {
if ($convert_date) {
return api_convert_and_format_date(
$first_login_date,
DATE_FORMAT_SHORT
);
} else {
return $first_login_date;
}
}
}
}
@@ -1841,45 +1898,106 @@ public static function get_last_connection_date_on_the_course(
$student_id = (int) $student_id;
$session_id = (int) $session_id;
$courseId = $courseInfo['real_id'];
$tbl_track_e_access = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
$sql = 'SELECT access_date
if (api_get_configuration_value('lp_minimum_time')) {
// ## NSR - Muestra la última fecha que accedió a la sesión cuando estaba activa
$where_condition = '';
$userInfo = api_get_user_info($student_id);
if ($userInfo['status'] == 5 && $session_id > 0) {
// fin de acceso a la sesión
$sessionInfo = SessionManager::fetch($session_id);
$last_access = $sessionInfo['access_end_date'];
$where_condition = ' AND access_date < "'.$last_access.'" ';
}
$tbl_track_e_access = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
$sql = 'SELECT access_date
FROM '.$tbl_track_e_access.'
WHERE access_user_id = '.$student_id.' AND
c_id = "'.$courseId.'" AND
access_session_id = '.$session_id.'
access_session_id = '.$session_id.$where_condition.'
ORDER BY access_date DESC
LIMIT 0,1';
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
if ($last_login_date = Database::result($rs, 0, 0)) {
if (empty($last_login_date)) {
return false;
}
//see #5736
$last_login_date_timestamp = api_strtotime($last_login_date);
$now = time();
//If the last connection is > than 7 days, the text is red
//345600 = 7 days in seconds
if ($now - $last_login_date_timestamp > 604800) {
if ($convert_date) {
$last_login_date = api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT);
$icon = api_is_allowed_to_edit() ?
'<a href="'.api_get_path(WEB_CODE_PATH).'announcements/announcements.php?action=add&remind_inactive='.$student_id.'&cidReq='.$courseInfo['code'].'" title="'.get_lang('RemindInactiveUser').'">
'.Display::return_icon('messagebox_warning.gif').'
</a>'
: null;
return $icon.Display::label($last_login_date, 'warning');
} else {
return $last_login_date;
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
if ($last_login_date = Database::result($rs, 0, 0)) {
if (empty($last_login_date)) {
return false;
}
} else {
//see #5736
$last_login_date_timestamp = api_strtotime($last_login_date);
$now = time();
//If the last connection is > than 7 days, the text is red
//345600 = 7 days in seconds
/*
if ($now - $last_login_date_timestamp > 604800) {
if ($convert_date) {
$last_login_date = api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT);
$icon = api_is_allowed_to_edit() ?
'<a href="'.api_get_path(WEB_CODE_PATH).'announcements/announcements.php?action=add&remind_inactive='.$student_id.'&cidReq='.$courseInfo['code'].'" title="'.get_lang('RemindInactiveUser').'">
'.Display::return_icon('messagebox_warning.gif').'
</a>'
: null;
return $icon.Display::label($last_login_date, 'warning');
} else {
return $last_login_date;
}
} else {
*/
if ($convert_date) {
return api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT);
} else {
return $last_login_date;
}
//}
}
}
} else {
$tbl_track_e_access = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
$sql = 'SELECT access_date
FROM '.$tbl_track_e_access.'
WHERE access_user_id = '.$student_id.' AND
c_id = "'.$courseId.'" AND
access_session_id = '.$session_id.'
ORDER BY access_date DESC
LIMIT 0,1';
$rs = Database::query($sql);
if (Database::num_rows($rs) > 0) {
if ($last_login_date = Database::result($rs, 0, 0)) {
if (empty($last_login_date)) {
return false;
}
//see #5736
$last_login_date_timestamp = api_strtotime($last_login_date);
$now = time();
//If the last connection is > than 7 days, the text is red
//345600 = 7 days in seconds
if ($now - $last_login_date_timestamp > 604800) {
if ($convert_date) {
$last_login_date = api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT);
$icon = api_is_allowed_to_edit() ?
'<a href="'.api_get_path(
WEB_CODE_PATH
).'announcements/announcements.php?action=add&remind_inactive='.$student_id.'&cidReq='.$courseInfo['code'].'" title="'.get_lang(
'RemindInactiveUser'
).'">
'.Display::return_icon('messagebox_warning.gif').'
</a>'
: null;
return $icon.Display::label($last_login_date, 'warning');
} else {
return $last_login_date;
}
} else {
if ($convert_date) {
return api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT);
} else {
return $last_login_date;
}
}
}
}
}
@@ -6679,21 +6797,30 @@ public static function displayUserSkills($userId, $courseId = 0, $sessionId = 0,
return $html;
}
public static function getCalculateTime($userId, $sessionId, $debug = false) {
$sql = "SELECT session_lifetime
/**
* @param int $userId
* @param int $sessionId
* @param bool $debug
*
* @return array
*/
public static function getCalculateTime($userId, $sessionId, $debug = false)
{
/* $sql = "SELECT session_lifetime
FROM plugin_licences_course_session
WHERE session_id = $sessionId";
$res = Database::query($sql);
$lifeTime = intval(Database::fetch_assoc($res)['session_lifetime']);
$lifeTime = intval(Database::fetch_assoc($res)['session_lifetime']);*/
//error_log("sessionId: $sessionId: $lifeTime");
if ($lifeTime > 0) {
/*if ($lifeTime > 0) {
$sessionLifetime = $lifeTime;
$sessionFixTime = $lifeTime;
} else {
$sessionLifetime = 28800; //intval(api_get_configuration_value('session_lifetime'));
$sessionFixTime = 2700;
}
}*/
$sessionLifetime = 28800; //intval(api_get_configuration_value('session_lifetime'));
$sessionFixTime = 2700;
$total_time = 0;
$course_time = 0;
@@ -6717,9 +6844,10 @@ public static function getCalculateTime($userId, $sessionId, $debug = false) {
$sql = 'SELECT date_reg
FROM track_e_access_complete
WHERE user_id = '.$userId.' AND
session_id = '.$sessionId.' AND
login_as = 0
WHERE
user_id = '.$userId.' AND
session_id = '.$sessionId.' AND
login_as = 0
ORDER BY date_reg ASC
LIMIT 0,1';
$rs = Database::query($sql);
@@ -6735,9 +6863,10 @@ public static function getCalculateTime($userId, $sessionId, $debug = false) {
$sql = 'SELECT date_reg
FROM track_e_access_complete
WHERE user_id = '.$userId.' AND
session_id = '.$sessionId.' AND
login_as = 0
WHERE
user_id = '.$userId.' AND
session_id = '.$sessionId.' AND
login_as = 0
ORDER BY date_reg DESC
LIMIT 0,1';
$rs = Database::query($sql);
@@ -6746,7 +6875,7 @@ public static function getCalculateTime($userId, $sessionId, $debug = false) {
if (empty($last_login_date)) {
$lastConection = '';
} else {
$lastConection = date("d/m/Y H:i:s", strtotime($last_login_date));
$lastConection = date('d/m/Y H:i:s', strtotime($last_login_date));
}
} else { $lastConection = ''; }
} else { $lastConection = ''; }
@@ -7057,7 +7186,6 @@ public static function getCalculateTime($userId, $sessionId, $debug = false) {
);
return $result;
}
/**
@@ -1048,6 +1048,7 @@
// Add a minimum time limit to be in the learning path
// in order to get the last item completed
// Requires a DB change:
// CREATE TABLE track_e_access_complete (id int(11) NOT NULL AUTO_INCREMENT, user_id int(11) NOT NULL, date_reg datetime NOT NULL, tool varchar(255) NOT NULL, tool_id int(11) NOT NULL, tool_id_detail int(11) NOT NULL, action varchar(255) NOT NULL, action_details varchar(255) NOT NULL, current_id int(11) NOT NULL, ip_user varchar(255) NOT NULL, user_agent varchar(255) NOT NULL, session_id int(11) NOT NULL, c_id int(11) NOT NULL, ch_sid varchar(255) NOT NULL, login_as int(11) NOT NULL, info longtext NOT NULL, url text NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB AUTO_INCREMENT=13989 DEFAULT CHARSET=utf8;
// ALTER TABLE c_lp ADD accumulate_work_time INT NOT NULL;
//$_configuration['lp_minimum_time'] = false;

0 comments on commit 0d5b344

Please sign in to comment.
You can’t perform that action at this time.