|
@@ -1,14 +1,11 @@
|
|
|
<?php
|
|
|
/* For licensing terms, see /license.txt */
|
|
|
-require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
|
|
|
+require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
|
|
|
/**
|
|
|
-==============================================================================
|
|
|
* This class provides some functions for statistics
|
|
|
-* @package dokeos.statistics
|
|
|
-==============================================================================
|
|
|
+* @package chamilo.statistics
|
|
|
*/
|
|
|
-class Statistics
|
|
|
-{
|
|
|
+class Statistics {
|
|
|
/**
|
|
|
* Converts a number of bytes in a formatted string
|
|
|
* @param int $size
|
|
@@ -26,8 +23,7 @@ class Statistics
|
|
|
* all courses.
|
|
|
* @return int Number of courses counted
|
|
|
*/
|
|
|
- function count_courses($category_code = NULL)
|
|
|
- {
|
|
|
+ function count_courses($category_code = NULL) {
|
|
|
$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
|
|
|
$sql = "SELECT COUNT(*) AS number FROM ".$course_table." ";
|
|
|
if (isset ($category_code)) {
|
|
@@ -44,8 +40,7 @@ class Statistics
|
|
|
* all users.
|
|
|
* @return int Number of users counted
|
|
|
*/
|
|
|
- function count_users($status, $category_code = NULL, $count_invisible_courses = true)
|
|
|
- {
|
|
|
+ function count_users($status, $category_code = NULL, $count_invisible_courses = true) {
|
|
|
// Database table definitions
|
|
|
$course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
|
|
|
$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
|
|
@@ -64,8 +59,7 @@ class Statistics
|
|
|
* Count activities from track_e_default_table
|
|
|
* @return int Number of activities counted
|
|
|
*/
|
|
|
- function get_number_of_activities()
|
|
|
- {
|
|
|
+ function get_number_of_activities() {
|
|
|
// Database table definitions
|
|
|
$track_e_default = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
|
|
|
$table_user = Database::get_main_table(TABLE_MAIN_USER);
|
|
@@ -83,8 +77,7 @@ class Statistics
|
|
|
/**
|
|
|
* Get activities data to display
|
|
|
*/
|
|
|
- function get_activities_data($from, $number_of_items, $column, $direction)
|
|
|
- {
|
|
|
+ function get_activities_data($from, $number_of_items, $column, $direction) {
|
|
|
global $dateTimeFormatLong;
|
|
|
$track_e_default = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_DEFAULT);
|
|
|
$table_user = Database::get_main_table(TABLE_MAIN_USER);
|
|
@@ -94,8 +87,8 @@ class Statistics
|
|
|
$from = intval($from);
|
|
|
$number_of_items = intval($number_of_items);
|
|
|
|
|
|
- if(!in_array($direction, array('ASC','DESC'))){
|
|
|
- $direction = 'DESC';
|
|
|
+ if (!in_array($direction, array('ASC','DESC'))) {
|
|
|
+ $direction = 'DESC';
|
|
|
}
|
|
|
|
|
|
$sql = "SELECT
|
|
@@ -108,8 +101,8 @@ class Statistics
|
|
|
WHERE track_default.default_user_id = user.user_id ";
|
|
|
|
|
|
if (isset($_GET['keyword'])) {
|
|
|
- $keyword = Database::escape_string(trim($_GET['keyword']));
|
|
|
- $sql .= " AND (user.username LIKE '%".$keyword."%' OR default_event_type LIKE '%".$keyword."%' OR default_value_type LIKE '%".$keyword."%' OR default_value LIKE '%".$keyword."%') ";
|
|
|
+ $keyword = Database::escape_string(trim($_GET['keyword']));
|
|
|
+ $sql .= " AND (user.username LIKE '%".$keyword."%' OR default_event_type LIKE '%".$keyword."%' OR default_value_type LIKE '%".$keyword."%' OR default_value LIKE '%".$keyword."%') ";
|
|
|
}
|
|
|
|
|
|
if (!empty($column) && !empty($direction)) {
|
|
@@ -132,14 +125,12 @@ class Statistics
|
|
|
* Get all course categories
|
|
|
* @return array All course categories (code => name)
|
|
|
*/
|
|
|
- function get_course_categories()
|
|
|
- {
|
|
|
+ function get_course_categories() {
|
|
|
$category_table = Database :: get_main_table(TABLE_MAIN_CATEGORY);
|
|
|
$sql = "SELECT code, name FROM $category_table ORDER BY tree_pos";
|
|
|
$res = Database::query($sql);
|
|
|
$categories = array ();
|
|
|
- while ($category = Database::fetch_object($res))
|
|
|
- {
|
|
|
+ while ($category = Database::fetch_object($res)) {
|
|
|
$categories[$category->code] = $category->name;
|
|
|
}
|
|
|
return $categories;
|
|
@@ -150,18 +141,15 @@ class Statistics
|
|
|
* @param int $max The maximum value in the rescaled data (default = 500);
|
|
|
* @return array The rescaled data, same key as $data
|
|
|
*/
|
|
|
- function rescale($data, $max = 500)
|
|
|
- {
|
|
|
+ function rescale($data, $max = 500) {
|
|
|
$data_max = 1;
|
|
|
- foreach ($data as $index => $value)
|
|
|
- {
|
|
|
+ foreach ($data as $index => $value) {
|
|
|
$data_max = ($data_max < $value ? $value : $data_max);
|
|
|
}
|
|
|
reset($data);
|
|
|
$result = array ();
|
|
|
$delta = $max / $data_max;
|
|
|
- foreach ($data as $index => $value)
|
|
|
- {
|
|
|
+ foreach ($data as $index => $value) {
|
|
|
$result[$index] = (int) round($value * $delta);
|
|
|
}
|
|
|
return $result;
|
|
@@ -173,30 +161,23 @@ class Statistics
|
|
|
* @param bool $show_total
|
|
|
* @param bool $is_file_size
|
|
|
*/
|
|
|
- function print_stats($title, $stats, $show_total = true, $is_file_size = false)
|
|
|
- {
|
|
|
+ function print_stats($title, $stats, $show_total = true, $is_file_size = 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>';
|
|
|
$i = 0;
|
|
|
- foreach($stats as $subtitle => $number)
|
|
|
- {
|
|
|
+ foreach ($stats as $subtitle => $number) {
|
|
|
$total += $number;
|
|
|
}
|
|
|
- foreach ($stats as $subtitle => $number)
|
|
|
- {
|
|
|
- $i = $i % 13;
|
|
|
- if (api_strlen($subtitle) > 30)
|
|
|
- {
|
|
|
+ foreach ($stats as $subtitle => $number) {
|
|
|
+ //$i = $i % 13;
|
|
|
+ if (api_strlen($subtitle) > 30) {
|
|
|
$subtitle = '<acronym title="'.$subtitle.'">'.api_substr($subtitle, 0, 27).'...</acronym>';
|
|
|
}
|
|
|
- if(!$is_file_size)
|
|
|
- {
|
|
|
+ if (!$is_file_size) {
|
|
|
$number_label = number_format($number, 0, ',', '.');
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
$number_label = Statistics::make_size_string($number);
|
|
|
}
|
|
|
echo '<tr class="row_'.($i%2 == 0 ? 'odd' : 'even').'">
|
|
@@ -205,21 +186,16 @@ class Statistics
|
|
|
'.Display::return_icon('bar_1u.gif', get_lang('Statistics') ,array('width' => $data[$subtitle], 'height' => '10')).'
|
|
|
</td>
|
|
|
<td align="right">'.$number_label.'</td>';
|
|
|
- if($show_total)
|
|
|
- {
|
|
|
+ if ($show_total) {
|
|
|
echo '<td align="right"> '.($total>0?number_format(100*$number/$total, 1, ',', '.'):'0').'%</td>';
|
|
|
}
|
|
|
echo '</tr>';
|
|
|
$i ++;
|
|
|
}
|
|
|
- if ($show_total)
|
|
|
- {
|
|
|
- if(!$is_file_size)
|
|
|
- {
|
|
|
+ if ($show_total) {
|
|
|
+ if (!$is_file_size) {
|
|
|
$total_label = number_format($total, 0, ',', '.');
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
$total_label = Statistics::make_size_string($total);
|
|
|
}
|
|
|
echo '<tr><th colspan="4" align="right">'.get_lang('Total').': '.$total_label.'</td></tr>';
|
|
@@ -230,11 +206,9 @@ class Statistics
|
|
|
* Show some stats about the number of logins
|
|
|
* @param string $type month, hour or day
|
|
|
*/
|
|
|
- function print_login_stats($type)
|
|
|
- {
|
|
|
+ function print_login_stats($type) {
|
|
|
$table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
|
|
|
- switch($type)
|
|
|
- {
|
|
|
+ switch ($type) {
|
|
|
case 'month':
|
|
|
$months = api_get_months_long();
|
|
|
$period = get_lang('PeriodMonth');
|
|
@@ -252,11 +226,9 @@ class Statistics
|
|
|
}
|
|
|
$res = Database::query($sql);
|
|
|
$result = array();
|
|
|
- while($obj = Database::fetch_object($res))
|
|
|
- {
|
|
|
+ while ($obj = Database::fetch_object($res)) {
|
|
|
$stat_date = $obj->stat_date;
|
|
|
- switch($type)
|
|
|
- {
|
|
|
+ switch ($type) {
|
|
|
case 'month':
|
|
|
$stat_date = explode('-', $stat_date);
|
|
|
$stat_date[1] = $months[$stat_date[1] - 1];
|
|
@@ -273,16 +245,14 @@ class Statistics
|
|
|
/**
|
|
|
* Print the number of recent logins
|
|
|
*/
|
|
|
- function print_recent_login_stats()
|
|
|
- {
|
|
|
+ function print_recent_login_stats() {
|
|
|
$total_logins = array();
|
|
|
$table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
|
|
|
$sql[get_lang('Thisday')] = "SELECT count(login_user_id) AS number FROM $table WHERE DATE_ADD(login_date, INTERVAL 1 DAY) >= NOW()";
|
|
|
$sql[get_lang('Last7days')] = "SELECT count(login_user_id) AS number FROM $table WHERE DATE_ADD(login_date, INTERVAL 7 DAY) >= NOW()";
|
|
|
$sql[get_lang('Last31days')] = "SELECT count(login_user_id) AS number FROM $table WHERE DATE_ADD(login_date, INTERVAL 31 DAY) >= NOW()";
|
|
|
$sql[get_lang('Total')] = "SELECT count(login_user_id) AS number FROM $table";
|
|
|
- foreach($sql as $index => $query)
|
|
|
- {
|
|
|
+ foreach ($sql as $index => $query) {
|
|
|
$res = Database::query($query);
|
|
|
$obj = Database::fetch_object($res);
|
|
|
$total_logins[$index] = $obj->number;
|
|
@@ -292,19 +262,23 @@ class Statistics
|
|
|
/**
|
|
|
* Show some stats about the accesses to the different course tools
|
|
|
*/
|
|
|
- function print_tool_stats()
|
|
|
- {
|
|
|
+ function print_tool_stats() {
|
|
|
$table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
|
|
|
- $tools = array('announcement','assignment','calendar_event','chat','conference','course_description','document','dropbox','group','learnpath','link','quiz','student_publication','user','forum');
|
|
|
+ $tools = array('announcement','assignment','calendar_event',
|
|
|
+ 'chat','conference','course_description','document',
|
|
|
+ 'dropbox','group','learnpath','link','quiz',
|
|
|
+ 'student_publication','user','forum');
|
|
|
$tool_names = array();
|
|
|
foreach ($tools as $tool) {
|
|
|
$tool_names[$tool] = get_lang(ucfirst($tool), '');
|
|
|
}
|
|
|
- $sql = "SELECT access_tool, count( access_id ) AS number_of_logins FROM $table WHERE access_tool IN ('".implode("','",$tools)."') GROUP BY access_tool ";
|
|
|
+ $sql = "SELECT access_tool, count( access_id )
|
|
|
+ AS number_of_logins FROM $table
|
|
|
+ WHERE access_tool IN ('".implode("','",$tools)."')
|
|
|
+ GROUP BY access_tool ";
|
|
|
$res = Database::query($sql);
|
|
|
$result = array();
|
|
|
- while($obj = Database::fetch_object($res))
|
|
|
- {
|
|
|
+ while ($obj = Database::fetch_object($res)) {
|
|
|
$result[$tool_names[$obj->access_tool]] = $obj->number_of_logins;
|
|
|
}
|
|
|
Statistics::print_stats(get_lang('PlatformToolAccess'),$result,true);
|
|
@@ -312,14 +286,14 @@ class Statistics
|
|
|
/**
|
|
|
* Show some stats about the number of courses per language
|
|
|
*/
|
|
|
- function print_course_by_language_stats()
|
|
|
- {
|
|
|
+ function print_course_by_language_stats() {
|
|
|
$table = Database::get_main_table(TABLE_MAIN_COURSE);
|
|
|
- $sql = "SELECT course_language, count( code ) AS number_of_courses FROM $table GROUP BY course_language ";
|
|
|
+ $sql = "SELECT course_language, count( code )
|
|
|
+ AS number_of_courses
|
|
|
+ FROM $table GROUP BY course_language ";
|
|
|
$res = Database::query($sql);
|
|
|
$result = array();
|
|
|
- while($obj = Database::fetch_object($res))
|
|
|
- {
|
|
|
+ while ($obj = Database::fetch_object($res)) {
|
|
|
$result[$obj->course_language] = $obj->number_of_courses;
|
|
|
}
|
|
|
Statistics::print_stats(get_lang('CountCourseByLanguage'),$result,true);
|
|
@@ -327,16 +301,17 @@ class Statistics
|
|
|
/**
|
|
|
* Shows the number of users having their picture uploaded in Dokeos.
|
|
|
*/
|
|
|
- function print_user_pictures_stats()
|
|
|
- {
|
|
|
+ function print_user_pictures_stats() {
|
|
|
$user_table = Database :: get_main_table(TABLE_MAIN_USER);
|
|
|
$sql = "SELECT COUNT(*) AS n FROM $user_table";
|
|
|
$res = Database::query($sql);
|
|
|
$count1 = Database::fetch_object($res);
|
|
|
- $sql = "SELECT COUNT(*) AS n FROM $user_table WHERE LENGTH(picture_uri) > 0";
|
|
|
+ $sql = "SELECT COUNT(*) AS n FROM $user_table
|
|
|
+ WHERE LENGTH(picture_uri) > 0";
|
|
|
$res = Database::query($sql);
|
|
|
$count2 = Database::fetch_object($res);
|
|
|
- $result[get_lang('No')] = $count1->n - $count2->n; // #users without picture
|
|
|
+ // #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);
|
|
|
}
|
|
@@ -374,27 +349,25 @@ class Statistics
|
|
|
$table->set_header(3, get_lang('UserName'));
|
|
|
$table->set_header(4, get_lang('Date'));
|
|
|
$table->display();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Shows statistics about the time of last visit to each course.
|
|
|
*/
|
|
|
- function print_course_last_visit()
|
|
|
- {
|
|
|
+ function print_course_last_visit() {
|
|
|
$columns[0] = 'access_cours_code';
|
|
|
$columns[1] = 'access_date';
|
|
|
$sql_order[SORT_ASC] = 'ASC';
|
|
|
$sql_order[SORT_DESC] = 'DESC';
|
|
|
- $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;
|
|
|
- if(!in_array($_GET['direction'],array(SORT_ASC,SORT_DESC))){
|
|
|
- $direction = SORT_ASC;
|
|
|
- } else {
|
|
|
- $direction = isset($_GET['direction']) ? $_GET['direction'] : SORT_ASC;
|
|
|
- }
|
|
|
+ $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;
|
|
|
+ if (!in_array($_GET['direction'],array(SORT_ASC,SORT_DESC))) {
|
|
|
+ $direction = SORT_ASC;
|
|
|
+ } else {
|
|
|
+ $direction = isset($_GET['direction']) ? $_GET['direction'] : SORT_ASC;
|
|
|
+ }
|
|
|
$form = new FormValidator('courselastvisit','get');
|
|
|
$form->addElement('hidden','action','courselastvisit');
|
|
|
$form->add_textfield('date_diff',get_lang('Days'),true);
|
|
@@ -410,7 +383,10 @@ class Statistics
|
|
|
$values = $form->exportValues();
|
|
|
$date_diff = $values['date_diff'];
|
|
|
$table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
|
|
|
- $sql = "SELECT * FROM $table GROUP BY access_cours_code HAVING access_cours_code <> '' AND DATEDIFF( NOW() , access_date ) <= ". $date_diff;
|
|
|
+ $sql = "SELECT * FROM $table
|
|
|
+ GROUP BY access_cours_code
|
|
|
+ HAVING access_cours_code <> ''
|
|
|
+ AND DATEDIFF( NOW() , access_date ) <= ". $date_diff;
|
|
|
$res = Database::query($sql);
|
|
|
$number_of_courses = Database::num_rows($res);
|
|
|
$sql .= ' ORDER BY '.$columns[$column].' '.$sql_order[$direction];
|
|
@@ -418,11 +394,9 @@ class Statistics
|
|
|
$sql .= ' LIMIT '.$from.','.$per_page;
|
|
|
echo '<p>'.get_lang('LastAccess').' >= '.$date_diff.' '.get_lang('Days').'</p>';
|
|
|
$res = Database::query($sql);
|
|
|
- if (Database::num_rows($res) > 0)
|
|
|
- {
|
|
|
+ if (Database::num_rows($res) > 0) {
|
|
|
$courses = array ();
|
|
|
- while ($obj = Database::fetch_object($res))
|
|
|
- {
|
|
|
+ while ($obj = Database::fetch_object($res)) {
|
|
|
$course = array ();
|
|
|
$course[]= '<a href="'.api_get_path(WEB_PATH).'courses/'.$obj->access_cours_code.'">'.$obj->access_cours_code.' <a>';
|
|
|
$course[] = api_convert_and_format_date($obj->access_date, null, date_default_timezone_get());
|
|
@@ -434,16 +408,14 @@ class Statistics
|
|
|
$table_header[] = array ("Coursecode", true);
|
|
|
$table_header[] = array ("Last login", true);
|
|
|
Display :: display_sortable_table($table_header, $courses, array ('column'=>$column,'direction'=>$direction), array (), $parameters);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
+ } else {
|
|
|
echo get_lang('NoSearchResults');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Displays the statistics of the messages sent and received by each user in the social network
|
|
|
- * @param string Type of message sent or received
|
|
|
+ * @param string Type of message: 'sent' or 'received'
|
|
|
* @return array Message list
|
|
|
*/
|
|
|
function get_messages($message_type) {
|
|
@@ -457,12 +429,17 @@ class Statistics
|
|
|
$field = 'user_receiver_id';
|
|
|
break;
|
|
|
}
|
|
|
- $sql = "SELECT lastname, firstname, username, COUNT($field) AS count_message
|
|
|
- FROM ".$message_table." m LEFT JOIN ".$user_table." u ON m.$field = u.user_id
|
|
|
- GROUP BY m.$field";
|
|
|
+ $sql = "SELECT lastname, firstname, username,
|
|
|
+ COUNT($field) AS count_message
|
|
|
+ FROM ".$message_table." m
|
|
|
+ LEFT JOIN ".$user_table." u ON m.$field = u.user_id
|
|
|
+ GROUP BY m.$field";
|
|
|
$res = Database::query($sql);
|
|
|
$messages_sent = array();
|
|
|
while ($messages = Database::fetch_array($res)) {
|
|
|
+ if (empty($messages['username'])) {
|
|
|
+ $messages['username'] = get_lang('Unknown');
|
|
|
+ }
|
|
|
$users = $messages['firstname'].' '.$messages['lastname'].' ('.$messages['username'].')';
|
|
|
$messages_sent[$users] = $messages['count_message'];
|
|
|
}
|
|
@@ -475,9 +452,12 @@ class Statistics
|
|
|
function get_friends() {
|
|
|
$user_friend_table = Database::get_main_table(TABLE_MAIN_USER_REL_USER);
|
|
|
$user_table = Database::get_main_table(TABLE_MAIN_USER);
|
|
|
- $sql = "SELECT lastname, firstname, username, COUNT(friend_user_id) AS count_friend
|
|
|
- FROM ".$user_friend_table." uf LEFT JOIN ".$user_table." u ON uf.user_id = u.user_id WHERE uf.relation_type <> '".USER_RELATION_TYPE_RRHH."'
|
|
|
- GROUP BY uf.user_id";
|
|
|
+ $sql = "SELECT lastname, firstname, username,
|
|
|
+ COUNT(friend_user_id) AS count_friend
|
|
|
+ FROM ".$user_friend_table." uf
|
|
|
+ LEFT JOIN ".$user_table." u ON uf.user_id = u.user_id
|
|
|
+ WHERE uf.relation_type <> '".USER_RELATION_TYPE_RRHH."'
|
|
|
+ GROUP BY uf.user_id";
|
|
|
$res = Database::query($sql);
|
|
|
$list_friends = array();
|
|
|
while ($friends = Database::fetch_array($res)) {
|
|
@@ -487,4 +467,3 @@ class Statistics
|
|
|
return $list_friends;
|
|
|
}
|
|
|
}
|
|
|
-?>
|