MDL-10383 - groups/groupings refactoring and improvements - basic UI for groupings implemented

This commit is contained in:
skodak 2007-08-16 09:28:18 +00:00
parent baea72ec48
commit 62d6383803
12 changed files with 454 additions and 196 deletions

View file

@ -46,24 +46,33 @@ function groups_get_group($groupid) {
* Gets array of all groups in a specified course.
* @param int $courseid The id of the course.
* @param int $userid optional user id, returns only groups of the user.
* @param int $groupingid optional returns only groups in the specified grouping.
* @return array | false Returns an array of the group IDs or false if no records
* or an error occurred.
*/
function groups_get_all_groups($courseid, $userid=0) {
function groups_get_all_groups($courseid, $userid=0, $groupingid=0) {
global $CFG;
if (empty($userdi)) {
return get_records('groups', 'courseid', $courseid, 'name ASC');
if (!empty($userid)) {
$userfrom = ", {$CFG->prefix}groups_members gm";
$userwhere = "AND g.id = gm.groupid AND gm.userid = '$userid'";
} else {
return get_records_sql("SELECT g.*
FROM {$CFG->prefix}groups g,
{$CFG->prefix}groups_members m
WHERE g.courseid = '$courseid'
AND g.id = m.groupid
AND m.userid = '$userid'
ORDER BY name ASC");
$userfrom = "";
$userwhere = "";
}
if (!empty($groupingid)) {
$groupingfrom = ", {$CFG->prefix}groupings_groups gg";
$groupingwhere = "AND g.id = gg.groupid AND gg.groupingid = '$groupingid'";
} else {
$groupingfrom = "";
$groupingwhere = "";
}
return get_records_sql("SELECT g.*
FROM {$CFG->prefix}groups g $userfrom $groupingfrom
WHERE g.courseid = '$courseid' $userwhere $groupingwhere
ORDER BY name ASC");
}
/**
@ -84,5 +93,22 @@ function groups_is_member($groupid, $userid=null) {
return record_exists('groups_members', 'groupid', $groupid, 'userid', $userid);
}
/**
* Returns the users in the specified group.
* @param int $groupid The groupid to get the users for
* @param int $sort optional sorting of returned users
* @return array | false Returns an array of the users for the specified
* group or false if no users or an error returned.
*/
function groups_get_members($groupid, $sort='lastname ASC') {
global $CFG;
return get_records_sql("SELECT u.*
FROM {$CFG->prefix}user u, {$CFG->prefix}groups_members gm
WHERE u.id = gm.userid AND gm.groupid = '$groupid'
ORDER BY $sort");
}
?>