Adding time filter in the teacher view

skala
Julio Montoya 14 years ago
parent c83cb9f3b2
commit 09a1c5bff0
  1. 30
      main/inc/lib/tracking.lib.php
  2. 41
      main/mySpace/teachers.php

@ -26,11 +26,11 @@ class Tracking {
* Calculates the time spent on the platform by a user * Calculates the time spent on the platform by a user
* @param int User id * @param int User id
* @param string type of time filter: 'last_week' or 'custom' * @param string type of time filter: 'last_week' or 'custom'
* @param strgin start date * @param strgin start date date('Y-m-d H:i:s')
* @param strgin end date * @param strgin end date date('Y-m-d H:i:s')
* @return timestamp $nb_seconds * @return timestamp $nb_seconds
*/ */
public static function get_time_spent_on_the_platform($user_id, $time_filter = 'last_week', $start_date = null, $end_date = null) { public static function get_time_spent_on_the_platform($user_id, $time_filter = 'last_7_days', $start_date = null, $end_date = null) {
$tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
@ -38,26 +38,30 @@ class Tracking {
if (empty($time_filter)) { if (empty($time_filter)) {
$time_filter = 'last_week'; $time_filter = 'last_week';
} }
$today = date('Y-m-d H:i:s');
switch ($time_filter) { switch ($time_filter) {
case 'last_week': case 'last_7_days':
$a_last_week = get_last_week(); $new_date = strtotime('-7 day');
$fday_last_week = date('Y-m-d H:i:s',$a_last_week[0]); $new_date = date('Y-m-d H:i:s', $new_date);
$lday_last_week = date('Y-m-d H:i:s',$a_last_week[6]); $condition_time = ' AND (login_date >= "'.$new_date.'" AND logout_date <= "'.$today.'") ';
$condition_time = ' AND (login_date >= "'.$fday_last_week.'" AND logout_date <= "'.$lday_last_week.'") ';
break; break;
case 'last_month': case 'last_30_days':
$new_date = strtotime('-30 day');
$new_date = date('Y-m-d H:i:s', $new_date);
$condition_time = ' AND (login_date >= "'.$new_date.'" AND logout_date <= "'.$today.'") ';
break; break;
case 'custom': case 'custom':
if (empty($start_date) && !empty($end_date)) { if (!empty($start_date) && !empty($end_date)) {
$condition_time = ' AND (login_date >= "'.$start_date.'" AND logout_date <= "'.$end_date.'" ) '; $condition_time = ' AND (login_date >= "'.$start_date.'" AND logout_date <= "'.$end_date.'" ) ';
} }
break; break;
} }
$sql = 'SELECT login_date, logout_date FROM '.$tbl_track_login.' $sql = 'SELECT login_date, logout_date FROM '.$tbl_track_login.'
WHERE login_user_id = '.intval($user_id).$condition_time; WHERE login_user_id = '.intval($user_id).$condition_time;
$rs = Database::query($sql); $rs = Database::query($sql);
$nb_seconds = 0; $nb_seconds = 0;

@ -82,21 +82,30 @@ if (!api_is_drh() && !api_is_platform_admin()) {
} }
} }
$a_last_week = get_last_week(); $time_filter = 'last_7_days';
$last_week = date('Y-m-d',$a_last_week[0]).' '.get_lang('To').' '.date('Y-m-d', $a_last_week[6]); $time_label = sprintf(get_lang('TimeSpentLastXDays'), 7);
$form = new FormValidator('time_filter');
$time_filter = 'last_week'; $form->addElement('datepickerdate', 'start_date', get_lang('StartDate'), array('form_name'=>'exercise_admin'));
$time_label = get_lang('TimeSpentLastWeek').'<br />'.$last_week; $form->addElement('datepickerdate', 'end_date', get_lang('EndDate'), array('form_name'=>'exercise_admin'));
$form->addRule('start_date', get_lang('InvalidDate'), 'date');
if (isset($_GET['time_filter'])) { $form->addRule('end_date', get_lang('InvalidDate'), 'date');
if ($_GET['time_filter'] == 'last_month') { $form->addRule(array ('start_date', 'end_date'), get_lang('StartDateShouldBeBeforeEndDate'), 'date_compare', 'lte');
$time_filter = $_GET['time_filter'];
$time_label = get_lang('TimeSpentLastMonth'); $defaults = array();
} $defaults['start_date'] = date('Y-m-d 12:00:00', strtotime("-7 days"));
$defaults['end_date'] = date('Y-m-d 12:00:00',time());
$start_date = $end_date = null;
if ($form->validate()) {
$values = $form->exportValues();
$start_date = $defaults['start_date'] = $values['start_date'];
$end_date = $defaults['end_date'] = $values['end_date'];
$time_filter = 'custom';
$time_label = sprintf(get_lang('TimeSpentBetweenXAndY'), $start_date, $end_date);
} }
$form->setDefaults($defaults);
//echo Display::url(get_lang('LastMonth'), api_get_self().'?time_filter=last_month', array('class' => 'btn')); $form->addelement('style_submit_button', 'submit', get_lang('Filter'));
//echo ' '.Display::url(get_lang('LastWeek'), api_get_self().'?time_filter=last_week', array('class' => 'btn')); $form->display();
if ($is_western_name_order) { if ($is_western_name_order) {
echo '<table class="data_table"><tr><th>'.get_lang('FirstName').'</th><th>'.get_lang('LastName').'</th><th>'.$time_label.'</th><th>'.get_lang('Email').'</th><th>'.get_lang('AdminCourses').'</th><th>'.get_lang('Students').'</th></tr>'; echo '<table class="data_table"><tr><th>'.get_lang('FirstName').'</th><th>'.get_lang('LastName').'</th><th>'.$time_label.'</th><th>'.get_lang('Email').'</th><th>'.get_lang('AdminCourses').'</th><th>'.get_lang('Students').'</th></tr>';
@ -112,7 +121,7 @@ if ($is_western_name_order) {
$header[] = get_lang('FirstName'); $header[] = get_lang('FirstName');
} }
$header[] = get_lang('TimeSpentLastWeek'); $header[] = $time_label;
$header[] = get_lang('Email'); $header[] = get_lang('Email');
$data = array(); $data = array();
@ -150,7 +159,7 @@ if (count($formateurs) > 0) {
$data[$user_id]["firstname"] = $firstname; $data[$user_id]["firstname"] = $firstname;
} }
$time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($user_id, $time_filter)); $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($user_id, $time_filter, $start_date, $end_date));
$data[$user_id]["timespentlastweek"] = $time_on_platform; $data[$user_id]["timespentlastweek"] = $time_on_platform;
$data[$user_id]["email"] = $email; $data[$user_id]["email"] = $email;

Loading…
Cancel
Save