Esempio n. 1
0
					FROM ' . $tbl_user . ',' . $tbl_sessions . ' as session,' . $tbl_track_login . ' , ' . $tbl_session_rel_access_url . ' as session_rel_url
					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;
Esempio n. 2
0
 /**
  * @param int $user_id
  * @param bool $include_sessions
  * @return array
  */
 public static function get_user_list_from_courses_as_coach($user_id, $include_sessions = true)
 {
     $students_in_courses = array();
     $sessions = CourseManager::get_course_list_as_coach($user_id, true);
     if (!empty($sessions)) {
         foreach ($sessions as $session_id => $courses) {
             if (!$include_sessions) {
                 if (!empty($session_id)) {
                     continue;
                 }
             }
             if (empty($session_id)) {
                 foreach ($courses as $course_code) {
                     $students_in_course = CourseManager::get_user_list_from_course_code($course_code);
                     foreach ($students_in_course as $user_item) {
                         //Only students
                         if ($user_item['status_rel'] == STUDENT) {
                             $students_in_courses[$user_item['user_id']] = $user_item['user_id'];
                         }
                     }
                 }
             } else {
                 $students_in_course = SessionManager::get_users_by_session($session_id, '0');
                 if (is_array($students_in_course)) {
                     foreach ($students_in_course as $user_item) {
                         $students_in_courses[$user_item['user_id']] = $user_item['user_id'];
                     }
                 }
             }
         }
     }
     $students = Tracking::get_student_followed_by_coach($user_id);
     if (!empty($students_in_courses)) {
         if (!empty($students)) {
             $students = array_merge($students, $students_in_courses);
         } else {
             $students = $students_in_courses;
         }
     }
     if (!empty($students)) {
         $students = array_unique($students);
     }
     return $students;
 }
Esempio n. 3
0
    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();
    }