mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
Work done on group functions
This commit is contained in:
parent
ddc7afad9a
commit
0d67c51458
@ -876,6 +876,7 @@ function remove_course_contents($courseid, $showfeedback=true) {
|
||||
|
||||
|
||||
/// GROUPS /////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* Returns a boolean: is the user a member of the given group?
|
||||
@ -886,12 +887,35 @@ function ismember($groupid, $userid=0) {
|
||||
global $USER;
|
||||
|
||||
if (!$userid) {
|
||||
return !empty($USER->groupmember[$groupid]);
|
||||
if (empty($USER->groupmember)) {
|
||||
return false;
|
||||
}
|
||||
foreach ($USER->groupmember as $courseid => $mgroupid) {
|
||||
if ($mgroupid == $groupid) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return record_exists("groups_members", "groupid", $groupid, "userid", $userid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the group ID of the current user in the given course
|
||||
*
|
||||
* @param type description
|
||||
*/
|
||||
function mygroupid($courseid) {
|
||||
global $USER;
|
||||
|
||||
if (empty($USER->groupmember[$courseid])) {
|
||||
return 0;
|
||||
} else {
|
||||
return $USER->groupmember[$courseid];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For a given course, and possibly course module, determine
|
||||
* what the current default groupmode is:
|
||||
@ -943,6 +967,39 @@ function get_current_group($courseid, $full=false) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A combination function to make it easier for modules
|
||||
* to set up groups.
|
||||
*
|
||||
* It will use a given "groupid" parameter and try to use
|
||||
* that to reset the current group for the user.
|
||||
*
|
||||
* @param type description
|
||||
*/
|
||||
function get_and_set_current_group($course, $groupmode, $groupid=0) {
|
||||
|
||||
if (!$groupmode) { // Groups don't even apply
|
||||
return false;
|
||||
}
|
||||
|
||||
$currentgroupid = get_current_group($course->id);
|
||||
|
||||
if ($groupid) { // Try to change the current group
|
||||
if ($group = get_record('groups', 'id', $groupid, 'courseid', $course->id)) { // Exists
|
||||
if (isteacheredit($course->id)) { // Sets current default group
|
||||
$currentgroupid = set_current_group($course->id, $group->id);
|
||||
|
||||
} else if ($groupmode == VISIBLEGROUPS) { // All groups are visible
|
||||
$currentgroupid = $group->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $currentgroupid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// CORRESPONDENCE ////////////////////////////////////////////////
|
||||
|
Loading…
x
Reference in New Issue
Block a user