function groups_groupingids_to_groupings($groupingids) { if (!$groupingids) { return false; } $groupings = array(); foreach ($groupingids as $id) { $groupings[] = groups_get_grouping_settings($id); } return $groupings; }
/** * Gets the name of a grouping with a specified ID * @param int $groupid The grouping ID. * @return string The name of the grouping. */ function groups_get_grouping_name($groupingid) { if (GROUP_NOT_IN_GROUPING == $groupingid) { return get_string('notingrouping', 'group'); } elseif (GROUP_ANY_GROUPING == $groupingid) { return get_string('anygrouping', 'group'); } $settings = groups_get_grouping_settings($groupingid); if ($settings && isset($settings->name)) { return $settings->name; } return false; }
/** * 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; }