2c386f82 |
1 | <?php //$Id$ |
2 | |
3 | // folowing files will be removed soon |
4 | require_once($CFG->dirroot.'/group/lib/basicgrouplib.php'); |
2c386f82 |
5 | require_once($CFG->dirroot.'/group/lib/utillib.php'); |
6 | require_once($CFG->dirroot.'/group/lib/legacylib.php'); |
7 | |
8 | /** |
9 | * Returns the groupid of a group with the name specified for the course. |
10 | * Group names should be unique in course |
11 | * @param int $courseid The id of the course |
12 | * @param string $name name of group (without magic quotes) |
13 | * @return int $groupid |
14 | */ |
15 | function groups_get_group_by_name($courseid, $name) { |
ddff2fa8 |
16 | if ($groups = get_records_select('groups', "courseid=$courseid AND name='".addslashes($name)."'")) { |
17 | return key($groups); |
2c386f82 |
18 | } |
ddff2fa8 |
19 | return false; |
20 | } |
2c386f82 |
21 | |
ddff2fa8 |
22 | /** |
23 | * Returns the groupingid of a grouping with the name specified for the course. |
24 | * Grouping names should be unique in course |
25 | * @param int $courseid The id of the course |
26 | * @param string $name name of group (without magic quotes) |
27 | * @return int $groupid |
28 | */ |
29 | function groups_get_grouping_by_name($courseid, $name) { |
30 | if ($groupings = get_records_select('groupings', "courseid=$courseid AND name='".addslashes($name)."'")) { |
31 | return key($groupings); |
32 | } |
33 | return false; |
2c386f82 |
34 | } |
35 | |
36 | /** |
37 | * Get the group object |
38 | * @param groupid ID of the group. |
39 | * @return group object |
40 | */ |
41 | function groups_get_group($groupid) { |
42 | return get_record('groups', 'id', $groupid); |
43 | } |
44 | |
45 | /** |
46 | * Gets array of all groups in a specified course. |
47 | * @param int $courseid The id of the course. |
48 | * @param int $userid optional user id, returns only groups of the user. |
49 | * @return array | false Returns an array of the group IDs or false if no records |
50 | * or an error occurred. |
51 | */ |
52 | function groups_get_all_groups($courseid, $userid=0) { |
53 | global $CFG; |
54 | |
55 | if (empty($userdi)) { |
56 | return get_records('groups', 'courseid', $courseid, 'name ASC'); |
57 | |
58 | } else { |
59 | return get_records_sql("SELECT g.* |
60 | FROM {$CFG->prefix}groups g, |
61 | {$CFG->prefix}groups_members m |
62 | WHERE g.courseid = '$courseid' |
63 | AND g.id = m.groupid |
64 | AND m.userid = '$userid' |
65 | ORDER BY name ASC"); |
66 | } |
67 | } |
68 | |
69 | /** |
70 | * Determines if the user is a member of the given group. |
71 | * |
72 | * @uses $USER If $userid is null, use the global object. |
73 | * @param int $groupid The group to check for membership. |
74 | * @param int $userid The user to check against the group. |
75 | * @return boolean True if the user is a member, false otherwise. |
76 | */ |
77 | function groups_is_member($groupid, $userid=null) { |
78 | global $USER; |
79 | |
80 | if (!$userid) { |
81 | $userid = $USER->id; |
82 | } |
83 | |
84 | return record_exists('groups_members', 'groupid', $groupid, 'userid', $userid); |
85 | } |
86 | |
87 | |
88 | ?> |