/** * Get course list as coach * * @param int $user_id * @param bool $include_courses_in_sessions * @return array Course list * **/ public static function get_course_list_as_coach($user_id, $include_courses_in_sessions = false) { // 1. Getting courses as teacher (No session) $courses_temp = CourseManager::get_course_list_of_user_as_course_admin($user_id); $courseList = array(); if (!empty($courses_temp)) { foreach ($courses_temp as $course_item) { $courseList[0][$course_item['code']] = $course_item['code']; } } //2. Include courses in sessions if ($include_courses_in_sessions) { $sessions = Tracking::get_sessions_coached_by_user($user_id); if (!empty($sessions)) { foreach ($sessions as $session_item) { $courses = Tracking::get_courses_followed_by_coach($user_id, $session_item['id']); if (is_array($courses)) { foreach ($courses as $course_item) { $courseList[$session_item['id']][$course_item] = $course_item; } } } } } return $courseList; }
break; case 'get_sessions_tracking': if (api_is_drh()) { $sessions = SessionManager::get_sessions_followed_by_drh(api_get_user_id(), $start, $limit, false, false, false, null, $keyword, $description); } else { // Sessions for the coach $sessions = Tracking::get_sessions_coached_by_user(api_get_user_id(), $start, $limit, false, $keyword, $description); } $columns = array('name', 'date', 'course_per_session', 'student_per_session', 'details'); $result = array(); if (!empty($sessions)) { foreach ($sessions as $session) { if (api_drh_can_access_all_session_content()) { $count_courses_in_session = count(SessionManager::get_course_list_by_session_id($session['id'])); } else { $count_courses_in_session = count(Tracking::get_courses_followed_by_coach($user_id, $session['id'])); } $count_users_in_session = count(SessionManager::get_users_by_session($session['id'], 0)); $session_date = array(); if (!empty($session['access_start_date']) && $session['access_start_date'] != '0000-00-00') { $session_date[] = get_lang('From') . ' ' . api_format_date($session['access_start_date'], DATE_FORMAT_SHORT); } if (!empty($session['access_end_date']) && $session['access_end_date'] != '0000-00-00') { $session_date[] = get_lang('Until') . ' ' . api_format_date($session['access_end_date'], DATE_FORMAT_SHORT); } if (empty($session_date)) { $session_date_string = '-'; } else { $session_date_string = implode(' ', $session_date); } $sessionUrl = api_get_path(WEB_CODE_PATH) . 'mySpace/course.php?session_id=' . $session['id'];
$tbl_user_course = Database::get_main_table(TABLE_MAIN_COURSE_USER); if (isset($_GET['action'])) { if ($_GET['action'] == 'show_message') { Display::display_normal_message(stripslashes($_GET['message']), false); } if ($_GET['action'] == 'error_message') { Display::display_error_message(stripslashes($_GET['message']), false); } } if ($show_import_icon) { echo "<div align=\"right\">"; echo '<a href="user_import.php?id_session=' . $id_session . '&action=export&type=xml">' . Display::return_icon('excel.gif', get_lang('ImportUserListXMLCSV')) . ' ' . get_lang('ImportUserListXMLCSV') . '</a>'; echo "</div><br />"; } if (!api_is_drh() && !api_is_session_admin() && !api_is_platform_admin()) { $courses = Tracking::get_courses_followed_by_coach($_user['user_id'], $id_session); $a_courses = array_keys($courses); } $nb_courses = count($a_courses); $table = new SortableTable('tracking_list_course', 'count_courses'); $table->set_header(0, get_lang('CourseTitle'), false); $table->set_header(1, get_lang('NbStudents'), false); $table->set_header(2, get_lang('TimeSpentInTheCourse') . Display::return_icon('info3.gif', get_lang('TimeOfActiveByTraining'), array('align' => 'absmiddle', 'hspace' => '3px')), false); $table->set_header(3, get_lang('ThematicAdvance'), false); $table->set_header(4, get_lang('AvgStudentsProgress') . Display::return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false); $table->set_header(5, get_lang('AvgCourseScore') . Display::return_icon('info3.gif', get_lang('AvgAllUsersInAllCourses'), array('align' => 'absmiddle', 'hspace' => '3px')), false); //$table -> set_header(5, get_lang('AvgExercisesScore'), false);// no code for this? $table->set_header(6, get_lang('AvgMessages'), false); $table->set_header(7, get_lang('AvgAssignments'), false); $table->set_header(8, get_lang('Details'), false); $csv_header[] = array(get_lang('CourseTitle', ''), get_lang('NbStudents', ''), get_lang('TimeSpentInTheCourse', ''), get_lang('ThematicAdvance', ''), get_lang('AvgStudentsProgress', ''), get_lang('AvgCourseScore', ''), get_lang('AvgMessages', ''), get_lang('AvgAssignments', ''));
WHERE id_coach=user_id AND login_user_id=user_id AND access_url_id = ' . $access_url_id . ' AND session_rel_url.session_id=session.id GROUP BY user_id ORDER BY login_date ' . $tracking_direction; } } $result_sessions_coach = Database::query($sql_session_coach); $total_no_coaches += Database::num_rows($result_sessions_coach); while ($coach = Database::fetch_array($result_sessions_coach)) { $global_coaches[$coach['user_id']] = $coach; } $all_datas = array(); foreach ($global_coaches as $id_coach => $coaches) { $time_on_platform = api_time_to_hms(Tracking::get_time_spent_on_the_platform($coaches['user_id'])); $last_connection = Tracking::get_last_connection_date($coaches['user_id']); $nb_students = count(Tracking::get_student_followed_by_coach($coaches['user_id'])); $nb_courses = count(Tracking::get_courses_followed_by_coach($coaches['user_id'])); $nb_sessions = count(Tracking::get_sessions_coached_by_user($coaches['user_id'])); $table_row = array(); if ($is_western_name_order) { $table_row[] = $coaches['firstname']; $table_row[] = $coaches['lastname']; } else { $table_row[] = $coaches['lastname']; $table_row[] = $coaches['firstname']; } $table_row[] = $time_on_platform; $table_row[] = $last_connection; $table_row[] = $nb_students; $table_row[] = $nb_courses; $table_row[] = $nb_sessions; $table_row[] = '<a href="session.php?id_coach=' . $coaches['user_id'] . '"><img src="' . api_get_path(WEB_IMG_PATH) . '2rightarrow.gif" border="0" /></a>';
public static function display_tracking_coach_overview($export_csv) { global $charset; if ($export_csv) { $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT); } else { $is_western_name_order = api_is_western_name_order(); } $sort_by_first_name = api_sort_by_first_name(); $tracking_column = isset($_GET['tracking_list_coaches_column']) ? $_GET['tracking_list_coaches_column'] : ($is_western_name_order xor $sort_by_first_name) ? 1 : 0; $tracking_direction = isset($_GET['tracking_list_coaches_direction']) && in_array(strtoupper($_GET['tracking_list_coaches_direction']), array('ASC', 'DESC', 'ASCENDING', 'DESCENDING', '0', '1')) ? $_GET['tracking_list_coaches_direction'] : 'DESC'; // Prepare array for column order - when impossible, use some of user names. if ($is_western_name_order) { $order = array(0 => 'firstname', 1 => 'lastname', 2 => $sort_by_first_name ? 'firstname' : 'lastname', 3 => 'login_date', 4 => $sort_by_first_name ? 'firstname' : 'lastname', 5 => $sort_by_first_name ? 'firstname' : 'lastname'); } else { $order = array(0 => 'lastname', 1 => 'firstname', 2 => $sort_by_first_name ? 'firstname' : 'lastname', 3 => 'login_date', 4 => $sort_by_first_name ? 'firstname' : 'lastname', 5 => $sort_by_first_name ? 'firstname' : 'lastname'); } $table = new SortableTable('tracking_list_coaches_myspace', array('MySpace', 'count_coaches'), null, ($is_western_name_order xor $sort_by_first_name) ? 1 : 0); $parameters['view'] = 'admin'; $table->set_additional_parameters($parameters); if ($is_western_name_order) { $table->set_header(0, get_lang('FirstName'), true); $table->set_header(1, get_lang('LastName'), true); } else { $table->set_header(0, get_lang('LastName'), true); $table->set_header(1, get_lang('FirstName'), true); } $table->set_header(2, get_lang('TimeSpentOnThePlatform'), false); $table->set_header(3, get_lang('LastConnexion'), false); $table->set_header(4, get_lang('NbStudents'), false); $table->set_header(5, get_lang('CountCours'), false); $table->set_header(6, get_lang('NumberOfSessions'), false); $table->set_header(7, get_lang('Sessions'), false); if ($is_western_name_order) { $csv_header[] = array(get_lang('FirstName', ''), get_lang('LastName', ''), get_lang('TimeSpentOnThePlatform', ''), get_lang('LastConnexion', ''), get_lang('NbStudents', ''), get_lang('CountCours', ''), get_lang('NumberOfSessions', '')); } else { $csv_header[] = array(get_lang('LastName', ''), get_lang('FirstName', ''), get_lang('TimeSpentOnThePlatform', ''), get_lang('LastConnexion', ''), get_lang('NbStudents', ''), get_lang('CountCours', ''), get_lang('NumberOfSessions', '')); } $tbl_track_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN); $tbl_user = Database::get_main_table(TABLE_MAIN_USER); $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $tbl_sessions = Database::get_main_table(TABLE_MAIN_SESSION); $sqlCoachs = "SELECT DISTINCT\n scu.user_id as id_coach,\n u.id as user_id,\n lastname,\n firstname,\n MAX(login_date) as login_date\n FROM {$tbl_user} u, {$tbl_session_course_user} scu, {$tbl_track_login}\n WHERE\n scu.user_id = u.id AND scu.status=2 AND login_user_id=u.id\n GROUP BY user_id "; if (api_is_multiple_url_enabled()) { $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $access_url_id = api_get_current_access_url_id(); if ($access_url_id != -1) { $sqlCoachs = "SELECT DISTINCT\n scu.user_id as id_coach,\n u.id as user_id,\n lastname,\n firstname,\n MAX(login_date) as login_date\n FROM {$tbl_user} u,\n {$tbl_session_course_user} scu,\n {$tbl_track_login} ,\n {$tbl_session_rel_access_url} session_rel_url\n WHERE\n scu.user_id = u.id AND\n scu.status = 2 AND\n login_user_id = u.id AND\n access_url_id = {$access_url_id} AND\n session_rel_url.session_id = scu.session_id\n GROUP BY u.id"; } } if (!empty($order[$tracking_column])) { $sqlCoachs .= "ORDER BY " . $order[$tracking_column] . " " . $tracking_direction; } $result_coaches = Database::query($sqlCoachs); $total_no_coaches = Database::num_rows($result_coaches); $global_coaches = array(); while ($coach = Database::fetch_array($result_coaches)) { $global_coaches[$coach['user_id']] = $coach; } $sql_session_coach = 'SELECT session.id_coach, u.id as user_id, lastname, firstname, MAX(login_date) as login_date FROM ' . $tbl_user . ' u ,' . $tbl_sessions . ' as session,' . $tbl_track_login . ' WHERE id_coach = u.id AND login_user_id = u.id GROUP BY u.id ORDER BY login_date ' . $tracking_direction; if (api_is_multiple_url_enabled()) { $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $access_url_id = api_get_current_access_url_id(); if ($access_url_id != -1) { $sql_session_coach = 'SELECT session.id_coach, u.id as user_id, lastname, firstname, MAX(login_date) as login_date FROM ' . $tbl_user . ' u ,' . $tbl_sessions . ' as session, ' . $tbl_track_login . ' , ' . $tbl_session_rel_access_url . ' as session_rel_url WHERE id_coach = u.id AND login_user_id = u.id AND access_url_id = ' . $access_url_id . ' AND session_rel_url.session_id = session.id GROUP BY u.id ORDER BY login_date ' . $tracking_direction; } } $result_sessions_coach = Database::query($sql_session_coach); $total_no_coaches += Database::num_rows($result_sessions_coach); while ($coach = Database::fetch_array($result_sessions_coach)) { $global_coaches[$coach['user_id']] = $coach; } $all_datas = array(); foreach ($global_coaches as $id_coach => $coaches) { $time_on_platform = api_time_to_hms(Tracking::get_time_spent_on_the_platform($coaches['user_id'])); $last_connection = Tracking::get_last_connection_date($coaches['user_id']); $nb_students = count(Tracking::get_student_followed_by_coach($coaches['user_id'])); $nb_courses = count(Tracking::get_courses_followed_by_coach($coaches['user_id'])); $nb_sessions = count(Tracking::get_sessions_coached_by_user($coaches['user_id'])); $table_row = array(); if ($is_western_name_order) { $table_row[] = $coaches['firstname']; $table_row[] = $coaches['lastname']; } else { $table_row[] = $coaches['lastname']; $table_row[] = $coaches['firstname']; } $table_row[] = $time_on_platform; $table_row[] = $last_connection; $table_row[] = $nb_students; $table_row[] = $nb_courses; $table_row[] = $nb_sessions; $table_row[] = '<a href="session.php?id_coach=' . $coaches['user_id'] . '"><img src="' . api_get_path(WEB_IMG_PATH) . 'icons/22/2rightarrow.png" border="0" /></a>'; $all_datas[] = $table_row; if ($is_western_name_order) { $csv_content[] = array(api_html_entity_decode($coaches['firstname'], ENT_QUOTES), api_html_entity_decode($coaches['lastname'], ENT_QUOTES), $time_on_platform, $last_connection, $nb_students, $nb_courses, $nb_sessions); } else { $csv_content[] = array(api_html_entity_decode($coaches['lastname'], ENT_QUOTES), api_html_entity_decode($coaches['firstname'], ENT_QUOTES), $time_on_platform, $last_connection, $nb_students, $nb_courses, $nb_sessions); } } if ($tracking_column != 3) { if ($tracking_direction == 'DESC') { usort($all_datas, array('MySpace', 'rsort_users')); } else { usort($all_datas, array('MySpace', 'sort_users')); } } if ($export_csv && $tracking_column != 3) { usort($csv_content, 'sort_users'); } if ($export_csv) { $csv_content = array_merge($csv_header, $csv_content); } foreach ($all_datas as $row) { $table->addRow($row, 'align="right"'); } $table->display(); }
// RRHH or session admin if (api_is_session_admin() || api_is_drh()) { $courses = CourseManager::get_courses_followed_by_drh(api_get_user_id()); $session_by_session_admin = SessionManager::get_sessions_followed_by_drh(api_get_user_id()); if (!empty($session_by_session_admin)) { foreach ($session_by_session_admin as $session_coached_by_user) { $courses_followed_by_coach = Tracking::get_courses_list_from_session($session_coached_by_user['id']); $courses_in_session_by_coach[$session_coached_by_user['id']] = $courses_followed_by_coach; } } } // Teacher or admin if (!empty($sessions_coached_by_user)) { foreach ($sessions_coached_by_user as $session_coached_by_user) { $sid = intval($session_coached_by_user['id']); $courses_followed_by_coach = Tracking::get_courses_followed_by_coach(api_get_user_id(), $sid); $courses_in_session_by_coach[$sid] = $courses_followed_by_coach; } } $sql = "SELECT c_id\n FROM {$tbl_course_user}\n WHERE\n relation_type <> " . COURSE_RELATION_TYPE_RRHH . " AND\n user_id = " . intval($user_info['user_id']); $rs = Database::query($sql); while ($row = Database::fetch_array($rs)) { if ($drh_can_access_all_courses) { $courses_in_session[0][] = $row['c_id']; } else { if (isset($courses[$row['c_id']])) { $courses_in_session[0][] = $row['c_id']; } } } // Get the list of sessions where the user is subscribed as student
echo get_lang('Score'); ?> </th> <th> <?php echo get_lang('Details'); ?> </th> </tr> <?php if (!api_is_platform_admin(true) && $_user['status'] != DRH) { // courses followed by user where we are coach if (!isset($_GET['id_coach'])) { $a_courses = Tracking::get_courses_followed_by_coach($_user['user_id']); } else { $a_courses = Tracking::get_courses_followed_by_coach(Security::remove_XSS($_GET['id_coach'])); } } if (count($a_courses) > 0) { $csv_content[] = array(); $csv_content[] = array(get_lang('Course'), get_lang('Time'), get_lang('Progress'), get_lang('Score')); foreach ($a_courses as $course_code) { if (CourseManager::is_user_subscribed_in_course($student_id, $course_code, true)) { $course_infos = CourseManager::get_course_information($course_code); $time_spent_on_course = api_time_to_hms(Tracking::get_time_spent_on_the_course($a_infosUser['user_id'], $course_code)); $progress = Tracking::get_avg_student_progress($a_infosUser['user_id'], $course_code) . ' %'; $score = Tracking::get_avg_student_score($a_infosUser['user_id'], $course_code) . ' %'; $csv_content[] = array($course_infos['title'], $time_spent_on_course, $progress, $score); echo ' <tr> <td align="right">