📄 groupmanager.lib.php
字号:
} /** * Unsubscribe all tutors from one or more groups * @param mixed $group_id Can be an array with group-id's or a single group-id * @see unsubscribe_all_users. This function is almost an exact copy of that function. * @return bool TRUE if successfull * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University */ function unsubscribe_all_tutors($group_ids) { $group_ids = is_array($group_ids) ? $group_ids : array ($group_ids); if( count($group_ids) > 0) { $table_group_tutor = Database :: get_course_table(TABLE_GROUP_TUTOR); $sql = 'DELETE FROM '.$table_group_tutor.' WHERE group_id IN ('.implode(',', $group_ids).')'; $result = api_sql_query($sql,__FILE__,__LINE__); return $result; } return true; } /** * Is the user a tutor of this group? * @param $user_id the id of the user * @param $group_id the id of the group * @return boolean true/false * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University */ function is_tutor_of_group($user_id,$group_id) { global $_course; $table_group_tutor = Database :: get_course_table(TABLE_GROUP_TUTOR); $sql = "SELECT * FROM ".$table_group_tutor." WHERE user_id='".$user_id."' AND group_id='".$group_id."'"; $result = api_sql_query($sql,__FILE__,__LINE__); if (mysql_num_rows($result)>0) { return true; } else { return false; } } /** * Is the user part of this group? This can be a tutor or a normal member * you should use this function if the access to a tool or functionality is restricted to the people who are actually in the group * before you had to check if the user was 1. a member of the group OR 2. a tutor of the group. This function combines both * @param $user_id the id of the user * @param $group_id the id of the group * @return boolean true/false * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University */ function is_user_in_group($user_id, $group_id) { $member = GroupManager :: is_subscribed($user_id,$group_id); $tutor = GroupManager :: is_tutor_of_group($user_id,$group_id); if ($member OR $tutor) { return true; } else { return false; } } /** * Get all tutors for the current course. * @return array An array with firstname, lastname and user_id for all * tutors in the current course. * @deprecated this function uses the old tutor implementation */ function get_all_tutors() { global $_course; $course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); $user_table = Database :: get_main_table(TABLE_MAIN_USER); $sql = "SELECT user.user_id AS user_id, user.lastname AS lastname, user.firstname AS firstname FROM ".$user_table." user, ".$course_user_table." cu WHERE cu.user_id=user.user_id AND cu.tutor_id='1' AND cu.course_code='".$_course['sysCode']."'"; $resultTutor = api_sql_query($sql,__FILE__,__LINE__); $tutors = array (); while ($tutor = mysql_fetch_array($resultTutor)) { $tutors[] = $tutor; } return $tutors; } /** * Is user a tutor in current course * @param int $user_id * @return bool TRUE if given user is a tutor in the current course. * @deprecated this function uses the old tutor implementation */ function is_tutor($user_id) { global $_course; $course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); $sql = "SELECT tutor_id FROM ".$course_user_table." WHERE `user_id`='".$user_id."' AND `course_code`='".$_course['sysCode']."'"."AND tutor_id=1"; $db_result = api_sql_query($sql,__FILE__,__LINE__); $result = (mysql_num_rows($db_result) > 0); return $result; } /** * Get all group's from a given course in which a given user is ubscribed * @author Patrick Cool * @param string $course_db: the database of the course you want to * retrieve the groups for * @param integer $user_id: the ID of the user you want to know all its * group memberships */ function get_group_ids($course_db,$user_id) { $groups = array(); $tbl_group = Database::get_course_table(TABLE_GROUP_USER,$course_db); $sql = "SELECT group_id FROM $tbl_group WHERE user_id = '$user_id'"; $groupres = api_sql_query($sql); // uncommenting causes a bug in Agenda AND announcements because there we check if the return value of this function is an array or not //$groups=array(); if($groupres) { while ($myrow= mysql_fetch_array($groupres)) $groups[]=$myrow['group_id']; } return $groups; } /* ----------------------------------------------------------- Group functions these take virtual/linked courses into account when necessary ----------------------------------------------------------- */ /** * Get a combined list of all users of the real course $course_code * and all users in virtual courses linked to this course $course_code * Filter user list: remove duplicate users; plus * remove users that * - are already in the current group $group_id; * - do not have student status in these courses; * - are not appointed as tutor (group assistent) for this group; * - have already reached their maximum # of groups in this course. * * Originally to get the correct list of users a big SQL statement was used, * but this has become more complicated now there is not just one real course but many virtual courses. * Still, that could have worked as well. * * @version 1.1.3 * @author Roan Embrechts */ function get_complete_list_of_users_that_can_be_added_to_group($course_code, $group_id) { global $_course, $_user; $category = GroupManager :: get_category_from_group($group_id, $course_code); $number_of_groups_limit = $category['groups_per_user'] == GROUP_PER_MEMBER_NO_LIMIT ? INFINITE : $category['groups_per_user']; $real_course_code = $_course['sysCode']; $real_course_info = Database :: get_course_info($real_course_code); $real_course_user_list = CourseManager :: get_user_list_from_course_code($virtual_course_code); //get list of all virtual courses $user_subscribed_course_list = CourseManager :: get_list_of_virtual_courses_for_specific_user_and_real_course($_user['user_id'], $real_course_code); //add real course to the list $user_subscribed_course_list[] = $real_course_info; if (!is_array($user_subscribed_course_list)) return; //for all courses... foreach ($user_subscribed_course_list as $this_course) { $this_course_code = $this_course["code"]; $course_user_list = CourseManager :: get_user_list_from_course_code($this_course_code); //for all users in the course foreach ($course_user_list as $this_user) { $user_id = $this_user["user_id"]; $loginname = $this_user["username"]; $lastname = $this_user["lastname"]; $firstname = $this_user["firstname"]; $status = $this_user["status"]; //$role = $this_user["role"]; $tutor_id = $this_user["tutor_id"]; $full_name = $lastname.", ".$firstname; if ($lastname == "" || $firstname == '') $full_name = $loginname; $complete_user["user_id"] = $user_id; $complete_user["full_name"] = $full_name; $complete_user['firstname'] = $firstname; $complete_user['lastname'] = $lastname; $complete_user["status"] = $status; $complete_user["tutor_id"] = $tutor_id; $student_number_of_groups = GroupManager :: user_in_number_of_groups($user_id, $category['id']); //filter: only add users that have not exceeded their maximum amount of groups if ($student_number_of_groups < $number_of_groups_limit) { $complete_user_list[] = $complete_user; } } } if (is_array($complete_user_list)) { //sort once, on array field "full_name" $complete_user_list = TableSort :: sort_table($complete_user_list, "full_name"); //filter out duplicates, based on field "user_id" $complete_user_list = GroupManager :: filter_duplicates($complete_user_list, "user_id"); $complete_user_list = GroupManager :: filter_users_already_in_group($complete_user_list, $group_id); //$complete_user_list = GroupManager :: filter_only_students($complete_user_list); } return $complete_user_list; } /** * Filter out duplicates in a multidimensional array * by comparing field $compare_field. * * @param $user_array_in list of users (must be sorted). * @param string $compare_field, the field to be compared */ function filter_duplicates($user_array_in, $compare_field) { $total_number = count($user_array_in); $user_array_out[0] = $user_array_in[0]; $count_out = 0; for ($count_in = 1; $count_in < $total_number; $count_in ++) { if ($user_array_in[$count_in][$compare_field] != $user_array_out[$count_out][$compare_field]) { $count_out ++; $user_array_out[$count_out] = $user_array_in[$count_in]; } } return $user_array_out; } /** * Filters from the array $user_array_in the users already in the group $group_id. */ function filter_users_already_in_group($user_array_in, $group_id) { foreach ($user_array_in as $this_user) { if (!GroupManager :: is_subscribed($this_user['user_id'], $group_id)) { $user_array_out[] = $this_user; } } return $user_array_out; } /** * Remove all users that are not students and all users who have tutor status * from the list. */ function filter_only_students($user_array_in) { $user_array_out = array (); foreach ($user_array_in as $this_user) { if ($this_user['status'] == STUDENT && $this_user['tutor_id'] == 0) { $user_array_out[] = $this_user; } } return $user_array_out; } /** * Check if a user has access to a certain group tool * @param int $user_id The user id * @param int $group_id The group id * @param constant $tool The tool to check the access rights. This should be * one of constants: GROUP_TOOL_DOCUMENTS * @return bool True if the given user has access to the given tool in the * given course. */ function user_has_access($user_id, $group_id, $tool) { switch ($tool) { case GROUP_TOOL_DOCUMENTS : $state_key = 'doc_state'; break; case GROUP_TOOL_CALENDAR : $state_key = 'calendar_state'; break; case GROUP_TOOL_ANNOUNCEMENT : $state_key = 'announcements_state'; break; case GROUP_TOOL_WORK : $state_key = 'work_state'; break; default: return false; } $group = GroupManager :: get_group_properties($group_id); if ($group[$state_key] == TOOL_NOT_AVAILABLE) { return false; } elseif ($group[$state_key] == TOOL_PUBLIC) { return true; } elseif (api_is_allowed_to_edit()) { return true; } elseif($group['tutor_id'] == $user_id) { return true; } else { return GroupManager :: is_subscribed($user_id, $group_id); } } /** * Get all groups where a specific user is subscribed */ function get_user_group_name($user_id){ $table_group_user=Database::get_course_table(TABLE_GROUP_USER); $table_group=Database::get_course_table(TABLE_GROUP); $sql_groups = 'SELECT name FROM '.$table_group.' g,'.$table_group_user.' gu WHERE gu.user_id="'.$user_id.'" AND gu.group_id=g.id'; $res = api_sql_query($sql_groups,__FILE__,__LINE__); $groups=array(); while($group = mysql_fetch_array($res)) { $groups[] .= $group['name']; } return $groups; }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -