/**
  * Returns either all course users or all session users depending on whether
  * session is turned on or not
  *
  * @return array
  */
 public function all_users()
 {
     $course_code = $this->course('code');
     if (empty($this->session_id)) {
         $group_id = api_get_group_id();
         if (empty($group_id)) {
             $user_list = CourseManager::get_user_list_from_course_code($course_code);
         } else {
             $user_list = GroupManager::get_users($group_id);
             $new_user_list = array();
             foreach ($user_list as $user) {
                 $new_user_list[] = array('user_id' => $user);
             }
             $user_list = $new_user_list;
         }
     } else {
         $user_list = CourseManager::get_user_list_from_course_code($course_code, $this->session_id);
     }
     return $user_list;
 }
 public static function get_group_reporting($course_id, $group_id = null, $type = 'all', $start = 0, $limit = 1000, $sidx = 1, $sord = 'desc', $where_condition = array())
 {
     if (empty($course_id)) {
         return null;
     }
     $course_info = api_get_course_info_by_id($course_id);
     $table_group = Database::get_course_table(TABLE_GROUP);
     $course_id = intval($course_id);
     $select = ' * ';
     if ($type == 'count') {
         $select = ' count(id) as count ';
     }
     $default_where = array('c_id = ? ' => array($course_id));
     $result = Database::select($select, $table_group, array('limit' => " {$start}, {$limit}", 'where' => $default_where, 'order' => "{$sidx} {$sord}"));
     if ($type == 'count') {
         return $result[0]['count'];
     }
     $parsed_result = array();
     if (!empty($result)) {
         foreach ($result as $group) {
             $users = GroupManager::get_users($group['id'], true);
             $time = 0;
             $avg_student_score = 0;
             $avg_student_progress = 0;
             $work = 0;
             $messages = 0;
             foreach ($users as $user_data) {
                 $time += Tracking::get_time_spent_on_the_course($user_data['user_id'], $course_info['code'], 0);
                 $avg_student_score += Tracking::get_avg_student_score($user_data['user_id'], $course_info['code'], array(), 0);
                 $avg_student_progress += Tracking::get_avg_student_progress($user_data['user_id'], $course_info['code'], array(), 0);
                 $work += Tracking::count_student_assignments($user_data['user_id'], $course_info['code'], 0);
                 $messages += Tracking::count_student_messages($user_data['user_id'], $course_info['code'], 0);
             }
             $group_item = array('id' => $group['id'], 'name' => $group['name'], 'time' => api_time_to_hms($time), 'progress' => $avg_student_progress, 'score' => $avg_student_score, 'works' => $work, 'messages' => $messages);
             $parsed_result[] = $group_item;
         }
     }
     return $parsed_result;
 }
 /**
  *  Return user info array of all users registered in a course
  *  This only returns the users that are registered in this actual course, not linked courses.
  *
  * @param string $course_code
  * @param boolean $with_session
  * @param integer $session_id
  * @param string $date_from
  * @param string $date_to
  * @param boolean $includeInvitedUsers Whether include the invited users
  * @param int $groupId
  * @return array with user id
  */
 public static function get_student_list_from_course_code($course_code, $with_session = false, $session_id = 0, $date_from = null, $date_to = null, $includeInvitedUsers = true, $groupId = 0)
 {
     $userTable = Database::get_main_table(TABLE_MAIN_USER);
     $session_id = intval($session_id);
     $course_code = Database::escape_string($course_code);
     $courseInfo = api_get_course_info($course_code);
     $courseId = $courseInfo['real_id'];
     $students = array();
     if ($session_id == 0) {
         if (empty($groupId)) {
             // students directly subscribed to the course
             $sql = "SELECT *\n                        FROM " . Database::get_main_table(TABLE_MAIN_COURSE_USER) . " cu\n                        INNER JOIN {$userTable} u\n                        ON cu.user_id = u.user_id\n                        WHERE c_id = '{$courseId}' AND cu.status = " . STUDENT;
             if (!$includeInvitedUsers) {
                 $sql .= " AND u.status != " . INVITEE;
             }
             $rs = Database::query($sql);
             while ($student = Database::fetch_array($rs)) {
                 $students[$student['user_id']] = $student;
             }
         } else {
             $students = GroupManager::get_users($groupId, false, null, null, false, $courseInfo['real_id']);
             $students = array_flip($students);
         }
     }
     // students subscribed to the course through a session
     if ($with_session) {
         $joinSession = "";
         //Session creation date
         if (!empty($date_from) && !empty($date_to)) {
             $joinSession = "INNER JOIN " . Database::get_main_table(TABLE_MAIN_SESSION) . " s";
         }
         $sql_query = "SELECT *\n                          FROM " . Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER) . " scu\n                          {$joinSession}\n                          INNER JOIN {$userTable} u ON scu.user_id = u.user_id\n                          WHERE scu.c_id = '{$courseId}' AND scu.status <> 2";
         if (!empty($date_from) && !empty($date_to)) {
             $date_from = Database::escape_string($date_from);
             $date_to = Database::escape_string($date_to);
             $sql_query .= " AND s.access_start_date >= '{$date_from}' AND s.access_end_date <= '{$date_to}'";
         }
         if ($session_id != 0) {
             $sql_query .= ' AND scu.session_id = ' . $session_id;
         }
         if (!$includeInvitedUsers) {
             $sql_query .= " AND u.status != " . INVITEE;
         }
         $rs = Database::query($sql_query);
         while ($student = Database::fetch_array($rs)) {
             $students[$student['user_id']] = $student;
         }
     }
     return $students;
 }
