Trying to improve time filter

skala
Julio Montoya 14 years ago
parent a76fdf0ef0
commit 0ce6128dd4
  1. 1
      main/inc/lib/text.lib.php
  2. 27
      main/inc/lib/tracking.lib.php
  3. 5
      main/mySpace/teachers.php

@ -607,6 +607,7 @@ function get_last_week() {
}
$lastweek = sprintf("%02d", $lastweek);
$arrdays = array();
for ($i = 1; $i <= 7; $i++) {
$arrdays[] = strtotime("$year"."W$lastweek"."$i");
}

@ -25,24 +25,35 @@ class Tracking {
/**
* Calculates the time spent on the platform by a user
* @param int User id
* @param bool True for calculating only time spent last week (optional)
* @param int Timestamp for filtering by Day (optional, default = 0)
* @param string type of time filter: 'last_week' or 'custom'
* @param strgin start date
* @param strgin end date
* @return timestamp $nb_seconds
*/
public static function get_time_spent_on_the_platform($user_id, $last_week = false, $by_day = 0) {
public static function get_time_spent_on_the_platform($user_id, $time_filter = 'last_week', $start_date = null, $end_date = null) {
$tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$condition_time = '';
if ($last_week) {
if (empty($time_filter)) {
$time_filter = 'last_week';
}
switch ($time_filter) {
case 'last_week':
$a_last_week = get_last_week();
$fday_last_week = date('Y-m-d H:i:s',$a_last_week[0]);
$lday_last_week = date('Y-m-d H:i:s',$a_last_week[6]);
$condition_time = ' AND (login_date >= "'.$fday_last_week.'" AND logout_date <= "'.$lday_last_week.'") ';
} else if (!empty($by_day)) {
$fdate_time = date('Y-m-d',$by_day).' 00:00:00';
$ldate_time = date('Y-m-d',$by_day).' 23:59:59';
$condition_time = ' AND (login_date >= "'.$fdate_time.'" AND logout_date <= "'.$ldate_time.'" ) ';
break;
case 'last_month':
break;
case 'custom':
if (empty($start_date) && !empty($end_date)) {
$condition_time = ' AND (login_date >= "'.$start_date.'" AND logout_date <= "'.$end_date.'" ) ';
}
break;
}
$sql = 'SELECT login_date, logout_date FROM '.$tbl_track_login.'

@ -6,11 +6,8 @@ ob_start();
// names of the language file that needs to be included
$language_file = array ('registration', 'index', 'trad4all', 'tracking', 'admin');
$cidReset = true;
require_once '../inc/global.inc.php';
require_once 'myspace.lib.php';
require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
$this_section = SECTION_TRACKING;
@ -140,7 +137,7 @@ if (count($formateurs) > 0) {
$data[$user_id]["firstname"] = $firstname;
}
$time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($user_id,true));
$time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($user_id, 'last_week'));
$data[$user_id]["timespentlastweek"] = $time_on_platform;
$data[$user_id]["email"] = $email;

Loading…
Cancel
Save