Fix graph see BT#12477

pull/2487/head
jmontoyaa 8 years ago
parent 2c718f9b8d
commit 32c9e8592f
  1. 7
      main/inc/ajax/statistics.ajax.php
  2. 94
      main/inc/lib/statistics.lib.php
  3. 2
      main/lang/english/trad4all.inc.php

@ -1,6 +1,6 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Responses to AJAX calls
*/
@ -16,8 +16,6 @@ switch ($action) {
header('Content-type: application/json');
$list = [];
$all = Statistics::getRecentLoginStats();
$distinct = Statistics::getRecentLoginStats(true);
foreach ($all as $tick => $tock) {
$list['labels'][] = $tick;
}
@ -42,6 +40,7 @@ switch ($action) {
$list['datasets'][1]['pointHighlightFill'] = "#fff";
$list['datasets'][1]['pointHighlightStroke'] = "rgba(0,204,0,1)";
$distinct = Statistics::getRecentLoginStats(true);
foreach ($distinct as $tick => $tock) {
$list['datasets'][1]['data'][] = $tock;
}
@ -49,5 +48,3 @@ switch ($action) {
echo json_encode($list);
break;
}

@ -30,7 +30,8 @@ class Statistics
/**
* Count courses
* @param string $categoryCode Code of a course category. Default: count all courses.
* @param string $categoryCode Code of a course category.
* Default: count all courses.
* @return int Number of courses counted
*/
public static function countCourses($categoryCode = null)
@ -40,18 +41,19 @@ class Statistics
$current_url_id = api_get_current_access_url_id();
if (api_is_multiple_url_enabled()) {
$sql = "SELECT COUNT(*) AS number
FROM ".$course_table." as c, ".$access_url_rel_course_table." as u
FROM ".$course_table." as c, $access_url_rel_course_table as u
WHERE u.c_id = c.id AND access_url_id='".$current_url_id."'";
if (isset ($categoryCode)) {
if (isset($categoryCode)) {
$sql .= " AND category_code = '".Database::escape_string($categoryCode)."'";
}
} else {
$sql = "SELECT COUNT(*) AS number
FROM ".$course_table." ";
if (isset ($categoryCode)) {
FROM $course_table";
if (isset($categoryCode)) {
$sql .= " WHERE category_code = '".Database::escape_string($categoryCode)."'";
}
}
$res = Database::query($sql);
$obj = Database::fetch_object($res);
@ -73,14 +75,14 @@ class Statistics
$current_url_id = api_get_current_access_url_id();
if (api_is_multiple_url_enabled()) {
$sql = "SELECT COUNT(*) AS number
FROM ".$course_table." as c, ".$access_url_rel_course_table." as u
FROM $course_table as c, $access_url_rel_course_table as u
WHERE u.c_id = c.id AND access_url_id='".$current_url_id."'";
if (isset ($visibility)) {
if (isset($visibility)) {
$sql .= " AND visibility = ".intval($visibility);
}
} else {
$sql = "SELECT COUNT(*) AS number FROM ".$course_table." ";
if (isset ($visibility)) {
if (isset($visibility)) {
$sql .= " WHERE visibility = ".intval($visibility);
}
}
@ -160,11 +162,13 @@ class Statistics
if (api_is_multiple_url_enabled()) {
$current_url_id = api_get_current_access_url_id();
$sql = "SELECT COUNT(id) AS number
FROM ".$session_table." as s, ".$access_url_rel_session_table." as u
WHERE u.session_id=s.id AND access_url_id='".$current_url_id."'";
FROM $session_table as s, $access_url_rel_session_table as u
WHERE
u.session_id = s.id AND
access_url_id = '".$current_url_id."'";
} else {
$sql = "SELECT COUNT(id) AS number
FROM ".$session_table." ";
FROM $session_table";
}
$res = Database::query($sql);
$obj = Database::fetch_object($res);
@ -189,7 +193,7 @@ class Statistics
WHERE
default_user_id = user.user_id AND
user.user_id=url.user_id AND
access_url_id='".$current_url_id."'";
access_url_id = '".$current_url_id."'";
} else {
$sql = "SELECT count(default_id) AS total_number_of_items
FROM $track_e_default, $table_user user
@ -277,12 +281,14 @@ class Statistics
} else {
$sql .= " ORDER BY col5 DESC ";
}
$sql .= " LIMIT $from,$numberOfItems ";
$sql .= " LIMIT $from, $numberOfItems ";
$res = Database::query($sql);
$activities = array();
while ($row = Database::fetch_row($res)) {
if (strpos($row[1], '_object') === false && strpos($row[1], '_array') === false) {
if (strpos($row[1], '_object') === false &&
strpos($row[1], '_array') === false
) {
$row[2] = $row[2];
} else {
if (!empty($row[2])) {
@ -332,7 +338,6 @@ class Statistics
$row[6] = get_lang('Unknown');
}
}
$activities[] = $row;
}
@ -391,7 +396,6 @@ class Statistics
{
$total = 0;
$data = self::rescale($stats);
echo '<table class="data_table" cellspacing="0" cellpadding="3">
<tr><th colspan="'.($showTotal ? '4' : '3').'">'.$title.'</th></tr>';
$i = 0;
@ -423,7 +427,7 @@ class Statistics
} else {
$total_label = self::makeSizeString($total);
}
echo '<tr><th colspan="4" align="right">'.get_lang('Total').': '.$total_label.'</td></tr>';
echo '<tr><th colspan="4" align="right">'.get_lang('Total').': '.$total_label.'</td></tr>';
}
echo '</table>';
}
@ -481,6 +485,7 @@ class Statistics
ORDER BY DATE_FORMAT( login_date, '%w' ) ";
break;
}
if ($sql_last_x) {
$res_last_x = Database::query($sql_last_x);
$result_last_x = array();
@ -518,7 +523,6 @@ class Statistics
*/
public static function printRecentLoginStats($distinct = false)
{
$totalLogin = array();
$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);
$current_url_id = api_get_current_access_url_id();
@ -530,18 +534,46 @@ class Statistics
$where_url = '';
}
$now = api_get_utc_datetime();
$field = 'login_user_id';
$field = 'login_id';
if ($distinct) {
$field = 'DISTINCT(login_user_id)';
}
$sql[get_lang('ThisDay')] = "SELECT count($field) AS number FROM $table $table_url WHERE DATE_ADD(login_date, INTERVAL 1 DAY) >= '$now' $where_url";
$sql[get_lang('Last7days')] = "SELECT count($field) AS number FROM $table $table_url WHERE DATE_ADD(login_date, INTERVAL 7 DAY) >= '$now' $where_url";
$sql[get_lang('Last31days')] = "SELECT count($field) AS number FROM $table $table_url WHERE DATE_ADD(login_date, INTERVAL 31 DAY) >= '$now' $where_url";
$sql[get_lang('Total')] = "SELECT count($field) AS number FROM $table $table_url WHERE 1=1 $where_url";
foreach ($sql as $index => $query) {
$days = [
1,
7,
15,
31,
];
$sqlList = [];
foreach ($days as $day) {
$date = new DateTime($now);
$date->sub(new DateInterval('P'.$day.'D'));
$startDate = $date->format('Y-m-d').' 00:00:00';
$endDate = $date->format('Y-m-d').' 23:59:59';
$localDate = api_get_local_time($startDate, null, null, false, false);
if ($day == 1) {
$label = get_lang('Today');
} else {
$label = sprintf(get_lang('LastXDays'), $day).' <br /> ('.$localDate.')';
}
$sql = "SELECT count($field) AS number
FROM $table $table_url
WHERE
login_date BETWEEN '$startDate' AND '$endDate'
$where_url";
$sqlList[$label] = $sql;
}
$sqlList[get_lang('Total')] = "SELECT count($field) AS number FROM $table $table_url WHERE 1=1 $where_url";
$totalLogin = [];
foreach ($sqlList as $label => $query) {
$res = Database::query($query);
$obj = Database::fetch_object($res);
$totalLogin[$index] = $obj->number;
$totalLogin[$label] = $obj->number;
}
if ($distinct) {
self::printStats(get_lang('DistinctUsersLogins'), $totalLogin, false);
@ -557,7 +589,6 @@ class Statistics
*/
public static function getRecentLoginStats($distinct = false)
{
$totalLogin = [];
$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);
$current_url_id = api_get_current_access_url_id();
@ -568,17 +599,23 @@ class Statistics
$table_url = '';
$where_url = '';
}
$now = api_get_utc_datetime();
$field = 'login_user_id';
$date = new DateTime($now);
$date->sub(new DateInterval('P15D'));
$newDate = $date->format('Y-m-d h:i:s');
$field = 'login_id';
if ($distinct) {
$field = 'DISTINCT(login_user_id)';
}
$sql = "SELECT count($field) AS number, date(login_date) as login_date
FROM $table $table_url
WHERE DATE_ADD(login_date, INTERVAL 15 DAY) >= '$now' $where_url
WHERE login_date >= '$newDate' $where_url
GROUP BY date(login_date)";
$res = Database::query($sql);
$totalLogin = [];
while ($row = Database::fetch_array($res, 'ASSOC')) {
$totalLogin[$row['login_date']] = $row['number'];
}
@ -765,7 +802,6 @@ class Statistics
$per_page = isset($_GET['per_page']) ? intval($_GET['per_page']) : 10;
$page_nr = isset($_GET['page_nr']) ? intval($_GET['page_nr']) : 1;
$column = isset($_GET['column']) ? intval($_GET['column']) : 0;
$date_diff = isset($_GET['date_diff']) ? intval($_GET['date_diff']) : 60;
$direction = isset($_GET['direction']) ? $_GET['direction'] : SORT_ASC;
if (!in_array($direction, array(SORT_ASC, SORT_DESC))) {

@ -7636,7 +7636,7 @@ $AssociateForumToLPItem = "Associate a forum to this learning path item";
$ForumDissociated = "Forum dissociated";
$ClickOrDropOneFileHere = "Click or drop one file here";
$ModuloPercentage = "Modulo:\t\t\t%";
$LastXDays = "Last % days";
$LastXDays = "Last %s days";
$ExportBadges = "Export badges";
$LanguagesDisableAllExceptDefault = "Disable all languages except the platform default";
$ThereAreUsersUsingThisLanguagesDisableItManually = "There are users currently using the following language. Please disable manually.";

Loading…
Cancel
Save