From c0a1e2d5c086c2517f8ae4107ca0a5b00b80243f Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Fri, 22 Nov 2019 01:43:24 +0100 Subject: [PATCH] Work: Count considered_working_time as total time connected to the platform - refs BT#16104 --- main/inc/lib/events.lib.php | 28 +++++++++++++++++++++++++++- main/mySpace/myStudents.php | 2 +- main/work/work.lib.php | 1 + 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/main/inc/lib/events.lib.php b/main/inc/lib/events.lib.php index eba1e5b2fb..32d3488584 100644 --- a/main/inc/lib/events.lib.php +++ b/main/inc/lib/events.lib.php @@ -2260,6 +2260,17 @@ class Event $courseTrackingTable = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); Database::insert($courseTrackingTable, $params); + // Time should also be added to the track_e_login table so as to + // affect total time on the platform + $params = [ + 'login_user_id' => $userId, + 'login_date' => $loginDate, + 'user_ip' => api_get_real_ip(), + 'logout_date' => $logoutDate + ]; + $platformTrackingTable = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN); + Database::insert($platformTrackingTable, $params); + return true; } @@ -2292,6 +2303,7 @@ class Event return false; } $courseTrackingTable = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); + $platformTrackingTable = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN); $courseId = (int) $courseId; $userId = (int) $userId; $sessionId = (int) $sessionId; @@ -2326,8 +2338,22 @@ class Event $courseAccessId = $row[0]; $sql = "DELETE FROM $courseTrackingTable WHERE course_access_id = $courseAccessId"; + Database::query($sql); + } + $sql = "SELECT login_id + FROM $platformTrackingTable + WHERE + login_user_id = $userId AND + (UNIX_TIMESTAMP(logout_date) - UNIX_TIMESTAMP(login_date)) = '$virtualTime' + ORDER BY login_date DESC LIMIT 0,1"; + $result = Database::query($sql); + if (Database::num_rows($result) > 0) { + // Found the latest connection + $row = Database::fetch_row($result); + $loginAccessId = $row[0]; + $sql = "DELETE FROM $platformTrackingTable + WHERE login_id = $loginAccessId"; $result = Database::query($sql); - return $result; } diff --git a/main/mySpace/myStudents.php b/main/mySpace/myStudents.php index 9427bfd158..fb467d5cef 100755 --- a/main/mySpace/myStudents.php +++ b/main/mySpace/myStudents.php @@ -1855,7 +1855,7 @@ if (empty($details)) { echo '('.$documentNumber.')'; $qualification = !empty($results['qualification']) ? $results['qualification'] : '-'; echo ''.$qualification.''; - echo ''.$results['formatted_date'].''; + echo ''.api_convert_and_format_date($results['sent_date_from_db']).' '.$results['expiry_note'].''; $assignment = get_work_assignment_by_id($work->id, $courseInfo['real_id']); echo ''; diff --git a/main/work/work.lib.php b/main/work/work.lib.php index 75b9a7edbf..ae1a691d42 100755 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -2069,6 +2069,7 @@ function get_work_user_list( $work_date = api_get_local_time($work['sent_date']); $date = date_to_str_ago($work['sent_date']).' '.$work_date; $work['formatted_date'] = $work_date.' '.$add_string; + $work['expiry_note'] = $add_string; $work['sent_date_from_db'] = $work['sent_date']; $work['sent_date'] = '
'. $add_string.' '.Display::dateToStringAgoAndLongDate($work['sent_date']).'
';