From f5c98679573f37b6cfd2529ac3d4ccd727718998 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Mon, 15 Dec 2014 09:49:28 -0500 Subject: [PATCH] List users time in platform - refs BT#9087 --- main/admin/teacher_time_report.php | 16 ++++++++++++---- main/inc/lib/sessionmanager.lib.php | 17 +++++++++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/main/admin/teacher_time_report.php b/main/admin/teacher_time_report.php index bf69a4d2ab..040ce05e00 100644 --- a/main/admin/teacher_time_report.php +++ b/main/admin/teacher_time_report.php @@ -53,10 +53,6 @@ $sessionsList = SessionManager::get_sessions_list(array(), array('name')); $teacherList = SessionManager::getAllCourseCoaches(); -foreach ($courseCoaches as &$coach) { - $coach['totalTime'] = SessionManager::getTotalUserTimeInPlatform($coach['id']); -} - $htmlHeadXtra[] = ' @@ -189,6 +185,18 @@ if (!empty($selectedTeacher)) { } } +if (empty($selectedCourse) && empty($selectedSession) && empty($selectedTeacher)) { + foreach ($teacherList as &$teacher) { + $rows[] = array( + 'coach' => array( + 'username' => $teacher['username'], + 'completeName' => $teacher['completeName'], + ), + 'totalTime' => SessionManager::getTotalUserTimeInPlatform($teacher['id'], $selectedFrom, $selectedUntil) + ); + } +} + // view //hack for daterangepicker $startDate->modify('+1 day'); diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index 942133b481..21c44fb0af 100755 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -5336,21 +5336,30 @@ class SessionManager /** * Calculate the total user time in the platform * @param int $userId The user id + * @param string $from Optional. From date + * @param string $until Optional. Until date * @return string The time (hh:mm:ss) */ - public static function getTotalUserTimeInPlatform($userId) + public static function getTotalUserTimeInPlatform($userId, $from = '', $until = '') { $userId = intval($userId); $trackLoginTable = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); + $whereConditions = array( + 'login_user_id = ?' => $userId + ); + + if (!empty($from) && !empty($until)) { + $whereConditions["AND (login_date >= '?' "] = $from; + $whereConditions["AND logout_date <= '?') "] = $until; + } + $trackResult = Database::select( 'SEC_TO_TIME(SUM(UNIX_TIMESTAMP(logout_date) - UNIX_TIMESTAMP(login_date))) as total_time', $trackLoginTable, array( - 'where' => array( - 'login_user_id = ?' => $userId - ) + 'where' => $whereConditions ), 'first' );