diff --git a/main/inc/lib/auth.lib.php b/main/inc/lib/auth.lib.php index 3305fd02ab..0d40f0ac5c 100755 --- a/main/inc/lib/auth.lib.php +++ b/main/inc/lib/auth.lib.php @@ -473,8 +473,7 @@ class Auth while ($row = Database::fetch_array($result)) { $row['registration_code'] = !empty($row['registration_code']); $count_users = count(CourseManager::get_user_list_from_course_code($row['code'])); - $lastmonth = mktime(0, 0, 0, date("m")-1, date("d"), date("Y")); - $count_connections_last_moth = Tracking::get_count_connections_on_the_course($row['code'], 0, $lastmonth); + $count_connections_last_month = Tracking::get_course_connections_count($row['code'], 0, api_get_utc_datetime(time()-(30*86400))); $courses[] = array( 'code' => $row['code'], 'directory' => $row['directory'], @@ -487,7 +486,7 @@ class Auth 'registration_code' => $registration_code, 'creation_date' => $row['creation_date'], 'count_users' => $count_users, - 'count_connections' => $count_connections_last_moth + 'count_connections' => $count_connections_last_month ); } @@ -540,8 +539,7 @@ class Auth $row['registration_code'] = !empty($row['registration_code']); $count_users = count(CourseManager::get_user_list_from_course_code($row['code'])); - $lastmonth = mktime(0, 0, 0, date("m")-1, date("d"), date("Y")); - $count_connections_last_moth = Tracking::get_count_connections_on_the_course($row['code'], 0, $lastmonth); + $count_connections_last_month = Tracking::get_course_connections_count($row['code'], 0, api_get_utc_datetime(time()-(30*86400))); $courses[] = array( 'code' => $row['code'], 'directory' => $row['directory'], @@ -554,7 +552,7 @@ class Auth 'registration_code' => $registration_code, 'creation_date' => $row['creation_date'], 'count_users' => $count_users, - 'count_connections' => $count_connections_last_moth + 'count_connections' => $count_connections_last_month ); // $courses[] = array('code' => $row['code'], 'directory' => $row['directory'], 'db' => $row['db_name'], 'visual_code' => $row['visual_code'], 'title' => $row['title'], 'tutor' => $row['tutor_name'], 'subscribe' => $row['subscribe'], 'unsubscribe' => $row['unsubscribe']); } diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index 680d036bdb..5e8d8fd199 100755 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -246,20 +246,22 @@ class Tracking { } /** - * Get count connections on the course + * Get count of the connections to the course during a specified period * @param string Course code * @param int Session id (optional) - * @param int number of month (optional) + * @param int Datetime from which to collect data (defaults to 0) + * @param int Datetime to which to collect data (defaults to now) * @return int count connections */ - public static function get_count_connections_on_the_course($course_code, $session_id = 0, $month = null) { + public static function get_course_connections_count($course_code, $session_id = 0, $start = 0, $stop = null) { // protect data $month_filter = ''; - if (isset($month)) { - $month = intval($month); - $month_filter = " AND MONTH(login_course_date)= $month "; + if ($start < 0) { $start = 0; } + if (!isset($stop) or ($stop < 0)) { + $stop = api_get_utc_datetime(); } + $month_filter = " AND login_course_date > '$start' AND login_course_date < '$stop' "; $course_code = Database::escape_string($course_code); $session_id = intval($session_id); @@ -3836,4 +3838,4 @@ class TrackingUserLogCSV { } -} \ No newline at end of file +}