2007-08-15 20:21:01 +00:00
|
|
|
<?php //$Id$
|
|
|
|
|
|
|
|
// folowing files will be removed soon
|
|
|
|
require_once($CFG->dirroot.'/group/lib/basicgrouplib.php');
|
|
|
|
require_once($CFG->dirroot.'/group/lib/utillib.php');
|
|
|
|
require_once($CFG->dirroot.'/group/lib/legacylib.php');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the groupid of a group with the name specified for the course.
|
|
|
|
* Group names should be unique in course
|
|
|
|
* @param int $courseid The id of the course
|
|
|
|
* @param string $name name of group (without magic quotes)
|
|
|
|
* @return int $groupid
|
|
|
|
*/
|
|
|
|
function groups_get_group_by_name($courseid, $name) {
|
2007-08-15 23:51:07 +00:00
|
|
|
if ($groups = get_records_select('groups', "courseid=$courseid AND name='".addslashes($name)."'")) {
|
|
|
|
return key($groups);
|
2007-08-15 20:21:01 +00:00
|
|
|
}
|
2007-08-15 23:51:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-08-15 20:21:01 +00:00
|
|
|
|
2007-08-15 23:51:07 +00:00
|
|
|
/**
|
|
|
|
* Returns the groupingid of a grouping with the name specified for the course.
|
|
|
|
* Grouping names should be unique in course
|
|
|
|
* @param int $courseid The id of the course
|
|
|
|
* @param string $name name of group (without magic quotes)
|
|
|
|
* @return int $groupid
|
|
|
|
*/
|
|
|
|
function groups_get_grouping_by_name($courseid, $name) {
|
|
|
|
if ($groupings = get_records_select('groupings', "courseid=$courseid AND name='".addslashes($name)."'")) {
|
|
|
|
return key($groupings);
|
|
|
|
}
|
|
|
|
return false;
|
2007-08-15 20:21:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the group object
|
|
|
|
* @param groupid ID of the group.
|
|
|
|
* @return group object
|
|
|
|
*/
|
|
|
|
function groups_get_group($groupid) {
|
|
|
|
return get_record('groups', 'id', $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.
|
|
|
|
* @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) {
|
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
if (empty($userdi)) {
|
|
|
|
return get_records('groups', 'courseid', $courseid, 'name ASC');
|
|
|
|
|
|
|
|
} 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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if the user is a member of the given group.
|
|
|
|
*
|
|
|
|
* @uses $USER If $userid is null, use the global object.
|
|
|
|
* @param int $groupid The group to check for membership.
|
|
|
|
* @param int $userid The user to check against the group.
|
|
|
|
* @return boolean True if the user is a member, false otherwise.
|
|
|
|
*/
|
|
|
|
function groups_is_member($groupid, $userid=null) {
|
|
|
|
global $USER;
|
|
|
|
|
|
|
|
if (!$userid) {
|
|
|
|
$userid = $USER->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return record_exists('groups_members', 'groupid', $groupid, 'userid', $userid);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|