|
|
|
@ -247,7 +247,6 @@ class Statistics |
|
|
|
|
default_value_type LIKE '%".$keyword."%' OR |
|
|
|
|
default_value LIKE '%".$keyword."%') "; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
$obj = Database::fetch_object($res); |
|
|
|
|
|
|
|
|
@ -278,9 +277,9 @@ class Statistics |
|
|
|
|
$table_user = Database::get_main_table(TABLE_MAIN_USER); |
|
|
|
|
$access_url_rel_user_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
|
|
|
|
$urlId = api_get_current_access_url_id(); |
|
|
|
|
$column = intval($column); |
|
|
|
|
$from = intval($from); |
|
|
|
|
$numberOfItems = intval($numberOfItems); |
|
|
|
|
$column = (int) $column; |
|
|
|
|
$from = (int) $from; |
|
|
|
|
$numberOfItems = (int) $numberOfItems; |
|
|
|
|
$direction = strtoupper($direction); |
|
|
|
|
|
|
|
|
|
if (!in_array($direction, ['ASC', 'DESC'])) { |
|
|
|
@ -364,6 +363,12 @@ class Statistics |
|
|
|
|
$row['default_date'] = '-'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!empty($row[7])) { |
|
|
|
|
$row[7] = api_get_local_time($row[7]); |
|
|
|
|
} else { |
|
|
|
|
$row[7] = '-'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!empty($row[5])) { |
|
|
|
|
// Course |
|
|
|
|
if (!empty($row[3])) { |
|
|
|
@ -458,6 +463,8 @@ class Statistics |
|
|
|
|
* @param array $stats |
|
|
|
|
* @param bool $showTotal |
|
|
|
|
* @param bool $isFileSize |
|
|
|
|
* |
|
|
|
|
* @return string HTML table |
|
|
|
|
*/ |
|
|
|
|
public static function printStats( |
|
|
|
|
$title, |
|
|
|
@ -466,8 +473,7 @@ class Statistics |
|
|
|
|
$isFileSize = false |
|
|
|
|
) { |
|
|
|
|
$total = 0; |
|
|
|
|
$data = self::rescale($stats); |
|
|
|
|
echo '<table class="data_table" cellspacing="0" cellpadding="3"> |
|
|
|
|
$content = '<table class="data_table" cellspacing="0" cellpadding="3" width="90%"> |
|
|
|
|
<tr><th colspan="'.($showTotal ? '4' : '3').'">'.$title.'</th></tr>'; |
|
|
|
|
$i = 0; |
|
|
|
|
foreach ($stats as $subtitle => $number) { |
|
|
|
@ -482,14 +488,14 @@ class Statistics |
|
|
|
|
} |
|
|
|
|
$percentage = ($total > 0 ? number_format(100 * $number / $total, 1, ',', '.') : '0'); |
|
|
|
|
|
|
|
|
|
echo '<tr class="row_'.(0 == $i % 2 ? 'odd' : 'even').'"> |
|
|
|
|
<td width="150">'.$subtitle.'</td> |
|
|
|
|
<td width="550">'.Display::bar_progress($percentage, false).'</td> |
|
|
|
|
<td align="right">'.$number_label.'</td>'; |
|
|
|
|
$content .= '<tr class="row_'.($i % 2 == 0 ? 'odd' : 'even').'"> |
|
|
|
|
<td width="25%" style="vertical-align:top;">'.$subtitle.'</td> |
|
|
|
|
<td width="60%">'.Display::bar_progress($percentage, false).'</td> |
|
|
|
|
<td width="5%" align="right" style="vertical-align:top;">'.$number_label.'</td>'; |
|
|
|
|
if ($showTotal) { |
|
|
|
|
echo '<td align="right"> '.$percentage.'%</td>'; |
|
|
|
|
$content .= '<td width="5%" align="right"> '.$percentage.'%</td>'; |
|
|
|
|
} |
|
|
|
|
echo '</tr>'; |
|
|
|
|
$content .= '</tr>'; |
|
|
|
|
$i++; |
|
|
|
|
} |
|
|
|
|
if ($showTotal) { |
|
|
|
@ -498,9 +504,11 @@ class Statistics |
|
|
|
|
} else { |
|
|
|
|
$total_label = self::makeSizeString($total); |
|
|
|
|
} |
|
|
|
|
echo '<tr><th colspan="4" align="right">'.get_lang('Total').': '.$total_label.'</td></tr>'; |
|
|
|
|
$content .= '<tr><th colspan="4" align="right">'.get_lang('Total').': '.$total_label.'</td></tr>'; |
|
|
|
|
} |
|
|
|
|
echo '</table>'; |
|
|
|
|
$content .= '</table>'; |
|
|
|
|
|
|
|
|
|
return $content; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -567,16 +575,17 @@ class Statistics |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$content = ''; |
|
|
|
|
if ($sql_last_x) { |
|
|
|
|
$res_last_x = Database::query($sql_last_x); |
|
|
|
|
$result_last_x = []; |
|
|
|
|
while ($obj = Database::fetch_object($res_last_x)) { |
|
|
|
|
$stat_date = ('day' === $type) ? $periodCollection[$obj->stat_date] : $obj->stat_date; |
|
|
|
|
$stat_date = ($type === 'day') ? $periodCollection[$obj->stat_date] : $obj->stat_date; |
|
|
|
|
$result_last_x[$stat_date] = $obj->number_of_logins; |
|
|
|
|
} |
|
|
|
|
self::printStats(get_lang('Last logins').' ('.$period.')', $result_last_x, true); |
|
|
|
|
$content .= self::printStats(get_lang('LastLogins').' ('.$period.')', $result_last_x, true); |
|
|
|
|
flush(); //flush web request at this point to see something already while the full data set is loading |
|
|
|
|
echo '<br />'; |
|
|
|
|
$content .= '<br />'; |
|
|
|
|
} |
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
$result = []; |
|
|
|
@ -594,16 +603,23 @@ class Statistics |
|
|
|
|
} |
|
|
|
|
$result[$stat_date] = $obj->number_of_logins; |
|
|
|
|
} |
|
|
|
|
self::printStats(get_lang('All logins').' ('.$period.')', $result, true); |
|
|
|
|
$content .= self::printStats(get_lang('AllLogins').' ('.$period.')', $result, true); |
|
|
|
|
|
|
|
|
|
return $content; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 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) |
|
|
|
|
* |
|
|
|
|
* @throws Exception |
|
|
|
|
* |
|
|
|
|
* @return string HTML table |
|
|
|
|
*/ |
|
|
|
|
public static function printRecentLoginStats($distinct = false, $sessionDuration = 0) |
|
|
|
|
public static function printRecentLoginStats($distinct = false, $sessionDuration = 0, $periods = []) |
|
|
|
|
{ |
|
|
|
|
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN); |
|
|
|
|
$access_url_rel_user_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
|
|
|
@ -621,11 +637,13 @@ class Statistics |
|
|
|
|
$field = 'DISTINCT(login_user_id)'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$days = [1, 7, 15, 31]; |
|
|
|
|
if (empty($periods)) { |
|
|
|
|
$periods = [1, 7, 31]; |
|
|
|
|
} |
|
|
|
|
$sqlList = []; |
|
|
|
|
|
|
|
|
|
$sessionDuration = (int) $sessionDuration; |
|
|
|
|
foreach ($days as $day) { |
|
|
|
|
$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'; |
|
|
|
|
$endDate = $date->format('Y-m-d').' 23:59:59'; |
|
|
|
@ -642,20 +660,27 @@ class Statistics |
|
|
|
|
if (1 == $day) { |
|
|
|
|
$label = get_lang('Today'); |
|
|
|
|
} |
|
|
|
|
$label .= " <br /> $localDate - $localEndDate"; |
|
|
|
|
$label .= " <span class=\"muted right\" style=\"float: right; margin-right: 5px;\">[$localDate - $localEndDate]</span>"; |
|
|
|
|
$sql = "SELECT count($field) AS number |
|
|
|
|
FROM $table $table_url |
|
|
|
|
WHERE |
|
|
|
|
UNIX_TIMESTAMP(logout_date) - UNIX_TIMESTAMP(login_date) > $sessionDuration AND |
|
|
|
|
login_date BETWEEN '$startDate' AND '$endDate' |
|
|
|
|
WHERE "; |
|
|
|
|
if ($sessionDuration == 0) { |
|
|
|
|
$sql .= " logout_date != login_date AND "; |
|
|
|
|
} else { |
|
|
|
|
$sql .= " UNIX_TIMESTAMP(logout_date) - UNIX_TIMESTAMP(login_date) > $sessionDuration AND "; |
|
|
|
|
} |
|
|
|
|
$sql .= "login_date BETWEEN '$startDate' AND '$endDate' |
|
|
|
|
$where_url"; |
|
|
|
|
$sqlList[$label] = $sql; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$sql = "SELECT count($field) AS number |
|
|
|
|
FROM $table $table_url |
|
|
|
|
WHERE UNIX_TIMESTAMP(logout_date) - UNIX_TIMESTAMP(login_date) > $sessionDuration $where_url |
|
|
|
|
"; |
|
|
|
|
FROM $table $table_url "; |
|
|
|
|
if ($sessionDuration == 0) { |
|
|
|
|
$sql .= " WHERE logout_date != login_date $where_url"; |
|
|
|
|
} else { |
|
|
|
|
$sql .= " WHERE UNIX_TIMESTAMP(logout_date) - UNIX_TIMESTAMP(login_date) > $sessionDuration $where_url"; |
|
|
|
|
} |
|
|
|
|
$sqlList[get_lang('Total')] = $sql; |
|
|
|
|
$totalLogin = []; |
|
|
|
|
foreach ($sqlList as $label => $query) { |
|
|
|
@ -663,55 +688,25 @@ class Statistics |
|
|
|
|
$obj = Database::fetch_object($res); |
|
|
|
|
$totalLogin[$label] = $obj->number; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($distinct) { |
|
|
|
|
self::printStats(get_lang('Distinct users logins'), $totalLogin, false); |
|
|
|
|
$content = self::printStats(get_lang('DistinctUsersLogins'), $totalLogin, false); |
|
|
|
|
} else { |
|
|
|
|
self::printStats(get_lang('Logins'), $totalLogin, false); |
|
|
|
|
} |
|
|
|
|
$content = self::printStats(get_lang('Logins'), $totalLogin, false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static function getLoginCount($startDate, $endDate) |
|
|
|
|
{ |
|
|
|
|
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN); |
|
|
|
|
$access_url_rel_user_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
|
|
|
|
$urlId = api_get_current_access_url_id(); |
|
|
|
|
$table_url = ''; |
|
|
|
|
$where_url = ''; |
|
|
|
|
if (api_is_multiple_url_enabled()) { |
|
|
|
|
$table_url = ", $access_url_rel_user_table"; |
|
|
|
|
$where_url = " AND login_user_id=user_id AND access_url_id='".$urlId."'"; |
|
|
|
|
} |
|
|
|
|
$startDate = Database::escape_string($startDate); |
|
|
|
|
$endDate = Database::escape_string($endDate); |
|
|
|
|
|
|
|
|
|
$sql = " |
|
|
|
|
SELECT count(logins) count FROM ( |
|
|
|
|
SELECT count(login_user_id) AS logins |
|
|
|
|
FROM $table $table_url |
|
|
|
|
WHERE |
|
|
|
|
login_date BETWEEN '$startDate' AND '$endDate' |
|
|
|
|
$where_url |
|
|
|
|
GROUP BY login_user_id |
|
|
|
|
) as t |
|
|
|
|
"; |
|
|
|
|
|
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
$totalLogin = 0; |
|
|
|
|
$row = Database::fetch_array($res, 'ASSOC'); |
|
|
|
|
if ($row) { |
|
|
|
|
$totalLogin = $row['count']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $totalLogin; |
|
|
|
|
return $content; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 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 |
|
|
|
|
* |
|
|
|
|
* @throws Exception |
|
|
|
|
* |
|
|
|
|
* @return array |
|
|
|
|
*/ |
|
|
|
|
public static function getRecentLoginStats($distinct = false, $sessionDuration = 0, $completeMissingDays = true) |
|
|
|
@ -728,7 +723,7 @@ class Statistics |
|
|
|
|
|
|
|
|
|
$now = api_get_utc_datetime(); |
|
|
|
|
$date = new DateTime($now); |
|
|
|
|
$date->sub(new DateInterval('P15D')); |
|
|
|
|
$date->sub(new DateInterval('P31D')); |
|
|
|
|
$newDate = $date->format('Y-m-d h:i:s'); |
|
|
|
|
$totalLogin = self::buildDatesArray($newDate, $now, true); |
|
|
|
|
|
|
|
|
@ -736,13 +731,17 @@ 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 |
|
|
|
|
WHERE |
|
|
|
|
UNIX_TIMESTAMP(logout_date) - UNIX_TIMESTAMP(login_date) > $sessionDuration AND |
|
|
|
|
login_date >= '$newDate' $where_url |
|
|
|
|
WHERE "; |
|
|
|
|
if ($sessionDuration == 0) { |
|
|
|
|
$sql .= " logout_date != login_date AND "; |
|
|
|
|
} else { |
|
|
|
|
$sql .= " UNIX_TIMESTAMP(logout_date) - UNIX_TIMESTAMP(login_date) > $sessionDuration AND "; |
|
|
|
|
} |
|
|
|
|
$sql .= " login_date >= '$newDate' $where_url |
|
|
|
|
GROUP BY date(login_date)"; |
|
|
|
|
|
|
|
|
|
$res = Database::query($sql); |
|
|
|
@ -812,13 +811,15 @@ class Statistics |
|
|
|
|
* Show some stats about the accesses to the different course tools. |
|
|
|
|
* |
|
|
|
|
* @param array $result If defined, this serves as data. Otherwise, will get the data from getToolsStats() |
|
|
|
|
* |
|
|
|
|
* @return string HTML table |
|
|
|
|
*/ |
|
|
|
|
public static function printToolStats($result = null) |
|
|
|
|
{ |
|
|
|
|
if (empty($result)) { |
|
|
|
|
$result = self::getToolsStats(); |
|
|
|
|
} |
|
|
|
|
self::printStats(get_lang('Tools access'), $result, true); |
|
|
|
|
return self::printStats(get_lang('Tools access'), $result, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -876,7 +877,7 @@ class Statistics |
|
|
|
|
$result[get_lang('No')] = $count1->n - $count2->n; |
|
|
|
|
$result[get_lang('Yes')] = $count2->n; // #users with picture |
|
|
|
|
|
|
|
|
|
self::printStats(get_lang('Number of users').' ('.get_lang('Picture').')', $result, true); |
|
|
|
|
return self::printStats(get_lang('Number of users').' ('.get_lang('Picture').')', $result, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -884,7 +885,7 @@ class Statistics |
|
|
|
|
*/ |
|
|
|
|
public static function printActivitiesStats() |
|
|
|
|
{ |
|
|
|
|
echo '<h4>'.get_lang('Important activities').'</h4>'; |
|
|
|
|
$content = '<h4>'.get_lang('Important activities').'</h4>'; |
|
|
|
|
// Create a search-box |
|
|
|
|
$form = new FormValidator( |
|
|
|
|
'search_simple', |
|
|
|
@ -901,9 +902,9 @@ class Statistics |
|
|
|
|
$form->addHidden('activities_column', '4'); |
|
|
|
|
$form->addElement('text', 'keyword', get_lang('Keyword')); |
|
|
|
|
$form->addButtonSearch(get_lang('Search'), 'submit'); |
|
|
|
|
echo '<div class="actions">'; |
|
|
|
|
$form->display(); |
|
|
|
|
echo '</div>'; |
|
|
|
|
$content .= '<div class="actions">'; |
|
|
|
|
$content .= $form->returnForm(); |
|
|
|
|
$content .= '</div>'; |
|
|
|
|
|
|
|
|
|
$table = new SortableTable( |
|
|
|
|
'activities', |
|
|
|
@ -929,7 +930,9 @@ class Statistics |
|
|
|
|
$table->set_header(5, get_lang('Username')); |
|
|
|
|
$table->set_header(6, get_lang('IP address')); |
|
|
|
|
$table->set_header(7, get_lang('Date')); |
|
|
|
|
$table->display(); |
|
|
|
|
$content .= $table->return_table(); |
|
|
|
|
|
|
|
|
|
return $content; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -963,7 +966,8 @@ class Statistics |
|
|
|
|
$defaults['date_diff'] = Security::remove_XSS($_GET['date_diff']); |
|
|
|
|
} |
|
|
|
|
$form->setDefaults($defaults); |
|
|
|
|
$form->display(); |
|
|
|
|
$content = $form->returnForm(); |
|
|
|
|
|
|
|
|
|
$values = $form->exportValues(); |
|
|
|
|
$date_diff = $values['date_diff']; |
|
|
|
|
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LASTACCESS); |
|
|
|
@ -985,7 +989,7 @@ class Statistics |
|
|
|
|
$from = ($page_nr - 1) * $per_page; |
|
|
|
|
$sql .= ' LIMIT '.$from.','.$per_page; |
|
|
|
|
|
|
|
|
|
echo '<p>'.get_lang('Latest access').' >= '.$date_diff.' '.get_lang('days').'</p>'; |
|
|
|
|
$content .= '<p>'.get_lang('Latest access').' >= '.$date_diff.' '.get_lang('days').'</p>'; |
|
|
|
|
$res = Database::query($sql); |
|
|
|
|
if (Database::num_rows($res) > 0) { |
|
|
|
|
$courses = []; |
|
|
|
@ -999,8 +1003,10 @@ class Statistics |
|
|
|
|
} |
|
|
|
|
$parameters['date_diff'] = $date_diff; |
|
|
|
|
$parameters['report'] = 'courselastvisit'; |
|
|
|
|
$table_header[] = [get_lang("Code"), true]; |
|
|
|
|
$table_header[] = [get_lang("Latest access"), true]; |
|
|
|
|
$table_header[] = [get_lang("CourseCode"), true]; |
|
|
|
|
$table_header[] = [get_lang("LastAccess"), true]; |
|
|
|
|
|
|
|
|
|
ob_start(); |
|
|
|
|
Display:: display_sortable_table( |
|
|
|
|
$table_header, |
|
|
|
|
$courses, |
|
|
|
@ -1008,9 +1014,13 @@ class Statistics |
|
|
|
|
[], |
|
|
|
|
$parameters |
|
|
|
|
); |
|
|
|
|
$content .= ob_get_contents(); |
|
|
|
|
ob_end_clean(); |
|
|
|
|
} else { |
|
|
|
|
echo get_lang('No search results'); |
|
|
|
|
$content = get_lang('NoSearchResults'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $content; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -1149,7 +1159,8 @@ class Statistics |
|
|
|
|
$r = $total - $obj->number; |
|
|
|
|
$totalLogin[$index] = $r < 0 ? 0 : $r; |
|
|
|
|
} |
|
|
|
|
self::printStats( |
|
|
|
|
|
|
|
|
|
return self::printStats( |
|
|
|
|
get_lang('Not logged in for some time'), |
|
|
|
|
$totalLogin, |
|
|
|
|
false |
|
|
|
@ -1216,11 +1227,14 @@ class Statistics |
|
|
|
|
success: function(data) { |
|
|
|
|
Chart.defaults.global.responsive = true; |
|
|
|
|
var ctx = document.getElementById("'.$elementId.'").getContext("2d"); |
|
|
|
|
var myLoginChart = new Chart(ctx, { |
|
|
|
|
var chart = new Chart(ctx, { |
|
|
|
|
type: "'.$type.'", |
|
|
|
|
data: data, |
|
|
|
|
options: {'.$options.'} |
|
|
|
|
}); |
|
|
|
|
var title = chart.options.title.text; |
|
|
|
|
$("#'.$elementId.'_title").html(title); |
|
|
|
|
$("#'.$elementId.'_table").html(data.table); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
@ -1229,6 +1243,74 @@ class Statistics |
|
|
|
|
return $chartCode; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static function getJSChartTemplateWithData($data, $type = 'pie', $options = '', $elementId = 'canvas') |
|
|
|
|
{ |
|
|
|
|
$data = json_encode($data); |
|
|
|
|
$chartCode = ' |
|
|
|
|
<script> |
|
|
|
|
$(function() { |
|
|
|
|
Chart.defaults.global.responsive = true; |
|
|
|
|
var ctx = document.getElementById("'.$elementId.'").getContext("2d"); |
|
|
|
|
var chart = new Chart(ctx, { |
|
|
|
|
type: "'.$type.'", |
|
|
|
|
data: '.$data.', |
|
|
|
|
options: {'.$options.'} |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
</script>'; |
|
|
|
|
|
|
|
|
|
return $chartCode; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static function buildJsChartData($all, $chartName) |
|
|
|
|
{ |
|
|
|
|
$list = []; |
|
|
|
|
$palette = ChamiloApi::getColorPalette(true, true); |
|
|
|
|
foreach ($all as $tick => $tock) { |
|
|
|
|
$list['labels'][] = $tick; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$list['datasets'][0]['label'] = $chartName; |
|
|
|
|
$list['datasets'][0]['borderColor'] = 'rgba(255,255,255,1)'; |
|
|
|
|
|
|
|
|
|
$i = 0; |
|
|
|
|
foreach ($all as $tick => $tock) { |
|
|
|
|
$j = $i % count($palette); |
|
|
|
|
$list['datasets'][0]['data'][] = $tock; |
|
|
|
|
$list['datasets'][0]['backgroundColor'][] = $palette[$j]; |
|
|
|
|
$i++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$scoreDisplay = ScoreDisplay::instance(); |
|
|
|
|
$table = new HTML_Table(['class' => 'data_table']); |
|
|
|
|
$headers = [ |
|
|
|
|
get_lang('Name'), |
|
|
|
|
get_lang('Count'), |
|
|
|
|
get_lang('Percentage'), |
|
|
|
|
]; |
|
|
|
|
$row = 0; |
|
|
|
|
$column = 0; |
|
|
|
|
foreach ($headers as $header) { |
|
|
|
|
$table->setHeaderContents($row, $column, $header); |
|
|
|
|
$column++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$total = 0; |
|
|
|
|
foreach ($all as $name => $value) { |
|
|
|
|
$total += $value; |
|
|
|
|
} |
|
|
|
|
$row++; |
|
|
|
|
foreach ($all as $name => $value) { |
|
|
|
|
$table->setCellContents($row, 0, $name); |
|
|
|
|
$table->setCellContents($row, 1, $value); |
|
|
|
|
$table->setCellContents($row, 2, $scoreDisplay->display_score([$value, $total], SCORE_PERCENT)); |
|
|
|
|
$row++; |
|
|
|
|
} |
|
|
|
|
$table = Display::page_subheader2($chartName).$table->toHtml(); |
|
|
|
|
|
|
|
|
|
return ['chart' => $list, 'table' => $table]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Display the Logins By Date report and allow export its result to XLS. |
|
|
|
|
*/ |
|
|
|
@ -1248,15 +1330,12 @@ class Statistics |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Export::arrayToXls($data); |
|
|
|
|
|
|
|
|
|
exit; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
echo Display::page_header(get_lang('Logins by date')); |
|
|
|
|
$content = Display::page_header(get_lang('Logins by date')); |
|
|
|
|
|
|
|
|
|
$actions = ''; |
|
|
|
|
$content = ''; |
|
|
|
|
|
|
|
|
|
$form = new FormValidator('frm_logins_by_date', 'get'); |
|
|
|
|
$form->addDateRangePicker( |
|
|
|
|
'daterange', |
|
|
|
@ -1304,13 +1383,48 @@ class Statistics |
|
|
|
|
$content = $table->toHtml(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$form->display(); |
|
|
|
|
$content .= $form->returnForm(); |
|
|
|
|
|
|
|
|
|
if (!empty($actions)) { |
|
|
|
|
echo Display::toolbarAction('logins_by_date_toolbar', [$actions]); |
|
|
|
|
$content .= Display::toolbarAction('logins_by_date_toolbar', [$actions]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $content; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static function getBossTable($bossId) |
|
|
|
|
{ |
|
|
|
|
$students = UserManager::getUsersFollowedByStudentBoss($bossId); |
|
|
|
|
|
|
|
|
|
if (!empty($students)) { |
|
|
|
|
$table = new HTML_Table(['class' => 'table table-responsive', 'id' => 'table_'.$bossId]); |
|
|
|
|
$headers = [ |
|
|
|
|
get_lang('Name'), |
|
|
|
|
//get_lang('LastName'), |
|
|
|
|
]; |
|
|
|
|
$row = 0; |
|
|
|
|
$column = 0; |
|
|
|
|
foreach ($headers as $header) { |
|
|
|
|
$table->setHeaderContents($row, $column, $header); |
|
|
|
|
$column++; |
|
|
|
|
} |
|
|
|
|
$row++; |
|
|
|
|
foreach ($students as $student) { |
|
|
|
|
$column = 0; |
|
|
|
|
$content = api_get_person_name($student['firstname'], $student['lastname']).''; |
|
|
|
|
$content = '<div style="width: 200px; overflow-wrap: break-word;">'.$content.'</div>'; |
|
|
|
|
$table->setCellContents( |
|
|
|
|
$row, |
|
|
|
|
$column++, |
|
|
|
|
$content |
|
|
|
|
); |
|
|
|
|
$row++; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $table->toHtml(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
echo $content; |
|
|
|
|
return '<table id="table_'.$bossId.'"></table>'; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|