Adding sleeping teachers/students counter in the reporting tab see BT#6770

1.9.x
Julio Montoya 12 years ago
parent 59d92d7b55
commit 311e823bd0
  1. 129
      main/inc/lib/sessionmanager.lib.php
  2. 17
      main/mySpace/index.php
  3. 49
      main/mySpace/student.php
  4. 116
      main/mySpace/teachers.php

@ -3141,6 +3141,8 @@ class SessionManager
* @param int $column
* @param string $direction
* @param string $keyword
* @param string $active
* @param string $lastConnectionDate
* @return array|int
*/
public static function getAllUsersFromCoursesFromAllSessionFromStatus(
@ -3152,7 +3154,8 @@ class SessionManager
$column = 1,
$direction = 'asc',
$keyword = null,
$active = null
$active = null,
$lastConnectionDate = null
) {
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
@ -3213,6 +3216,7 @@ class SessionManager
}
$select = "SELECT DISTINCT u.*";
if ($getCount) {
$select = "SELECT count(DISTINCT u.user_id) as count ";
}
@ -3221,11 +3225,29 @@ class SessionManager
FROM $tbl_session s
INNER JOIN $tbl_session_rel_course_rel_user su ON (s.id = su.id_session)
INNER JOIN $tbl_user u ON (u.user_id = su.id_user AND s.id = id_session)
INNER JOIN $tbl_session_rel_access_url url ON (url.session_id = s.id)
WHERE access_url_id = $urlId
INNER JOIN $tbl_session_rel_access_url url ON (url.session_id = s.id)";
if (!empty($lastConnectionDate)) {
$loginTable = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$sql .= " INNER JOIN $loginTable l ON (l.login_user_id = u.user_id) ";
}
$where = " WHERE access_url_id = $urlId
$statusConditions
$activeCondition
";
";
if (!empty($lastConnectionDate)) {
$lastConnectionDate = Database::escape_string($lastConnectionDate);
$where .= " AND l.login_date = (
SELECT MAX(a.login_date)
FROM $loginTable as a
WHERE a.login_user_id = u.user_id
)";
$where .= " AND l.login_date <= '$lastConnectionDate' ";
}
$sql .= $where;
if (!empty($keyword)) {
$keyword = Database::escape_string($keyword);
@ -3402,10 +3424,11 @@ class SessionManager
/**
* @param string $keyword
* @param int $active
* @param string $active
* @param string $lastConnectionDate
* @return array|int
*/
public static function getCountUserTracking($keyword = null, $active = null)
public static function getCountUserTracking($keyword = null, $active = null, $lastConnectionDate = null)
{
if (!isset($keyword)) {
$keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
@ -3426,7 +3449,8 @@ class SessionManager
null,
null,
$keyword,
$active
$active,
$lastConnectionDate
);
} else {
$count = self::getAllUsersFromCoursesFromAllSessionFromStatus(
@ -3438,7 +3462,8 @@ class SessionManager
null,
null,
$keyword,
$active
$active,
$lastConnectionDate
);
}
} else {
@ -3452,7 +3477,8 @@ class SessionManager
null,
null,
$keyword,
$active
$active,
$lastConnectionDate
);
} else {
$count = self::getAllUsersFromCoursesFromAllSessionFromStatus(
@ -3464,13 +3490,96 @@ class SessionManager
null,
null,
$keyword,
$active
$active,
$lastConnectionDate
);
}
}
return $count;
}
/**
* @param int $userId
* @param int $active
* @param string $lastConnectionDate
* @param bool $getCount
*/
public function getTeacherTracking($userId, $active = 1, $lastConnectionDate = null, $getCount = false)
{
$teacherResult = array();
if (api_is_drh() || api_is_platform_admin()) {
// Followed teachers by drh
if (api_drh_can_access_all_session_content()) {
$sessions = SessionManager::get_sessions_followed_by_drh($userId);
if (!empty($sessions)) {
foreach ($sessions as $session) {
$coursesFromSession = SessionManager::get_course_list_by_session_id($session['id']);
foreach ($coursesFromSession as $course) {
$teachers = CourseManager::get_teacher_list_from_course_code($course['code']);
foreach ($teachers as $teacher) {
if (isset($teacherResult[$teacher['user_id']])) {
continue;
}
$teacherResult[$teacher['user_id']] = $teacher;
}
}
}
}
} else {
$teacherResult = UserManager::get_users_followed_by_drh($userId, COURSEMANAGER);
}
}
if (!empty($teacherResult)) {
$tableUser = Database::get_main_table(TABLE_MAIN_USER);
$select = "SELECT DISTINCT u.* ";
if ($getCount) {
$select = "SELECT count(DISTINCT(u.user_id)) as count";
}
$sql = "$select FROM $tableUser u";
if (!empty($lastConnectionDate)) {
$tableLogin = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$sql .= " INNER JOIN $tableLogin l ON (l.login_user_id = u.user_id) ";
}
$active = intval($active);
$teacherListId = array();
foreach ($teacherResult as $userInfo) {
$teacherListId[] = $userInfo['user_id'];
}
$teacherListId = implode("','", $teacherListId);
$where = " WHERE u.active = $active AND u.user_id IN ('$teacherListId') ";
if (!empty($lastConnectionDate)) {
$lastConnectionDate = Database::escape_string($lastConnectionDate);
$where .= " AND l.login_date = (
SELECT MAX(a.login_date)
FROM $tableLogin as a
WHERE a.login_user_id = u.user_id
) AND ";
$where .= " l.login_date <= '$lastConnectionDate' ";
}
$sql .= $where;
$result = Database::query($sql);
if (Database::num_rows($result)) {
if ($getCount) {
$row = Database::fetch_array($result);
return $row['count'];
} else {
return Database::store_result($result, 'ASSOC');
}
}
}
return 0;
}
/**
* Get the list of course tools that have to be dealt with in case of
* registering any course to a session

@ -374,6 +374,11 @@ if (empty($session_id)) {
$countActiveUsers = SessionManager::getCountUserTracking(null, 1);
$countInactiveUsers = SessionManager::getCountUserTracking(null, 0);
$lastConnectionDate = api_get_utc_datetime(strtotime('15 days ago'));
$countSleepingTeachers = SessionManager::getTeacherTracking(api_get_user_id(), 1, $lastConnectionDate, true);
$countSleepingStudents =SessionManager::getCountUserTracking(null, 1, $lastConnectionDate);
$form = new FormValidator('search_user', 'get', api_get_path(WEB_CODE_PATH).'mySpace/student.php');
$form->addElement('text', 'keyword', get_lang('User'));
$form->addElement('button', 'submit', get_lang('Search'));
@ -386,11 +391,21 @@ if (empty($session_id)) {
<td>'.Display::url(get_lang('ActiveUsers'), api_get_path(WEB_CODE_PATH).'mySpace/student.php?active=1').'</td>
<td align="right">'.$countActiveUsers.'</td>
</tr>
<tr>
<tr>
<td>'.Display::url(get_lang('InactiveUsers'), api_get_path(WEB_CODE_PATH).'mySpace/student.php?active=0').'</td>
<td align="right">'.$countInactiveUsers.'</td>
</tr>
<tr>
<td>'.Display::url(get_lang('SleepingTeachers'), api_get_path(WEB_CODE_PATH).'mySpace/teachers.php?sleeping_days=15').'</td>
<td align="right">'.$countSleepingTeachers.'</td>
</tr>
<tr>
<td>'.Display::url(get_lang('SleepingStudents'), api_get_path(WEB_CODE_PATH).'mySpace/student.php?sleeping_days=15').'</td>
<td align="right">'.$countSleepingStudents.'</td>
</tr>
<tr>
<td>'.get_lang('AverageCoursePerStudent').'</td>
<td align="right">'.(is_null($avg_courses_per_student) ? '' : $avg_courses_per_student).'</td>

@ -16,6 +16,7 @@ require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
$export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
$keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
$active = isset($_GET['active']) ? intval($_GET['active']) : null;
api_block_anonymous_users();
@ -40,6 +41,12 @@ function get_users($from, $number_of_items, $column, $direction)
{
$active = isset($_GET['active']) ? $_GET['active'] : null;
$keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
$sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null;
$lastConnectionDate = null;
if (!empty($sleepingDays)) {
$lastConnectionDate = api_get_utc_datetime(strtotime($sleepingDays.' days ago'));
}
$is_western_name_order = api_is_western_name_order();
$coach_id = api_get_user_id();
@ -56,7 +63,8 @@ function get_users($from, $number_of_items, $column, $direction)
$column,
$direction,
$keyword,
$active
$active,
$lastConnectionDate
);
} else {
$students = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
@ -68,7 +76,8 @@ function get_users($from, $number_of_items, $column, $direction)
$column,
$direction,
$keyword,
$active
$active,
$lastConnectionDate
);
}
} else {
@ -82,7 +91,8 @@ function get_users($from, $number_of_items, $column, $direction)
$column,
$direction,
$keyword,
$active
$active,
$lastConnectionDate
);
} else {
$students = SessionManager::getAllUsersFromCoursesFromAllSessionFromStatus(
@ -94,7 +104,8 @@ function get_users($from, $number_of_items, $column, $direction)
$column,
$direction,
$keyword,
$active
$active,
$lastConnectionDate
);
}
}
@ -171,12 +182,13 @@ $sort_by_first_name = api_sort_by_first_name();
$actions .= '<div class="actions">';
if (api_is_drh()) {
$menu_items = array();
$menu_items[] = Display::url(Display::return_icon('stats.png', get_lang('MyStats'),'',ICON_SIZE_MEDIUM), api_get_path(WEB_CODE_PATH)."auth/my_progress.php" );
$menu_items[] = Display::url(Display::return_icon('user_na.png', get_lang('Students'), array(), ICON_SIZE_MEDIUM), '#');
$menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('Trainers'), array(), ICON_SIZE_MEDIUM), 'teachers.php');
$menu_items[] = Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), ICON_SIZE_MEDIUM), 'course.php');
$menu_items[] = Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_MEDIUM), 'session.php');
$menu_items = array(
Display::url(Display::return_icon('stats.png', get_lang('MyStats'), '', ICON_SIZE_MEDIUM), api_get_path(WEB_CODE_PATH)."auth/my_progress.php" ),
Display::url(Display::return_icon('user_na.png', get_lang('Students'), array(), ICON_SIZE_MEDIUM), '#'),
Display::url(Display::return_icon('teacher.png', get_lang('Trainers'), array(), ICON_SIZE_MEDIUM), 'teachers.php'),
Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), ICON_SIZE_MEDIUM), 'course.php'),
Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_MEDIUM), 'session.php')
);
$nb_menu_items = count($menu_items);
if ($nb_menu_items > 1) {
@ -201,7 +213,8 @@ $table = new SortableTable(
);
$params = array(
'keyword' => isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null,
'keyword' => $keyword,
'active' => $active
);
$table->set_additional_parameters($params);
@ -214,7 +227,7 @@ if ($is_western_name_order) {
}
$table->set_header(2, get_lang('FirstLogin'), false);
$table->set_header(3, get_lang('LatestLogin'), false);
$table->set_header(3, get_lang('LastConnexion'), false);
$table->set_header(4, get_lang('Details'), false);
if ($export_csv) {
@ -223,14 +236,14 @@ if ($export_csv) {
get_lang('FirstName', ''),
get_lang('LastName', ''),
get_lang('FirstLogin', ''),
get_lang('LatestLogin', '')
get_lang('LastConnexion', '')
);
} else {
$csv_header[] = array (
get_lang('LastName', ''),
get_lang('FirstName', ''),
get_lang('FirstLogin', ''),
get_lang('LatestLogin', '')
get_lang('LastConnexion', '')
);
}
}
@ -256,6 +269,14 @@ if ($export_csv) {
echo $actions;
$page_title = get_lang('Students');
echo Display::page_subheader($page_title);
if (isset($active)) {
if ($active) {
$activeLabel = get_lang('ActiveUsers');
} else {
$activeLabel = get_lang('InactiveUsers');
}
echo Display::page_subheader2($activeLabel);
}
$form->display();
$table->display();
}

@ -15,6 +15,8 @@ $cidReset = true;
require_once '../inc/global.inc.php';
require_once 'myspace.lib.php';
$userId = api_get_user_id();
$this_section = SECTION_TRACKING;
$nameTools = get_lang('Teachers');
@ -23,11 +25,13 @@ api_block_anonymous_users();
$interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
Display :: display_header($nameTools);
$sleepingDays = isset($_GET['sleeping_days']) ? intval($_GET['sleeping_days']) : null;
$formateurs = array();
if (api_is_drh() || api_is_platform_admin()) {
// Followed teachers by drh
// Followed teachers by drh
if (api_drh_can_access_all_session_content()) {
$sessions = SessionManager::get_sessions_followed_by_drh(api_get_user_id());
$sessions = SessionManager::get_sessions_followed_by_drh($userId);
if (!empty($sessions)) {
$formateurs = array();
foreach ($sessions as $session) {
@ -43,17 +47,24 @@ if (api_is_drh() || api_is_platform_admin()) {
}
}
}
} else {
$formateurs = UserManager::get_users_followed_by_drh($_user['user_id'], COURSEMANAGER);
$formateurs = UserManager::get_users_followed_by_drh($userId, COURSEMANAGER);
}
$lastConnectionDate = null;
if (!empty($sleepingDays)) {
$lastConnectionDate = api_get_utc_datetime(strtotime($sleepingDays.' days ago'));
}
$formateurs = SessionManager::getTeacherTracking($userId, 1, $lastConnectionDate);
$menu_items = array(
Display::url(Display::return_icon('stats.png', get_lang('MyStats'), '', ICON_SIZE_MEDIUM), api_get_path(WEB_CODE_PATH)."auth/my_progress.php" ),
Display::url(Display::return_icon('user.png', get_lang('Students'), array(), ICON_SIZE_MEDIUM), "index.php?view=drh_students&amp;display=yourstudents"),
Display::url(Display::return_icon('user.png', get_lang('Students'), array(), ICON_SIZE_MEDIUM), "index.php?view=drh_students&amp;display=yourstudents"),
Display::url(Display::return_icon('teacher_na.png', get_lang('Trainers'), array(), ICON_SIZE_MEDIUM), '#'),
Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), ICON_SIZE_MEDIUM), 'course.php'),
Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_MEDIUM), 'session.php')
Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), ICON_SIZE_MEDIUM), 'course.php'),
Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), ICON_SIZE_MEDIUM), 'session.php')
);
echo '<div class="actions">';
@ -71,15 +82,17 @@ if (api_is_drh() || api_is_platform_admin()) {
}
echo '</div>';
echo Display::page_subheader(get_lang('YourTeachers'));
if (!empty($lastConnectionDate)) {
echo Display::page_subheader2(get_lang('SleepingTeachers').' '.api_get_local_time($lastConnectionDate));
}
}
if (!api_is_drh()) {
api_display_tool_title($nameTools);
}
/**
* MAIN PART
*/
/** MAIN PART */
if (isset($_POST['export'])) {
$is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
@ -135,9 +148,27 @@ $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>';
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('LastConnexion').'</th>
<th>'.get_lang('AdminCourses').'</th>
<th>'.get_lang('Students').'</th>
</tr>';
} else {
echo '<table class="data_table"><tr><th>'.get_lang('LastName').'</th><th>'.get_lang('FirstName').'</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('LastName').'</th>
<th>'.get_lang('FirstName').'</th>
<th>'.$time_label.'</th>
<th>'.get_lang('Email').'</th>
<th>'.get_lang('LastConnexion').'</th>
<th>'.get_lang('AdminCourses').'</th>
<th>'.get_lang('Students').'</th>
</tr>';
}
if ($is_western_name_order) {
@ -156,21 +187,21 @@ $data = array();
if (count($formateurs) > 0) {
$i = 1;
foreach ($formateurs as $formateur) {
foreach ($formateurs as $formateur) {
$user_id = $formateur["user_id"];
$lastname = $formateur["lastname"];
$firstname = $formateur["firstname"];
$email = $formateur["email"];
if ($i % 2 == 0) {
$css_class = "row_odd";
if ($i % 2 == 0) {
$css_class = "row_odd";
if ($i % 20 == 0 && $i != 0) {
if ($is_western_name_order) {
echo '<tr>
<th>'.get_lang('FirstName').'</th>
<th>'.get_lang('LastName').'</th>
<th>'.get_lang('Email').'</th>
<th>'.get_lang('LastConnexion').'</th>
<th>'.get_lang('AdminCourses').'</th>
<th>'.get_lang('Students').'</th>
</tr>';
@ -179,6 +210,7 @@ if (count($formateurs) > 0) {
<th>'.get_lang('LastName').'</th>
<th>'.get_lang('FirstName').'</th>
<th>'.get_lang('Email').'</th>
<th>'.get_lang('LastConnexion').'</th>
<th>'.get_lang('AdminCourses').'</th>
<th>'.get_lang('Students').'</th>
</tr>';
@ -188,7 +220,7 @@ if (count($formateurs) > 0) {
$css_class = "row_even";
}
$i++;
$i++;
if ($is_western_name_order) {
$data[$user_id]["firstname"] = $firstname;
@ -198,24 +230,50 @@ 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, $start_date, $end_date));
$data[$user_id]["timespentlastweek"] = $time_on_platform;
$data[$user_id]["email"] = $email;
$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;
$timestamp = Tracking::get_last_connection_date($user_id, false, true);
$lastConnection = api_get_local_time($timestamp);
if ($is_western_name_order) {
echo '<tr class="'.$css_class.'"><td>'.$firstname.'</td><td>'.$lastname.'</td><td align="right">'.$time_on_platform.'</td><td align="right"><a href="mailto:'.$email.'">'.$email.'</a></td><td align="right"><a href="course.php?user_id='.$user_id.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></td><td align="right"><a href="student.php?user_id='.$user_id.'&amp;display=yourstudents"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></td></tr>';
} else {
echo '<tr class="'.$css_class.'"><td>'.$lastname.'</td><td>'.$firstname.'</td><td align="right">'.$time_on_platform.'</td><td align="right"><a href="mailto:'.$email.'">'.$email.'</a></td><td align="right"><a href="course.php?user_id='.$user_id.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></td><td align="right"><a href="student.php?user_id='.$user_id.'&amp;display=yourstudents"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></td></tr>';
}
}
if ($is_western_name_order) {
echo '<tr class="'.$css_class.'">
<td>'.$firstname.'</td>
<td>'.$lastname.'</td>
<td align="right">'.$time_on_platform.'</td>
<td align="right"><a href="mailto:'.$email.'">'.$email.'</a></td>
<td align="right">'.$lastConnection.'</td>
<td align="right">
<a href="course.php?user_id='.$user_id.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>
</td>
<td align="right">
<a href="student.php?user_id='.$user_id.'&amp;display=yourstudents">
<img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>
</td>
</tr>';
} else {
echo '<tr class="'.$css_class.'"><td>'.$lastname.'</td>
<td>'.$firstname.'</td><td align="right">'.$time_on_platform.'</td>
<td align="right"><a href="mailto:'.$email.'">'.$email.'</a></td>
<td align="right"><a href="course.php?user_id='.$user_id.'">
<img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>
</td>
<td align="right"><a href="student.php?user_id='.$user_id.'&amp;display=yourstudents">
<img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>
</td>
</tr>';
}
}
} else {
// No results
echo '<tr><td colspan="6">'.get_lang("NoResults").'</td></tr>';
// No results
echo '<tr><td colspan="6">'.get_lang("NoResults").'</td></tr>';
}
echo '</table>';
if (isset($_POST['export']) || (api_is_drh() && isset($_GET['export']))) {
MySpace::export_csv($header, $data, 'teachers.csv');
MySpace::export_csv($header, $data, 'teachers.csv');
}
if (!api_is_drh()) {

Loading…
Cancel
Save