Exemple #4
0
 }
 /*	Display list of student publications */
 if (!empty($my_folder_data['description'])) {
     echo '<p><div><strong>' . get_lang('Description') . ':</strong><p>' . Security::remove_XSS($my_folder_data['description'], STUDENT) . '</p></div></p>';
 }
 $my_folder_data = get_work_data_by_id($work_id);
 $work_parents = array();
 if (empty($my_folder_data)) {
     $work_parents = getWorkList($work_id, $my_folder_data, $add_query);
 }
 if (api_is_allowed_to_edit()) {
     // Work list
     echo '<div class="row">';
     echo '<div class="span9">';
     if (!empty($group_id)) {
         $userList = GroupManager::get_users($group_id);
     } else {
         if (empty($session_id)) {
             $userList = CourseManager::get_user_list_from_course_code($course_code, $session_id, null, null, STUDENT);
         } else {
             $userList = CourseManager::get_user_list_from_course_code($course_code, $session_id, null, null, 0);
         }
         $userList = array_keys($userList);
     }
     display_student_publications_list($work_id, $my_folder_data, $work_parents, $origin, $add_query, $userList);
     echo '</div>';
     echo '<div class="span3">';
     $table = new HTML_Table(array('class' => 'data_table'));
     $column = 0;
     $row = 0;
     $headers = array(get_lang('Students'), get_lang('Works'));
     $extra = '<div style="text-align:center"><h2>' . get_lang('GroupList') . '</h2></div>';
     $extra .= '<strong>' . get_lang('Course') . ': </strong>' . $courseInfo['title'] . ' (' . $courseInfo['code'] . ')';
     $content = $extra . $content;
     $pdf->content_to_pdf($content, null, null, api_get_course_id());
     break;
 case 'export':
     $groupId = isset($_GET['id']) ? intval($_GET['id']) : null;
     $groups = GroupManager::get_group_list();
     $data = array();
     foreach ($groups as $index => $group) {
         if (!empty($groupId)) {
             if ($group['id'] != $groupId) {
                 continue;
             }
         }
         $users = GroupManager::get_users($group['id']);
         foreach ($users as $index => $user) {
             $row = array();
             $user = api_get_user_info($user);
             $row[] = $group['name'];
             $row[] = $user['official_code'];
             $row[] = $user['lastName'];
             $row[] = $user['firstName'];
             $data[] = $row;
         }
     }
     switch ($_GET['type']) {
         case 'csv':
             Export::export_table_csv($data);
             exit;
             break;
Exemple #6
0
/**
 * @param string $courseCode
 * @param int $sessionId
 * @param int $groupId
 * @param int $start
 * @param int $limit
 * @param string $sidx
 * @param string $sord
 * @param $getCount
 * @return array|int
 */
function getWorkUserList($courseCode, $sessionId, $groupId, $start, $limit, $sidx, $sord, $getCount = false)
{
    if (!empty($groupId)) {
        $userList = GroupManager::get_users(
            $groupId,
            false,
            $start,
            $limit,
            $getCount,
            null,
            $sidx,
            $sord
        );
    } else {
        $limitString = null;
        if (!empty($start) && !empty($limit)) {
            $start = intval($start);
            $limit = intval($limit);
            $limitString = " LIMIT $start, $limit";
        }

        $orderBy = null;

        if (!empty($sidx) && !empty($sord)) {
            if (in_array($sidx, array('firstname', 'lastname'))) {
                $orderBy = "ORDER BY $sidx $sord";
            }
        }

        if (empty($sessionId)) {
            $userList = CourseManager::get_user_list_from_course_code(
                $courseCode,
                $sessionId,
                $limitString,
                $orderBy ,
                STUDENT,
                $getCount
            );
        } else {
            $userList = CourseManager::get_user_list_from_course_code(
                $courseCode,
                $sessionId,
                $limitString,
                $orderBy,
                0,
                $getCount
            );
        }

        if ($getCount == false) {
            $userList = array_keys($userList);
        }
    }
    return $userList;
}
Exemple #7
0
 /**
  *    Return user info array of all users registered in the specified real or virtual course
  *    This only returns the users that are registered in this actual course, not linked courses.
  *
  *    @param string $course_code
  *    @param boolean $full list to true if we want sessions students too
  *    @return array with user id
  */
 public static function get_student_list_from_course_code($courseId, $with_session = false, $session_id = 0, $group_id = 0)
 {
     $session_id = intval($session_id);
     $courseId = Database::escape_string($courseId);
     $students = array();
     if ($session_id == 0) {
         if (empty($group_id)) {
             // students directly subscribed to the course
             $sql = "SELECT * FROM " . Database::get_main_table(TABLE_MAIN_COURSE_USER) . "\n                       WHERE c_id = " . $courseId . " AND status = " . STUDENT;
             $rs = Database::query($sql);
             while ($student = Database::fetch_array($rs)) {
                 $students[$student['user_id']] = $student;
             }
         } else {
             $students = GroupManager::get_users($group_id, false, $courseId);
             $students = array_flip($students);
         }
     }
     // students subscribed to the course through a session
     if ($with_session) {
         $sql_query = "SELECT * FROM " . Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER) . "\n                          WHERE c_id = '{$courseId}' AND status <> 2";
         if ($session_id != 0) {
             $sql_query .= ' AND id_session = ' . $session_id;
         }
         $rs = Database::query($sql_query);
         while ($student = Database::fetch_array($rs)) {
             $students[$student['id_user']] = $student;
         }
     }
     return $students;
 }
 static function separate_users_groups_array($to, $add_group_users = false)
 {
     $grouplist = array();
     $userlist = array();
     $send_to = array();
     foreach ($to as $to_item) {
         list($type, $id) = explode(':', $to_item);
         switch ($type) {
             case 'GROUP':
                 $grouplist[] = intval($id);
                 if ($add_group_users) {
                     $users = GroupManager::get_users($id);
                     foreach ($users as $user_id) {
                         $userlist[] = $user_id;
                     }
                 }
                 break;
             case 'USER':
                 $userlist[] = intval($id);
                 break;
         }
     }
     $send_to['groups'] = $grouplist;
     $send_to['users'] = array_unique($userlist);
     return $send_to;
 }