/** * * See : fill_groups * Fill the groups with students. * * note : optimize fill_groups_list <--> fill_groups * @param array $group_ids * @return array|bool */ public static function fill_groups_list($group_ids) { $group_ids = is_array($group_ids) ? $group_ids : array($group_ids); $group_ids = array_map('intval', $group_ids); /*if (api_is_course_coach()) { for ($i = 0; $i < count($group_ids); $i++) { if (!api_is_element_in_the_session(TOOL_GROUP, $group_ids[$i])) { array_splice($group_ids, $i, 1); $i--; } } if (count($group_ids) == 0) { return false; } }*/ $_course = api_get_course_info(); $category = self::get_category_from_group($group_ids[0]); $groups_per_user = $category['groups_per_user']; $group_table = Database::get_course_table(TABLE_GROUP); $group_user_table = Database::get_course_table(TABLE_GROUP_USER); $session_id = api_get_session_id(); $complete_user_list = CourseManager::get_real_and_linked_user_list($_course['sysCode'], true, $session_id); $number_groups_per_user = $groups_per_user == self::GROUP_PER_MEMBER_NO_LIMIT ? self::INFINITE : $groups_per_user; $course_id = api_get_course_int_id(); /* * Retrieve all the groups where enrollment is still allowed * (reverse) ordered by the number of place available */ $sql = "SELECT g.id gid, count(ug.user_id) count_users, g.max_student\n FROM " . $group_table . " g\n LEFT JOIN " . $group_user_table . " ug\n ON g.id = ug.group_id\n WHERE g.c_id = {$course_id} AND\n ug.c_id = {$course_id} AND\n g.id IN (" . implode(',', $group_ids) . ")\n GROUP BY (g.id)"; $sql_result = Database::query($sql); $group_available_place = array(); while ($group = Database::fetch_array($sql_result, 'ASSOC')) { if (!empty($group['max_student'])) { $places = intval($group['max_student'] - $group['count_users']); } else { $places = self::MEMBER_PER_GROUP_NO_LIMIT; } $group_available_place[$group['gid']] = $places; } /* * Retrieve course users (reverse) ordered by the number * of group they are already enrolled */ for ($i = 0; $i < count($complete_user_list); $i++) { //find # of groups the user is enrolled in $number_of_groups = self::user_in_number_of_groups($complete_user_list[$i]["user_id"], $category['id']); //add # of groups to user list $complete_user_list[$i]['number_groups_left'] = $number_groups_per_user - $number_of_groups; } //first sort by user_id to filter out duplicates $complete_user_list = TableSort::sort_table($complete_user_list, 'user_id'); $complete_user_list = self::filter_duplicates($complete_user_list, 'user_id'); //$complete_user_list = self :: filter_only_students($complete_user_list); //now sort by # of group left $complete_user_list = TableSort::sort_table($complete_user_list, 'number_groups_left', SORT_DESC); return $complete_user_list; }
/** * this function displays the form to upload a new item to the dropbox. * * @author Patrick Cool <*****@*****.**>, Ghent University * @version march 2006 */ function display_add_form($dropbox_unid, $viewReceivedCategory, $viewSentCategory, $view) { $course_info = api_get_course_info(); $_user = api_get_user_info(); $is_courseAdmin = api_is_course_admin(); $is_courseTutor = api_is_course_tutor(); $origin = isset($_GET['origin']) ? $_GET['origin'] : null; $token = Security::get_token(); $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor); $form = new FormValidator('sent_form', 'post', api_get_self() . '?view_received_category=' . $viewReceivedCategory . '&view_sent_category=' . $viewSentCategory . '&view=' . $view . '&' . api_get_cidreq(), null, array('enctype' => 'multipart/form-data', 'onsubmit' => 'javascript: return checkForm(this);')); $form->addElement('header', get_lang('UploadNewFile')); $form->addElement('hidden', 'MAX_FILE_SIZE', dropbox_cnf('maxFilesize')); $form->addElement('hidden', 'dropbox_unid', $dropbox_unid); $form->addElement('hidden', 'sec_token', $token); $form->addElement('hidden', 'origin', $origin); $form->addElement('file', 'file', get_lang('UploadFile'), array('onChange' => 'javascript: checkfile(this.value);')); if (dropbox_cnf('allowOverwrite')) { $form->addElement('checkbox', 'cb_overwrite', null, get_lang('OverwriteFile'), array('id' => 'cb_overwrite')); } // List of all users in this course and all virtual courses combined with it if (api_get_session_id()) { $complete_user_list_for_dropbox = array(); if (api_get_setting('dropbox_allow_student_to_student') == 'true' || $_user['status'] != STUDENT) { $complete_user_list_for_dropbox = CourseManager::get_user_list_from_course_code($course_info['code'], api_get_session_id()); } $complete_user_list2 = CourseManager::get_coach_list_from_course_code($course_info['code'], api_get_session_id()); $complete_user_list_for_dropbox = array_merge($complete_user_list_for_dropbox, $complete_user_list2); } else { if (api_get_setting('dropbox_allow_student_to_student') == 'true' || $_user['status'] != STUDENT) { $complete_user_list_for_dropbox = CourseManager::get_user_list_from_course_code($course_info['code'], api_get_session_id()); } else { $complete_user_list_for_dropbox = CourseManager::get_teacher_list_from_course_code($course_info['code'], false); } } if (!empty($complete_user_list_for_dropbox)) { foreach ($complete_user_list_for_dropbox as $k => $e) { $complete_user_list_for_dropbox[$k] = $e + array('lastcommafirst' => api_get_person_name($e['firstname'], $e['lastname'])); } $complete_user_list_for_dropbox = TableSort::sort_table($complete_user_list_for_dropbox, 'lastcommafirst'); } /* Create the options inside the select box: List all selected users their user id as value and a name string as display */ $current_user_id = ''; $options = array(); foreach ($complete_user_list_for_dropbox as $current_user) { if (($dropbox_person->isCourseTutor || $dropbox_person->isCourseAdmin || dropbox_cnf('allowStudentToStudent') || $current_user['status'] != 5 || $current_user['tutor_id'] == 1) && $current_user['user_id'] != $_user['user_id']) { // Don't include yourself. if ($current_user['user_id'] == $current_user_id) { continue; } $full_name = $current_user['lastcommafirst']; $current_user_id = $current_user['user_id']; $options['user_' . $current_user_id] = $full_name; //echo '<option value="user_' . $current_user_id . '">' . $full_name . '</option>'; } } /* * Show groups */ if (($dropbox_person->isCourseTutor || $dropbox_person->isCourseAdmin) && dropbox_cnf('allowGroup') || dropbox_cnf('allowStudentToStudent')) { $complete_group_list_for_dropbox = GroupManager::get_group_list(null, dropbox_cnf('courseId')); if (count($complete_group_list_for_dropbox) > 0) { foreach ($complete_group_list_for_dropbox as $current_group) { if ($current_group['number_of_members'] > 0) { //echo '<option value="group_'.$current_group['id'].'">G: '.$current_group['name'].' - '.$current_group['number_of_members'].' '.get_lang('Users').'</option>'; $options['group_' . $current_group['id']] = 'G: ' . $current_group['name'] . ' - ' . $current_group['number_of_members'] . ' ' . get_lang('Users'); } } } } if (dropbox_cnf('allowJustUpload')) { //echo '<option value="upload">'.get_lang('JustUploadInSelect').'</option>'; //echo '<option value="user_'.$_user['user_id'].'">'.get_lang('JustUploadInSelect').'</option>'; $options['user_' . $_user['user_id']] = get_lang('JustUploadInSelect'); } $form->addElement('select', 'recipients', get_lang('SendTo'), $options, array('multiple' => 'multiple', 'size' => '10', 'class' => 'span4')); $form->addElement('button', 'submitWork', get_lang('Upload')); $form->display(); }
/** * Get table data to show on current page * @see SortableTable#get_table_data */ public function get_table_data($from = 1, $per_page = null, $column = null, $direction = null, $sort = true) { if ($sort) { $content = TableSort::sort_table($this->table_data, $this->column, $this->direction == 'ASC' ? SORT_ASC : SORT_DESC); } else { $content = $this->table_data; } return array_slice($content, $from, $this->per_page); }
/** * this function displays the form to upload a new item to the dropbox. * * @author Patrick Cool <*****@*****.**>, Ghent University * @version march 2006 */ function display_add_form($dropbox_unid, $viewReceivedCategory, $viewSentCategory, $view) { $course_info = api_get_course_info(); $_user = api_get_user_info(); $is_courseAdmin = api_is_course_admin(); $is_courseTutor = api_is_course_tutor(); $origin = isset($_GET['origin']) ? $_GET['origin'] : null; $token = Security::get_token(); $dropbox_person = new Dropbox_Person(api_get_user_id(), $is_courseAdmin, $is_courseTutor); $form = new FormValidator('sent_form', 'post', api_get_self() . '?view_received_category=' . $viewReceivedCategory . '&view_sent_category=' . $viewSentCategory . '&view=' . $view . '&' . api_get_cidreq(), null, array('enctype' => 'multipart/form-data', 'onsubmit' => 'javascript: return checkForm(this);')); $form->addElement('header', get_lang('UploadNewFile')); $form->addElement('hidden', 'MAX_FILE_SIZE', dropbox_cnf('maxFilesize')); $form->addElement('hidden', 'dropbox_unid', $dropbox_unid); $form->addElement('hidden', 'sec_token', $token); $form->addElement('hidden', 'origin', $origin); $form->addElement('file', 'file', get_lang('UploadFile'), array('onChange' => 'javascript: checkfile(this.value);')); if (dropbox_cnf('allowOverwrite')) { $form->addElement('checkbox', 'cb_overwrite', null, get_lang('OverwriteFile'), array('id' => 'cb_overwrite')); } // List of all users in this course and all virtual courses combined with it if (api_get_session_id()) { $complete_user_list_for_dropbox = array(); if (api_get_setting('dropbox.dropbox_allow_student_to_student') == 'true' || $_user['status'] != STUDENT) { $complete_user_list_for_dropbox = CourseManager::get_user_list_from_course_code($course_info['code'], api_get_session_id(), null, null, 0); } $complete_user_list2 = CourseManager::get_coach_list_from_course_code($course_info['code'], api_get_session_id()); $generalCoachList = array(); $courseCoachList = array(); foreach ($complete_user_list2 as $coach) { if ($coach['type'] == 'general_coach') { $generalCoachList[] = $coach; } else { $courseCoachList[] = $coach; } } $hideCourseCoach = api_get_setting('dropbox_hide_course_coach'); if ($hideCourseCoach == 'false') { $complete_user_list_for_dropbox = array_merge($complete_user_list_for_dropbox, $courseCoachList); } $hideGeneralCoach = api_get_setting('dropbox_hide_general_coach'); if ($hideGeneralCoach == 'false') { $complete_user_list_for_dropbox = array_merge($complete_user_list_for_dropbox, $generalCoachList); } } else { if (api_get_setting('dropbox.dropbox_allow_student_to_student') == 'true' || $_user['status'] != STUDENT) { $complete_user_list_for_dropbox = CourseManager::get_user_list_from_course_code($course_info['code'], api_get_session_id()); } else { $complete_user_list_for_dropbox = CourseManager::getTeacherListFromCourse($course_info['real_id'], false); } } if (!empty($complete_user_list_for_dropbox)) { foreach ($complete_user_list_for_dropbox as $k => $e) { $complete_user_list_for_dropbox[$k] = $e + array('lastcommafirst' => api_get_person_name($e['firstname'], $e['lastname'])); } $complete_user_list_for_dropbox = TableSort::sort_table($complete_user_list_for_dropbox, 'lastcommafirst'); } /* Create the options inside the select box: List all selected users their user id as value and a name string as display */ $current_user_id = ''; $options = array(); $userGroup = new UserGroup(); foreach ($complete_user_list_for_dropbox as $current_user) { if (($dropbox_person->isCourseTutor || $dropbox_person->isCourseAdmin || dropbox_cnf('allowStudentToStudent') || $current_user['status'] != 5 || $current_user['is_tutor'] == 1) && $current_user['user_id'] != $_user['user_id']) { // Don't include yourself. if ($current_user['user_id'] == $current_user_id) { continue; } $userId = $current_user['user_id']; $userInfo = api_get_user_info($userId); if ($userInfo['status'] != INVITEE) { $groupNameListToString = ''; if (!empty($groups)) { $groupNameList = array_column($groups, 'name'); $groupNameListToString = ' - [' . implode(', ', $groupNameList) . ']'; } $groups = $userGroup->getUserGroupListByUser($userId); $full_name = $userInfo['complete_name'] . $groupNameListToString; $current_user_id = $current_user['user_id']; $options['user_' . $current_user_id] = $full_name; } } } /* * Show groups */ if (($dropbox_person->isCourseTutor || $dropbox_person->isCourseAdmin) && dropbox_cnf('allowGroup') || dropbox_cnf('allowStudentToStudent')) { $complete_group_list_for_dropbox = GroupManager::get_group_list(null, dropbox_cnf('courseId')); if (count($complete_group_list_for_dropbox) > 0) { foreach ($complete_group_list_for_dropbox as $current_group) { if ($current_group['number_of_members'] > 0) { $options['group_' . $current_group['id']] = 'G: ' . $current_group['name'] . ' - ' . $current_group['number_of_members'] . ' ' . get_lang('Users'); } } } } if (dropbox_cnf('allowJustUpload')) { $options['user_' . $_user['user_id']] = get_lang('JustUploadInSelect'); } $form->addSelect('recipients', get_lang('SendTo'), $options, array('multiple' => 'multiple', 'size' => '10')); $form->addButtonUpload(get_lang('Upload'), 'submitWork'); $headers = array(get_lang('Upload'), get_lang('Upload') . ' (' . get_lang('Simple') . ')'); $multipleForm = new FormValidator('sent_multiple', 'post', '#', null, array('enctype' => 'multipart/form-data', 'id' => 'fileupload')); $multipleForm->addSelect('recipients', get_lang('SendTo'), $options, array('multiple' => 'multiple', 'size' => '10', 'id' => 'recipient_form')); $url = api_get_path(WEB_AJAX_PATH) . 'dropbox.ajax.php?' . api_get_cidreq() . '&a=upload_file&id='; $multipleForm->addHtml('<div id="multiple_form" style="display:none">'); $multipleForm->addMultipleUpload($url); $multipleForm->addHtml('</div>'); echo Display::tabs($headers, array($multipleForm->returnForm(), $form->returnForm()), 'tabs'); }