Browse Source

Implemented platformwide not logged in statistics (closes #1929)

ywarnier 14 years ago
parent
commit
5f3b160801
2 changed files with 48 additions and 0 deletions
  1. 4 0
      main/admin/statistics/index.php
  2. 44 0
      main/admin/statistics/statistics.lib.php

+ 4 - 0
main/admin/statistics/index.php

@@ -45,6 +45,7 @@ $tools[$strUsers]['action=logins&type=month'] = get_lang('Logins').' ('.get_
 $tools[$strUsers]['action=logins&type=day'] = get_lang('Logins').' ('.get_lang('PeriodDay').')';
 $tools[$strUsers]['action=logins&type=hour'] = get_lang('Logins').' ('.get_lang('PeriodHour').')';
 $tools[$strUsers]['action=pictures'] = get_lang('CountUsers').' ('.get_lang('UserPicture').')';
+$tools[$strUsers]['action=no_login_users'] = get_lang('StatsUsersDidNotLoginInLastPeriods');
 
 // system ...
 $tools[$strSystem]['action=activities'] = get_lang('ImportantActivities');
@@ -131,6 +132,9 @@ switch ($_GET['action']) {
 		$friends = statistics::get_friends();
 		statistics::print_stats(get_lang('CountFriends'), $friends);
 		break;
+    case 'no_login_users':
+        statistics::print_users_not_logged_in_stats();
+        break;
 }
 
 Display::display_footer();

+ 44 - 0
main/admin/statistics/statistics.lib.php

@@ -623,4 +623,48 @@ class Statistics {
         }
         return $list_friends;
     }
+    /**
+     * Print the number of users that didn't login for a certain period of time
+     */
+    function print_users_not_logged_in_stats() {
+        global $_configuration;
+        $total_logins = array();
+        $table = Database::get_statistic_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();
+        if ($_configuration['multiple_access_urls']) {
+            $table_url = ", $access_url_rel_user_table";
+            $where_url = " AND login_user_id=user_id AND access_url_id='".$current_url_id."'";
+        } else {
+            $table_url = '';
+            $where_url='';
+        }
+        $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";
+        $sql[get_lang('Last7days')]  = 
+            "SELECT count(distinct(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(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)] = 
+            "SELECT count(distinct(login_user_id)) AS number ".
+            " FROM $table $table_url ".
+            " WHERE DATE_ADD(login_date, INTERVAL 6 MONTH) >= NOW() $where_url";
+        $sql[get_lang('NeverConnected')]      = 
+            "SELECT count(distinct(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);
+            $r = $total - $obj->number;
+            $total_logins[$index] = $r < 0 ? 0 : $r;
+        }
+        Statistics::print_stats(get_lang('StatsUsersDidNotLoginInLastPeriods'),$total_logins,false);
+    }
 }