Minor - Code style change

1.10.x
Yannick Warnier 10 years ago
parent d345f0f00a
commit f3ef5f9b32
  1. 48
      main/admin/statistics/index.php
  2. 8
      main/inc/ajax/admin.ajax.php
  3. 230
      main/inc/lib/statistics.lib.php
  4. 2
      main/tracking/courseLogCSV.php
  5. 16
      plugin/dashboard/block_global_info/block_global_info.class.php
  6. 311
      tests/main/admin/statistics/statistics.lib.test.php

@ -61,77 +61,77 @@ foreach ($tools as $section => $items) {
}
echo '</tr></table>';
$course_categories = Statistics::get_course_categories();
$course_categories = Statistics::getCourseCategories();
echo '<br/><br/>';//@todo: spaces between elements should be handled in the css, br should be removed if only there for presentation
switch ($_REQUEST['report']) {
case 'courses':
// total amount of courses
foreach ($course_categories as $code => $name) {
$courses[$name] = Statistics::count_courses($code);
$courses[$name] = Statistics::countCourses($code);
}
// courses for each course category
Statistics::print_stats(get_lang('CountCours'), $courses);
Statistics::printStats(get_lang('CountCours'), $courses);
break;
case 'tools':
Statistics::print_tool_stats();
Statistics::printToolStats();
break;
case 'coursebylanguage':
Statistics::print_course_by_language_stats();
Statistics::printCourseByLanguageStats();
break;
case 'courselastvisit':
Statistics::print_course_last_visit();
Statistics::printCourseLastVisit();
break;
case 'users':
// total amount of users
Statistics::print_stats(
Statistics::printStats(
get_lang('NumberOfUsers'),
array(
get_lang('Teachers') => Statistics::count_users(1, null, $_GET['count_invisible_courses']),
get_lang('Students') => Statistics::count_users(5, null, $_GET['count_invisible_courses'])
get_lang('Teachers') => Statistics::countUsers(1, null, $_GET['count_invisible_courses']),
get_lang('Students') => Statistics::countUsers(5, null, $_GET['count_invisible_courses'])
)
);
$teachers = $students = array();
$countInvisible = isset($_GET['count_invisible_courses']) ? $_GET['count_invisible_courses'] : null;
foreach ($course_categories as $code => $name) {
$name = str_replace(get_lang('Department'), "", $name);
$teachers[$name] = Statistics::count_users(1, $code, $countInvisible);
$students[$name] = Statistics::count_users(5, $code, $countInvisible);
$teachers[$name] = Statistics::countUsers(1, $code, $countInvisible);
$students[$name] = Statistics::countUsers(5, $code, $countInvisible);
}
// docents for each course category
Statistics::print_stats(get_lang('Teachers'), $teachers);
Statistics::printStats(get_lang('Teachers'), $teachers);
// students for each course category
Statistics::print_stats(get_lang('Students'), $students);
Statistics::printStats(get_lang('Students'), $students);
break;
case 'recentlogins':
Statistics::print_recent_login_stats();
Statistics::printRecentLoginStats();
break;
case 'logins':
Statistics::print_login_stats($_GET['type']);
Statistics::printLoginStats($_GET['type']);
break;
case 'pictures':
Statistics::print_user_pictures_stats();
Statistics::printUserPicturesStats();
break;
case 'no_login_users':
Statistics::print_users_not_logged_in_stats();
Statistics::printUsersNotLoggedInStats();
break;
case 'zombies':
ZombieReport::create(array('report' => 'zombies'))->display();
break;
case 'activities':
Statistics::print_activities_stats();
Statistics::printActivitiesStats();
break;
case 'messagesent':
$messages_sent = Statistics::get_messages('sent');
Statistics::print_stats(get_lang('MessagesSent'), $messages_sent);
$messages_sent = Statistics::getMessages('sent');
Statistics::printStats(get_lang('MessagesSent'), $messages_sent);
break;
case 'messagereceived':
$messages_received = Statistics::get_messages('received');
Statistics::print_stats(get_lang('MessagesReceived'), $messages_received);
$messages_received = Statistics::getMessages('received');
Statistics::printStats(get_lang('MessagesReceived'), $messages_received);
break;
case 'friends':
// total amount of friends
$friends = Statistics::get_friends();
Statistics::print_stats(get_lang('CountFriends'), $friends);
$friends = Statistics::getFriends();
Statistics::printStats(get_lang('CountFriends'), $friends);
break;
}

@ -156,14 +156,14 @@ function check_system_version()
if (ini_get('allow_url_fopen') == 1) {
// The number of courses
$number_of_courses = Statistics::count_courses();
$number_of_courses = Statistics::countCourses();
// The number of users
$number_of_users = Statistics::count_users();
$number_of_active_users = Statistics::count_users(null, null, null, true);
$number_of_users = Statistics::countUsers();
$number_of_active_users = Statistics::countUsers(null, null, null, true);
// The number of sessions
$number_of_sessions = Statistics::count_sessions();
$number_of_sessions = Statistics::countSessions();
$data = array(
'url' => api_get_path(WEB_PATH),

@ -12,34 +12,41 @@ class Statistics
* @param int $size
* @return string Formatted file size
*/
static function make_size_string($size)
public static function makeSizeString($size)
{
if ($size < pow(2,10)) return $size." bytes";
if ($size >= pow(2,10) && $size < pow(2,20)) return round($size / pow(2,10), 0)." KB";
if ($size >= pow(2,20) && $size < pow(2,30)) return round($size / pow(2,20), 1)." MB";
if ($size > pow(2,30)) return round($size / pow(2,30), 2)." GB";
if ($size < pow(2, 10)) {
return $size." bytes";
}
if ($size >= pow(2, 10) && $size < pow(2, 20)) {
return round($size / pow(2, 10), 0)." KB";
}
if ($size >= pow(2, 20) && $size < pow(2, 30)) {
return round($size / pow(2, 20), 1)." MB";
}
if ($size > pow(2, 30)) {
return round($size / pow(2, 30), 2)." GB";
}
}
/**
* Count courses
* @param string $category_code 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
*/
static function count_courses($category_code = NULL)
public static function countCourses($categoryCode = null)
{
$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
$access_url_rel_course_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$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 WHERE u.course_code=c.code AND access_url_id='".$current_url_id."'";
if (isset ($category_code)) {
$sql .= " AND category_code = '".Database::escape_string($category_code)."'";
if (isset ($categoryCode)) {
$sql .= " AND category_code = '".Database::escape_string($categoryCode)."'";
}
} else {
$sql = "SELECT COUNT(*) AS number FROM ".$course_table." ";
if (isset ($category_code)) {
$sql .= " WHERE category_code = '".Database::escape_string($category_code)."'";
if (isset ($categoryCode)) {
$sql .= " WHERE category_code = '".Database::escape_string($categoryCode)."'";
}
}
$res = Database::query($sql);
@ -49,13 +56,12 @@ class Statistics
/**
* Count courses by visibility
* @param int Visibility (0 = closed, 1 = private, 2 = open, 3 = public)
* all courses.
* @param int $visibility Visibility (0 = closed, 1 = private, 2 = open, 3 = public) all courses.
* @return int Number of courses counted
*/
static function count_courses_by_visibility($vis = null)
public static function countCoursesByVisibility($visibility = null)
{
if (!isset($vis)) {
if (!isset($visibility)) {
return 0;
}
$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
@ -64,13 +70,13 @@ class Statistics
if (api_is_multiple_url_enabled()) {
$sql = "SELECT COUNT(*) AS number FROM ".$course_table." as c, ".$access_url_rel_course_table." as u
WHERE u.course_code=c.code AND access_url_id='".$current_url_id."'";
if (isset ($vis)) {
$sql .= " AND visibility = ".intval($vis);
if (isset ($visibility)) {
$sql .= " AND visibility = ".intval($visibility);
}
} else {
$sql = "SELECT COUNT(*) AS number FROM ".$course_table." ";
if (isset ($vis)) {
$sql .= " WHERE visibility = ".intval($vis);
if (isset ($visibility)) {
$sql .= " WHERE visibility = ".intval($visibility);
}
}
$res = Database::query($sql);
@ -80,13 +86,13 @@ class Statistics
/**
* Count users
* @param int optional, user status (COURSEMANAGER or STUDENT), if it's not setted it'll count all users.
* @param string optional, code of a course category. Default: count only users without filtering category
* @param bool count invisible courses (todo)
* @param bool count only active users (false to only return currently active users)
* @param int $status Optional user status (COURSEMANAGER or STUDENT), if it's not setted it'll count all users.
* @param string $categoryCode Optional, code of a course category. Default: count only users without filtering category
* @param bool $countInvisibleCourses Count invisible courses (todo)
* @param bool $onlyActive Count only active users (false to only return currently active users)
* @return int Number of users counted
*/
static function count_users($status = null, $category_code = null, $count_invisible_courses = true, $only_active = false)
public static function countUsers($status = null, $categoryCode = null, $countInvisibleCourses = true, $onlyActive = false)
{
// Database table definitions
$course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
@ -94,19 +100,28 @@ class Statistics
$user_table = Database :: get_main_table(TABLE_MAIN_USER);
$access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$current_url_id = api_get_current_access_url_id();
$active_filter = $only_active?' AND active=1':'';
$active_filter = $onlyActive?' AND active=1':'';
$status_filter = isset($status)?' AND status = '.intval($status):'';
if (api_is_multiple_url_enabled()) {
$sql = "SELECT COUNT(DISTINCT(u.user_id)) AS number FROM $user_table as u, $access_url_rel_user_table as url WHERE u.user_id=url.user_id AND access_url_id='".$current_url_id."' $status_filter $active_filter";
if (isset ($category_code)) {
$sql = "SELECT COUNT(DISTINCT(cu.user_id)) AS number FROM $course_user_table cu, $course_table c, $access_url_rel_user_table as url WHERE c.code = cu.course_code AND c.category_code = '".Database::escape_string($category_code)."' AND cu.user_id=url.user_id AND access_url_id='".$current_url_id."' $status_filter $active_filter";
$sql = "SELECT COUNT(DISTINCT(u.user_id)) AS number
FROM $user_table as u, $access_url_rel_user_table as url
WHERE u.user_id=url.user_id
AND access_url_id='".$current_url_id."'
$status_filter $active_filter";
if (isset ($categoryCode)) {
$sql = "SELECT COUNT(DISTINCT(cu.user_id)) AS number
FROM $course_user_table cu, $course_table c, $access_url_rel_user_table as url
WHERE c.code = cu.course_code
AND c.category_code = '".Database::escape_string($categoryCode)."'
AND cu.user_id=url.user_id AND access_url_id='".$current_url_id."'
$status_filter $active_filter";
}
} else {
$sql = "SELECT COUNT(DISTINCT(user_id)) AS number FROM $user_table WHERE 1=1 $status_filter $active_filter";
if (isset ($category_code)) {
if (isset ($categoryCode)) {
$status_filter = isset($status)?' AND status = '.intval($status):'';
$sql = "SELECT COUNT(DISTINCT(cu.user_id)) AS number FROM $course_user_table cu, $course_table c WHERE c.code = cu.course_code AND c.category_code = '".Database::escape_string($category_code)."' $status_filter $active_filter";
$sql = "SELECT COUNT(DISTINCT(cu.user_id)) AS number FROM $course_user_table cu, $course_table c WHERE c.code = cu.course_code AND c.category_code = '".Database::escape_string($categoryCode)."' $status_filter $active_filter";
}
}
@ -119,7 +134,7 @@ class Statistics
* Count sessions
* @return int Number of sessions counted
*/
static function count_sessions()
public static function countSessions()
{
$session_table = Database :: get_main_table(TABLE_MAIN_SESSION);
$access_url_rel_session_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
@ -138,7 +153,7 @@ class Statistics
* Count activities from track_e_default_table
* @return int Number of activities counted
*/
static function get_number_of_activities()
public static function getNumberOfActivities()
{
// Database table definitions
$track_e_default = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
@ -164,12 +179,12 @@ class Statistics
/**
* Get activities data to display
* @param int $from
* @param int $number_of_items
* @param int $numberOfItems
* @param int $column
* @param string $direction
* @return array
*/
static function get_activities_data($from, $number_of_items, $column, $direction)
public static function getActivitiesData($from, $numberOfItems, $column, $direction)
{
global $dateTimeFormatLong;
$track_e_default = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
@ -179,7 +194,7 @@ class Statistics
$column = intval($column);
$from = intval($from);
$number_of_items = intval($number_of_items);
$numberOfItems = intval($numberOfItems);
if (!in_array($direction, array('ASC','DESC'))) {
$direction = 'DESC';
@ -222,7 +237,7 @@ class Statistics
} else {
$sql .= " ORDER BY col5 DESC ";
}
$sql .= " LIMIT $from,$number_of_items ";
$sql .= " LIMIT $from,$numberOfItems ";
$res = Database::query($sql);
$activities = array ();
@ -251,7 +266,8 @@ class Statistics
// User id.
$row[3] = Display::url(
$row[3],
api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.$row[4], array('title' => get_lang('UserInfo'))
api_get_path(WEB_CODE_PATH).'admin/user_information.php?user_id='.$row[4],
array('title' => get_lang('UserInfo'))
);
$row[4] = TrackingUserLog::get_ip_from_user_event($row[4], $row[5], true);
@ -268,7 +284,7 @@ class Statistics
* Get all course categories
* @return array All course categories (code => name)
*/
static function get_course_categories()
public static function getCourseCategories()
{
$category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
$sql = "SELECT code, name FROM $category_table ORDER BY tree_pos";
@ -286,7 +302,8 @@ class Statistics
* @param int $max The maximum value in the rescaled data (default = 500);
* @return array The rescaled data, same key as $data
*/
static function rescale($data, $max = 500) {
public static function rescale($data, $max = 500)
{
$data_max = 1;
foreach ($data as $index => $value) {
$data_max = ($data_max < $value ? $value : $data_max);
@ -304,25 +321,26 @@ class Statistics
* Show statistics
* @param string $title The title
* @param array $stats
* @param bool $show_total
* @param bool $is_file_size
* @param bool $showTotal
* @param bool $isFileSize
*/
static function print_stats($title, $stats, $show_total = true, $is_file_size = false) {
public static function printStats($title, $stats, $showTotal = true, $isFileSize = false)
{
$total = 0;
$data = Statistics::rescale($stats);
echo '<table class="data_table" cellspacing="0" cellpadding="3">
<tr><th colspan="'.($show_total ? '4' : '3').'">'.$title.'</th></tr>';
<tr><th colspan="'.($showTotal ? '4' : '3').'">'.$title.'</th></tr>';
$i = 0;
foreach ($stats as $subtitle => $number) {
$total += $number;
}
foreach ($stats as $subtitle => $number) {
if (!$is_file_size) {
if (!$isFileSize) {
$number_label = number_format($number, 0, ',', '.');
} else {
$number_label = Statistics::make_size_string($number);
$number_label = Statistics::makeSizeString($number);
}
$percentage = ($total>0?number_format(100*$number/$total, 1, ',', '.'):'0');
@ -330,17 +348,17 @@ class Statistics
<td width="150">'.$subtitle.'</td>
<td width="550">'.Display::bar_progress($percentage, false).'</td>
<td align="right">'.$number_label.'</td>';
if ($show_total) {
if ($showTotal) {
echo '<td align="right"> '.$percentage.'%</td>';
}
echo '</tr>';
$i ++;
}
if ($show_total) {
if (!$is_file_size) {
if ($showTotal) {
if (!$isFileSize) {
$total_label = number_format($total, 0, ',', '.');
} else {
$total_label = Statistics::make_size_string($total);
$total_label = Statistics::makeSizeString($total);
}
echo '<tr><th colspan="4" align="right">'.get_lang('Total').': '.$total_label.'</td></tr>';
}
@ -351,7 +369,7 @@ class Statistics
* Show some stats about the number of logins
* @param string $type month, hour or day
*/
static function print_login_stats($type)
public static function printLoginStats($type)
{
$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);
@ -401,7 +419,7 @@ class Statistics
}
$result_last_x[$stat_date] = $obj->number_of_logins;
}
Statistics::print_stats(get_lang('LastLogins').' ('.$period.')', $result_last_x, true);
Statistics::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 />';
$res = Database::query($sql);
@ -420,15 +438,15 @@ class Statistics
}
$result[$stat_date] = $obj->number_of_logins;
}
Statistics::print_stats(get_lang('AllLogins').' ('.$period.')', $result, true);
Statistics::printStats(get_lang('AllLogins').' ('.$period.')', $result, true);
}
/**
* Print the number of recent logins
*/
static function print_recent_login_stats()
public static function printRecentLoginStats()
{
$total_logins = array();
$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();
@ -439,21 +457,21 @@ class Statistics
$table_url = '';
$where_url='';
}
$sql[get_lang('Thisday')] = "SELECT count(login_user_id) AS number FROM $table $table_url WHERE DATE_ADD(login_date, INTERVAL 1 DAY) >= NOW() $where_url";
$sql[get_lang('ThisDay')] = "SELECT count(login_user_id) AS number FROM $table $table_url WHERE DATE_ADD(login_date, INTERVAL 1 DAY) >= NOW() $where_url";
$sql[get_lang('Last7days')] = "SELECT count(login_user_id) AS number FROM $table $table_url WHERE DATE_ADD(login_date, INTERVAL 7 DAY) >= NOW() $where_url";
$sql[get_lang('Last31days')] = "SELECT count(login_user_id) AS number FROM $table $table_url WHERE DATE_ADD(login_date, INTERVAL 31 DAY) >= NOW() $where_url";
$sql[get_lang('Total')] = "SELECT count(login_user_id) AS number FROM $table $table_url WHERE 1=1 $where_url";
foreach ($sql as $index => $query) {
$res = Database::query($query);
$obj = Database::fetch_object($res);
$total_logins[$index] = $obj->number;
$totalLogin[$index] = $obj->number;
}
Statistics::print_stats(get_lang('Logins'),$total_logins,false);
Statistics::printStats(get_lang('Logins'), $totalLogin, false);
}
/**
* Show some stats about the accesses to the different course tools
*/
static function print_tool_stats()
public static function printToolStats()
{
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
$access_url_rel_course_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
@ -484,7 +502,7 @@ class Statistics
$sql = "SELECT access_tool, count( access_id ) AS number_of_logins
FROM $table t , $access_url_rel_course_table a
WHERE
access_tool IN ('".implode("','",$tools)."') AND
access_tool IN ('".implode("','", $tools)."') AND
t.c_id = a.c_id AND
access_url_id='".$current_url_id."'
GROUP BY access_tool
@ -492,7 +510,7 @@ class Statistics
} else {
$sql = "SELECT access_tool, count( access_id ) ".
"AS number_of_logins FROM $table ".
"WHERE access_tool IN ('".implode("','",$tools)."') ".
"WHERE access_tool IN ('".implode("','", $tools)."') ".
"GROUP BY access_tool ";
}
$res = Database::query($sql);
@ -500,22 +518,22 @@ class Statistics
while ($obj = Database::fetch_object($res)) {
$result[$tool_names[$obj->access_tool]] = $obj->number_of_logins;
}
Statistics::print_stats(get_lang('PlatformToolAccess'),$result,true);
Statistics::printStats(get_lang('PlatformToolAccess'), $result, true);
}
/**
* Show some stats about the number of courses per language
*/
static function print_course_by_language_stats()
public static function printCourseByLanguageStats()
{
$table = Database :: get_main_table(TABLE_MAIN_COURSE);
$access_url_rel_course_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$current_url_id = api_get_current_access_url_id();
if (api_is_multiple_url_enabled()) {
$sql = "SELECT course_language, count( c.code ) AS number_of_courses ".
"FROM $table as c, $access_url_rel_course_table as u
WHERE u.course_code=c.code AND access_url_id='".$current_url_id."'
GROUP BY course_language ORDER BY number_of_courses DESC";
"FROM $table as c, $access_url_rel_course_table as u
WHERE u.course_code=c.code AND access_url_id='".$current_url_id."'
GROUP BY course_language ORDER BY number_of_courses DESC";
} else {
$sql = "SELECT course_language, count( code ) AS number_of_courses ".
"FROM $table GROUP BY course_language ORDER BY number_of_courses DESC";
@ -525,13 +543,13 @@ class Statistics
while ($obj = Database::fetch_object($res)) {
$result[$obj->course_language] = $obj->number_of_courses;
}
Statistics::print_stats(get_lang('CountCourseByLanguage'),$result,true);
Statistics::printStats(get_lang('CountCourseByLanguage'), $result, true);
}
/**
* Shows the number of users having their picture uploaded in Dokeos.
*/
static function print_user_pictures_stats()
public static function printUserPicturesStats()
{
$user_table = Database :: get_main_table(TABLE_MAIN_USER);
$access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
@ -554,29 +572,43 @@ class Statistics
// #users without picture
$result[get_lang('No')] = $count1->n - $count2->n;
$result[get_lang('Yes')] = $count2->n; // #users with picture
Statistics::print_stats(get_lang('CountUsers').' ('.get_lang('UserPicture').')',$result,true);
Statistics::printStats(get_lang('CountUsers').' ('.get_lang('UserPicture').')', $result, true);
}
/**
* Important activities
*/
static function print_activities_stats()
public static function printActivitiesStats()
{
echo '<h4>'.get_lang('ImportantActivities').'</h4>';
// Create a search-box
$form = new FormValidator('search_simple','get',api_get_path(WEB_CODE_PATH).'admin/statistics/index.php','','width=200px',false);
$form = new FormValidator(
'search_simple',
'get',
api_get_path(WEB_CODE_PATH).'admin/statistics/index.php',
'',
'width=200px',
false
);
$renderer =& $form->defaultRenderer();
$renderer->setCustomElementTemplate('<span>{element}</span> ');
$form->addElement('hidden','report','activities');
$form->addElement('hidden','activities_direction','DESC');
$form->addElement('hidden','activities_column','4');
$form->addElement('text','keyword',get_lang('keyword'));
$form->addElement('style_submit_button', 'submit', get_lang('Search'),'class="search"');
$form->addElement('hidden', 'report', 'activities');
$form->addElement('hidden', 'activities_direction', 'DESC');
$form->addElement('hidden', 'activities_column', '4');
$form->addElement('text', 'keyword', get_lang('keyword'));
$form->addElement('style_submit_button', 'submit', get_lang('Search'), 'class="search"');
echo '<div class="actions">';
$form->display();
echo '</div>';
$table = new SortableTable('activities', array('Statistics','get_number_of_activities'), array('Statistics','get_activities_data'),5,50,'DESC');
$table = new SortableTable(
'activities',
array('Statistics', 'get_number_of_activities'),
array('Statistics','get_activities_data'),
5,
50,
'DESC'
);
$parameters = array();
$parameters['report'] = 'activities';
@ -597,7 +629,7 @@ class Statistics
/**
* Shows statistics about the time of last visit to each course.
*/
static function print_course_last_visit()
public static function printCourseLastVisit()
{
$access_url_rel_course_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$current_url_id = api_get_current_access_url_id();
@ -613,14 +645,14 @@ class Statistics
$direction = isset($_GET['direction']) ? $_GET['direction'] : SORT_ASC;
if (!in_array($direction,array(SORT_ASC,SORT_DESC))) {
if (!in_array($direction, array(SORT_ASC, SORT_DESC))) {
$direction = SORT_ASC;
}
$form = new FormValidator('courselastvisit', 'get');
$form->addElement('hidden','report','courselastvisit');
$form->addText('date_diff',get_lang('Days'),true);
$form->addRule('date_diff','InvalidNumber','numeric');
$form->addElement('style_submit_button', 'submit', get_lang('Search'),'class="search"');
$form->addElement('hidden', 'report', 'courselastvisit');
$form->addText('date_diff', get_lang('Days'), true);
$form->addRule('date_diff', 'InvalidNumber', 'numeric');
$form->addElement('style_submit_button', 'submit', get_lang('Search'), 'class="search"');
if (!isset($_GET['date_diff'])) {
$defaults['date_diff'] = 60;
} else {
@ -676,15 +708,15 @@ class Statistics
* @param string Type of message: 'sent' or 'received'
* @return array Message list
*/
static function get_messages($message_type)
public static function getMessages($messageType)
{
$message_table = Database::get_main_table(TABLE_MAIN_MESSAGE);
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$access_url_rel_user_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$message_table = Database::get_main_table(TABLE_MAIN_MESSAGE);
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$access_url_rel_user_table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$current_url_id = api_get_current_access_url_id();
$current_url_id = api_get_current_access_url_id();
switch ($message_type) {
switch ($messageType) {
case 'sent':
$field = 'user_sender_id';
break;
@ -719,7 +751,7 @@ class Statistics
/**
* Count the number of friends for social network users
*/
static function get_friends()
public static function getFriends()
{
$user_friend_table = Database::get_main_table(TABLE_MAIN_USER_REL_USER);
$user_table = Database::get_main_table(TABLE_MAIN_USER);
@ -751,13 +783,13 @@ class Statistics
/**
* Print the number of users that didn't login for a certain period of time
*/
static function print_users_not_logged_in_stats()
public static function printUsersNotLoggedInStats()
{
$total_logins = array();
$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();
$total = self::count_users();
$total = self::countUsers();
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='".$current_url_id."'";
@ -765,7 +797,7 @@ class Statistics
$table_url = '';
$where_url='';
}
$sql[get_lang('Thisday')] =
$sql[get_lang('ThisDay')] =
"SELECT count(distinct(login_user_id)) AS number ".
" FROM $table $table_url ".
" WHERE DATE_ADD(login_date, INTERVAL 1 DAY) >= NOW() $where_url";
@ -777,7 +809,7 @@ class Statistics
"SELECT count(distinct(login_user_id)) AS number ".
" FROM $table $table_url ".
" WHERE DATE_ADD(login_date, INTERVAL 31 DAY) >= NOW() $where_url";
$sql[sprintf(get_lang('LastXMonths'),6)] =
$sql[sprintf(get_lang('LastXMonths'), 6)] =
"SELECT count(distinct(login_user_id)) AS number ".
" FROM $table $table_url ".
" WHERE DATE_ADD(login_date, INTERVAL 6 MONTH) >= NOW() $where_url";
@ -788,8 +820,12 @@ class Statistics
$res = Database::query($query);
$obj = Database::fetch_object($res);
$r = $total - $obj->number;
$total_logins[$index] = $r < 0 ? 0 : $r;
$totalLogin[$index] = $r < 0 ? 0 : $r;
}
Statistics::print_stats(get_lang('StatsUsersDidNotLoginInLastPeriods'),$total_logins,false);
Statistics::printStats(
get_lang('StatsUsersDidNotLoginInLastPeriods'),
$totalLogin,
false
);
}
}

@ -219,7 +219,7 @@ if ($is_allowedToTrack) {
AND ( access_date > CURDATE() )
AND access_tool IS NULL";
$count = StatsUtils::getOneResult($sql);
$line .= get_lang('Thisday') . " ; " . $count . "\n";
$line .= get_lang('ThisDay') . " ; " . $count . "\n";
}
/* Tools */

@ -130,16 +130,16 @@ class BlockGlobalInfo extends Block
$path = api_get_path(WEB_CODE_PATH);
// Check total number of users
$global_info = array(
array(get_lang('CountUsers'), '<a href="'.$path.'admin/user_list.php">'.Statistics::count_users().'</a>'),
array(get_lang('CountUsers'), '<a href="'.$path.'admin/user_list.php">'.Statistics::countUsers().'</a>'),
// Check only active users
array(get_lang('NumberOfUsersActive'), '<a href="'.$path.'admin/user_list.php?keyword_firstname=&amp;keyword_lastname=&amp;keyword_username=&amp;keyword_email=&amp;keyword_officialcode=&amp;keyword_status=%25&amp;keyword_active=1&amp;submit=&amp;_qf__advanced_search=">'.Statistics::count_users(null,null,null,true).'</a>'),
array(get_lang('NumberOfUsersActive'), '<a href="'.$path.'admin/user_list.php?keyword_firstname=&amp;keyword_lastname=&amp;keyword_username=&amp;keyword_email=&amp;keyword_officialcode=&amp;keyword_status=%25&amp;keyword_active=1&amp;submit=&amp;_qf__advanced_search=">'.Statistics::countUsers(null, null, null, true).'</a>'),
// Check number of courses
array(get_lang('NumberOfCoursesTotal'), '<a href="'.$path.'admin/course_list.php">'.Statistics::count_courses().'</a>'),
array(get_lang('NumberOfCoursesPublic'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_OPEN_WORLD.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::count_courses_by_visibility(COURSE_VISIBILITY_OPEN_WORLD).'</a>'),
array(get_lang('NumberOfCoursesOpen'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_OPEN_PLATFORM.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::count_courses_by_visibility(COURSE_VISIBILITY_OPEN_PLATFORM).'</a>'),
array(get_lang('NumberOfCoursesPrivate'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_REGISTERED.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::count_courses_by_visibility(COURSE_VISIBILITY_REGISTERED).'</a>'),
array(get_lang('NumberOfCoursesClosed'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_CLOSED.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::count_courses_by_visibility(COURSE_VISIBILITY_CLOSED).'</a>'),
array(get_lang('NumberOfCoursesHidden'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_HIDDEN.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::count_courses_by_visibility(COURSE_VISIBILITY_HIDDEN).'</a>')
array(get_lang('NumberOfCoursesTotal'), '<a href="'.$path.'admin/course_list.php">'.Statistics::countCourses().'</a>'),
array(get_lang('NumberOfCoursesPublic'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_OPEN_WORLD.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::countCoursesByVisibility(COURSE_VISIBILITY_OPEN_WORLD).'</a>'),
array(get_lang('NumberOfCoursesOpen'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_OPEN_PLATFORM.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::countCoursesByVisibility(COURSE_VISIBILITY_OPEN_PLATFORM).'</a>'),
array(get_lang('NumberOfCoursesPrivate'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_REGISTERED.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::countCoursesByVisibility(COURSE_VISIBILITY_REGISTERED).'</a>'),
array(get_lang('NumberOfCoursesClosed'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_CLOSED.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::countCoursesByVisibility(COURSE_VISIBILITY_CLOSED).'</a>'),
array(get_lang('NumberOfCoursesHidden'), '<a href="'.$path.'admin/course_list.php?keyword_code=&amp;keyword_title=&amp;keyword_language=%25&amp;keyword_category=&amp;keyword_visibility='.COURSE_VISIBILITY_HIDDEN.'&amp;keyword_subscribe=%25&amp;keyword_unsubscribe=%25&amp;submit=&amp;_qf__advanced_course_search=">'.Statistics::countCoursesByVisibility(COURSE_VISIBILITY_HIDDEN).'</a>')
);
return $global_info;
}

@ -1,155 +1,188 @@
<?php
class TestStatistics extends UnitTestCase{
public function TestStatistics(){
$this->UnitTestCase('this File test the provides some function for statistics ');
}
public function setUp(){
$this-> statisc = new Statistics();
}
public function tearDown(){
$this->statisc = null;
}
public function testMakeSizeString(){
$size=20960000;
$res = Statistics::make_size_string($size);
$this->assertTrue(is_string($res));
//var_dump($res);
}
/**
* Count courses
* @param string $category_code Code of a course category. Default: count
* all courses.
* @return int Number of courses counted
*/
public function testCountCourses(){
$res = Statistics::count_courses();
$this->assertTrue(is_numeric($res));
//var_dump($res);
}
public function testCountUsers(){
$user_id ='1';
$category_code = NULL;
$course_code='ABC';
$firstName='Jhon'; $lastName='Doe'; $status='1'; $email='localhost@localhost.com'; $loginName='admin'; $password='admin';
$count_invisible_courses = true;
$res = Statistics::count_users($status, $category_code, $count_invisible_courses);
$this->assertTrue(is_numeric($res));
$this->assertTrue(count($res)===0 || count($res)!==0);
}
public function testGetNumberOfActivities() {
$resu = Statistics::get_number_of_activities();
if(!is_null($resu)){
$this->assertTrue(is_numeric($resu));
$this->assertTrue(count($resu)==0 || count($resu)!==0);
}
}
/**
* Get activities data to display
*/
public function testGetActivitiesData(){
global $dateTimeFormatLong;
$from = 0;
$number_of_items = 30;
$column = '';
$direction = 'ASC';
$resu = Statistics::get_activities_data($from, $number_of_items, $column, $direction);
$this->assertTrue(is_array($resu));
}
/**
* Get all course categories
* @return array All course categories (code => name)
*/
public function testGetCourseCategories(){
$res = Statistics::get_course_categories();
$this->assertTrue($res);
//var_dump($res);
}
public function testRescale(){
$data=array('test','test2','test3');
$max = 500;
$res = Statistics::rescale($data, $max);
$this->assertTrue($res);
$this->assertTrue(is_array($res));
//var_dump($res);
}
public function testPrintStats(){
ob_start();
$title='testing';
$stats=array('test','test2','test3');
$show_total = true;
$is_file_size = false;
$res = Statistics::print_stats($title, $stats, $show_total = true, $is_file_size = false);
ob_end_clean();
$this->assertTrue(is_null($res));
//var_dump($res);
}
public function testPrintLoginStats(){
ob_start();
$type='month';
$resu = Statistics::print_login_stats($type);
ob_end_clean();
class TestStatistics extends UnitTestCase
{
public function TestStatistics()
{
$this->UnitTestCase('this File test the provides some function for statistics ');
}
public function setUp()
{
$this->statisc = new Statistics();
}
public function tearDown()
{
$this->statisc = null;
}
public function testMakeSizeString()
{
$size = 20960000;
$res = Statistics::makeSizeString($size);
$this->assertTrue(is_string($res));
//var_dump($res);
}
/**
* Count courses
* @param string $category_code Code of a course category. Default: count
* all courses.
* @return int Number of courses counted
*/
public function testCountCourses()
{
$res = Statistics::countCourses();
$this->assertTrue(is_numeric($res));
//var_dump($res);
}
public function testCountUsers()
{
$user_id = '1';
$category_code = null;
$course_code = 'ABC';
$firstName = 'Jhon';
$lastName = 'Doe';
$status = '1';
$email = 'localhost@localhost.com';
$loginName = 'admin';
$password = 'admin';
$count_invisible_courses = true;
$res = Statistics::countUsers($status, $category_code,
$count_invisible_courses);
$this->assertTrue(is_numeric($res));
$this->assertTrue(count($res) === 0 || count($res) !== 0);
}
public function testGetNumberOfActivities()
{
$resu = Statistics::getNumberOfActivities();
if (!is_null($resu)) {
$this->assertTrue(is_numeric($resu));
$this->assertTrue(count($resu) == 0 || count($resu) !== 0);
}
}
/**
* Get activities data to display
*/
public function testGetActivitiesData()
{
global $dateTimeFormatLong;
$from = 0;
$number_of_items = 30;
$column = '';
$direction = 'ASC';
$resu = Statistics::getActivitiesData($from, $number_of_items, $column,
$direction);
$this->assertTrue(is_array($resu));
}
/**
* Get all course categories
* @return array All course categories (code => name)
*/
public function testGetCourseCategories()
{
$res = Statistics::getCourseCategories();
$this->assertTrue($res);
//var_dump($res);
}
public function testRescale()
{
$data = array('test', 'test2', 'test3');
$max = 500;
$res = Statistics::rescale($data, $max);
$this->assertTrue($res);
$this->assertTrue(is_array($res));
//var_dump($res);
}
public function testPrintStats()
{
ob_start();
$title = 'testing';
$stats = array('test', 'test2', 'test3');
$show_total = true;
$is_file_size = false;
$res = Statistics::printStats(
$title,
$stats,
$show_total = true,
$is_file_size = false
);
ob_end_clean();
$this->assertTrue(is_null($res));
//var_dump($res);
}
public function testPrintLoginStats()
{
ob_start();
$type = 'month';
$resu = Statistics::printLoginStats($type);
ob_end_clean();
$this->assertTrue(is_null($resu));
//var_dump($resu);
}
//var_dump($resu);
}
public function testPrintRecenLoginStats(){
ob_start();
$res = Statistics::print_recent_login_stats();
ob_end_clean();
$this->assertTrue(is_null($res));
//var_dump($res);
public function testPrintRecentLoginStats()
{
ob_start();
$res = Statistics::printRecentLoginStats();
ob_end_clean();
$this->assertTrue(is_null($res));
//var_dump($res);
}
public function testPrintToolStats(){
ob_start();
$resu = Statistics::print_tool_stats();
ob_end_clean();
$this->assertTrue(is_null($resu));
public function testPrintToolStats()
{
ob_start();
$resu = Statistics::printToolStats();
ob_end_clean();
$this->assertTrue(is_null($resu));
}
public function testPrintCourseByLanguageStats(){
ob_start();
$resu = Statistics::print_course_by_language_stats();
ob_end_clean();
$this->assertTrue(is_null($resu));
//var_dump($resu);
public function testPrintCourseByLanguageStats()
{
ob_start();
$resu = Statistics::printCourseByLanguageStats();
ob_end_clean();
$this->assertTrue(is_null($resu));
//var_dump($resu);
}
public function testPrintUserPicturesStats(){
ob_start();
$resu = Statistics::print_user_pictures_stats();
ob_end_clean();
$this->assertTrue(is_null($resu));
public function testPrintUserPicturesStats()
{
ob_start();
$resu = Statistics::printUserPicturesStats();
ob_end_clean();
$this->assertTrue(is_null($resu));
}
public function testPrintActivitiesStats(){
ob_start();
$res = Statistics::print_activities_stats();
ob_end_clean();
$this->assertTrue(is_null($res));
//var_dump($res);
public function testPrintActivitiesStats()
{
ob_start();
$res = Statistics::printActivitiesStats();
ob_end_clean();
$this->assertTrue(is_null($res));
//var_dump($res);
}
public function testPrintCourseLastVisit(){
ob_start();
$column='';
$direction='';
$parameters['action'] = 'courselastvisit';
$res = Statistics::print_course_last_visit();
ob_end_clean();
$this->assertTrue(is_null($res));
public function testPrintCourseLastVisit()
{
ob_start();
$column = '';
$direction = '';
$parameters['action'] = 'courselastvisit';
$res = Statistics::printCourseLastVisit();
ob_end_clean();
$this->assertTrue(is_null($res));
}
}
?>

Loading…
Cancel
Save