Adding time filter in the teacher view

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

@ -26,11 +26,11 @@ class Tracking {
* Calculates the time spent on the platform by a user
* @param int User id
* @param string type of time filter: 'last_week' or 'custom'
* @param strgin start date
* @param strgin end date
* @param strgin start date date('Y-m-d H:i:s')
* @param strgin end date date('Y-m-d H:i:s')
* @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);
@ -40,17 +40,21 @@ class Tracking {
$time_filter = 'last_week';
}
$today = date('Y-m-d H:i:s');
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.'") ';
case 'last_7_days':
$new_date = strtotime('-7 day');
$new_date = date('Y-m-d H:i:s', $new_date);
$condition_time = ' AND (login_date >= "'.$new_date.'" AND logout_date <= "'.$today.'") ';
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;
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.'" ) ';
}
break;

@ -82,21 +82,30 @@ if (!api_is_drh() && !api_is_platform_admin()) {
}
}
$a_last_week = get_last_week();
$last_week = date('Y-m-d',$a_last_week[0]).' '.get_lang('To').' '.date('Y-m-d', $a_last_week[6]);
$time_filter = 'last_week';
$time_label = get_lang('TimeSpentLastWeek').'<br />'.$last_week;
if (isset($_GET['time_filter'])) {
if ($_GET['time_filter'] == 'last_month') {
$time_filter = $_GET['time_filter'];
$time_label = get_lang('TimeSpentLastMonth');
}
}
//echo Display::url(get_lang('LastMonth'), api_get_self().'?time_filter=last_month', array('class' => 'btn'));
//echo ' '.Display::url(get_lang('LastWeek'), api_get_self().'?time_filter=last_week', array('class' => 'btn'));
$time_filter = 'last_7_days';
$time_label = sprintf(get_lang('TimeSpentLastXDays'), 7);
$form = new FormValidator('time_filter');
$form->addElement('datepickerdate', 'start_date', get_lang('StartDate'), array('form_name'=>'exercise_admin'));
$form->addElement('datepickerdate', 'end_date', get_lang('EndDate'), array('form_name'=>'exercise_admin'));
$form->addRule('start_date', get_lang('InvalidDate'), 'date');
$form->addRule('end_date', get_lang('InvalidDate'), 'date');
$form->addRule(array ('start_date', 'end_date'), get_lang('StartDateShouldBeBeforeEndDate'), 'date_compare', 'lte');
$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);
$form->addelement('style_submit_button', 'submit', get_lang('Filter'));
$form->display();
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>';
@ -112,7 +121,7 @@ if ($is_western_name_order) {
$header[] = get_lang('FirstName');
}
$header[] = get_lang('TimeSpentLastWeek');
$header[] = $time_label;
$header[] = get_lang('Email');
$data = array();
@ -150,7 +159,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, $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]["email"] = $email;

Loading…
Cancel
Save