course) || !groupmode($cm->course, $cm)) { return false; } elseif (GROUP_ANY_GROUPING == $groupingid) { return groups_get_groups_for_user($userid, $cm->course); } return groups_get_groups_for_user_in_grouping($userid, $groupingid); } /** * Get the ID of the first group for the global $USER in the course module. * Replaces legacylib function 'mygroupid'. * @uses $USER * @param $cm A course module object. * @return int A single group ID for this user. */ function groups_m_get_my_group($cm) { global $USER; $groupids = groups_m_get_groups_for_user($cm, $USER->id); if (!$groupids || count($groupids) == 0) { return 0; } return array_shift($groupids); } /** * Indicates if a specified user has a particular type of permission for a * particular group for this module instance. * @uses $USER * @param int $cmid The id of the module instance. This is necessary because the * same group can be used in different module instances with different * permission setups. * @param int $groupid The id of the group * @param int $permissiontype The permission type - see note on permission types * above * @userid int $userid The id of the user, defaults to the current user * @return boolean True if the user has the specified permission type, false * otherwise or if an error occurred. */ function groups_m_has_permission($cm, $groupid, $permissiontype, $userid = null) { if (!$userid) { global $USER; $userid = $USER->id; } $groupingid = groups_get_grouping_for_coursemodule($cm); if (!$groupingid || !is_object($cm) || !isset($cm->course)) { return false; } $courseid = $cm->course; $isstudent = isstudent($courseid, $userid); $isteacher = isteacher($courseid, $userid); $groupmember = groups_is_member($groupid, $userid); $memberofsomegroup = groups_is_member_of_some_group_in_grouping($userid, $groupingid); $groupingsettings = groups_get_grouping_settings($groupingid); $viewowngroup = $groupingsettings->viewowngroup; $viewallgroupsmembers = $groupingsettings->viewallgroupmembers; $viewallgroupsactivities = $groupingsettings->viewallgroupsactivities; $teachersgroupsmark = $groupingsettings->teachersgroupsmark; $teachersgroupsview = $groupingsettings->teachersgroupsview; $teachersgroupmark = $groupingsettings->teachersgroupmark; $teachersgroupview = $groupingsettings->teachersgroupview; $teachersoverride = $groupingsettings->teachersoverride; $permission = false; switch ($permissiontype) { case 'view': if (($isstudent and $groupmember) or ($isteacher and $groupmember) or ($isstudent and $viewallgroupsactivities) or ($isteacher and !$teachersgroupview) or ($isteacher and !$memberofsomegroup and $teachersoverride)) { $permission = true; } break; case 'studentcontribute': if (($isstudent and $groupmember) or ($isteacher and $groupmember) or ($isteacher and !$memberofsomegroup and $teachersoverride)) { $permission = true; } break; case 'teachermark': if (($isteacher and $groupmember) or ($isteacher and !$teachersgroupmark) or ($isteacher and !$memberofsomegroup and $teachersoverride)) { $permission = true; } break; case 'viewmembers': if (($isstudent and $groupmember and $viewowngroup) or ($isstudent and $viewallgroupsmembers) or ($isteacher and $groupmember) or ($isteacher and !$teachersgroupview) or ($isteacher and !$memberofsomegroup and $teachersoverride) or $isteacheredit) { $permission = true; } break; } return $permission; } /** * Gets an array of members of a group that have a particular permission type * for this instance of the module and that are enrolled on the course that * the module instance belongs to. * * @param int $cmid The id of the module instance. This is necessary because the * same group can be used in different module instances with different * permission setups. * @param int $groupid The id of the group * @param int $permissiontype The permission type - see note on permission types * above * @return array An array containing the ids of the users with the specified * permission. */ function groups_m_get_members_with_permission($cmid, $groupid, $permissiontype) { // Get all the users as $userid $validuserids = array(); foreach($validuserids as $userid) { $haspermission = groups_m_has_permission($cmid, $groupid, $permissiontype, $userid); if ($haspermission) { array_push($validuserids, $userid); } } return $validuserids; } /** * Gets the group object associated with a group id. This group object can be * used to get information such as the name of the group and the file for the * group icon if it exists. (Look at the groups table in the database to see * the fields). * @param int $groupid The id of the group * @return group The group object */ function groups_m_get_group($groupid) { return groups_db_m_get_group($groupid); } /** * Gets the groups for the module instance. In general, you should use * groups_m_get_groups_for_user, however this function is provided for * circumstances where this function isn't sufficient for some reason. * @param int $cmid The id of the module instance. * @return array An array of the ids of the groups for the module instance */ function groups_m_get_groups($cmid) { $groupingid = groups_db_get_groupingid($cmid); $groupids = groups_get_groups_in_grouping($groupingid); return $groupids; } /** * Gets the members of group that are enrolled on the course that the specified * module instance belongs to. * @param int $cmid The id of the module instance * @param int $groupid The id of the group * @return array An array of the userids of the members. */ function groups_m_get_members($cmid, $groupid) { $userids = groups_get_members($groupid, $membertype); if (!$userids) { $memberids = false; } else { // Check if each user is enrolled on the course @@@ TO DO } return $memberids; } ?>