From d6082cb1538c54f651071a14caf8c4f0bf7fcdb2 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Tue, 14 Apr 2020 01:25:12 +0200 Subject: [PATCH] Statistics: Fix query for recent logins using minutes as seconds, finetune stats tables display and add some code documentation - refs BT#17034 --- main/inc/lib/statistics.lib.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/main/inc/lib/statistics.lib.php b/main/inc/lib/statistics.lib.php index 71fe1ff4c0..048e648e9f 100644 --- a/main/inc/lib/statistics.lib.php +++ b/main/inc/lib/statistics.lib.php @@ -446,6 +446,7 @@ class Statistics * @param array $stats * @param bool $showTotal * @param bool $isFileSize + * @return string HTML table */ public static function printStats( $title, @@ -454,7 +455,7 @@ class Statistics $isFileSize = false ) { $total = 0; - $content = ' + $content = '
'; $i = 0; foreach ($stats as $subtitle => $number) { @@ -470,11 +471,11 @@ class Statistics $percentage = ($total > 0 ? number_format(100 * $number / $total, 1, ',', '.') : '0'); $content .= ' - - - '; + + + '; if ($showTotal) { - $content .= ''; + $content .= ''; } $content .= ''; $i++; @@ -591,10 +592,11 @@ class Statistics /** * Print the number of recent logins. - * * @param bool $distinct whether to only give distinct users stats, or *all* logins - * @param int $sessionDuration + * @param int $sessionDuration Number of minutes a session must have lasted at a minimum to be taken into account * @param array $periods List of number of days we want to query (default: [1, 7, 31] for last 1 day, last 7 days, last 31 days) + * @return string HTML table + * @throws Exception */ public static function printRecentLoginStats($distinct = false, $sessionDuration = 0, $periods = []) { @@ -619,7 +621,7 @@ class Statistics } $sqlList = []; - $sessionDuration = (int) $sessionDuration; + $sessionDuration = (int) $sessionDuration * 60; // convert from minutes to seconds foreach ($periods as $day) { $date = new DateTime($now); $startDate = $date->format('Y-m-d').' 00:00:00'; @@ -637,7 +639,7 @@ class Statistics if ($day == 1) { $label = get_lang('Today'); } - $label .= "
$localDate - $localEndDate"; + $label .= " [$localDate - $localEndDate]"; $sql = "SELECT count($field) AS number FROM $table $table_url WHERE "; @@ -676,13 +678,13 @@ class Statistics } /** - * get the number of recent logins. - * + * Get the number of recent logins. * @param bool $distinct Whether to only give distinct users stats, or *all* logins - * @param int $sessionDuration + * @param int $sessionDuration Number of minutes a session must have lasted at a minimum to be taken into account * @param bool $completeMissingDays Whether to fill the daily gaps (if any) when getting a list of logins * * @return array + * @throws Exception */ public static function getRecentLoginStats($distinct = false, $sessionDuration = 0, $completeMissingDays = true) { @@ -706,7 +708,7 @@ class Statistics if ($distinct) { $field = 'DISTINCT(login_user_id)'; } - $sessionDuration = (int) $sessionDuration; + $sessionDuration = (int) $sessionDuration * 60; //Convert from minutes to seconds $sql = "SELECT count($field) AS number, date(login_date) as login_date FROM $table $table_url
'.$title.'
'.$subtitle.''.Display::bar_progress($percentage, false).''.$number_label.''.$subtitle.''.Display::bar_progress($percentage, false).''.$number_label.' '.$percentage.'% '.$percentage.'%