3 * Print an overview of groupings & group membership
5 * @author Matt Clarkson mattc@catalyst.net.nz
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
11 require_once('../config.php');
13 $courseid = required_param('id', PARAM_INT
);
14 $groupid = optional_param('group', 0, PARAM_INT
);
15 $groupingid = optional_param('grouping', 0, PARAM_INT
);
17 $returnurl = $CFG->wwwroot
.'/group/index.php?id='.$courseid;
18 $rooturl = $CFG->wwwroot
.'/group/overview.php?id='.$courseid;
20 if (!$course = get_record('course', 'id',$courseid)) {
21 error('invalidcourse');
24 // Make sure that the user has permissions to manage groups.
25 require_login($course);
27 $context = get_context_instance(CONTEXT_COURSE
, $courseid);
28 require_capability('moodle/course:managegroups', $context);
30 $strgroups = get_string('groups');
31 $strparticipants = get_string('participants');
32 $stroverview = get_string('overview', 'group');
33 $strgrouping = get_string('grouping', 'group');
34 $strgroup = get_string('group', 'group');
35 $strnotingrouping = get_string('notingrouping', 'group');
36 $strfiltergroups = get_string('filtergroups', 'group');
37 $strnogroups = get_string('nogroups', 'group');
38 $strdescription = get_string('description');
41 if (empty($CFG->enablegroupings
)) {
43 $members = array(-1 => array()); //groups not in a grouping
46 if (!$groupings = get_records('groupings', 'courseid', $courseid, 'name')) {
50 foreach ($groupings as $grouping) {
51 $members[$grouping->id
] = array();
53 $members[-1] = array(); //groups not in a grouping
57 if (!$groups = get_records('groups', 'courseid', $courseid, 'name')) {
61 if (empty($CFG->enablegroupings
)) {
62 $groupwhere = $groupid ?
"AND g.id = $groupid" : "";
63 $sql = "SELECT g.id AS groupid, NULL AS groupingid, u.id AS userid, u.firstname, u.lastname, u.idnumber, u.username
64 FROM {$CFG->prefix}groups g
65 LEFT JOIN {$CFG->prefix}groups_members gm ON g.id = gm.groupid
66 LEFT JOIN {$CFG->prefix}user u ON gm.userid = u.id
67 WHERE g.courseid = {$course->id} $groupwhere
68 ORDER BY g.name, u.lastname, u.firstname";
70 $groupingwhere = $groupingid ?
"AND gg.groupingid = $groupingid" : "";
71 $groupwhere = $groupid ?
"AND g.id = $groupid" : "";
72 $sql = "SELECT g.id AS groupid, gg.groupingid, u.id AS userid, u.firstname, u.lastname, u.idnumber, u.username
73 FROM {$CFG->prefix}groups g
74 LEFT JOIN {$CFG->prefix}groupings_groups gg ON g.id = gg.groupid
75 LEFT JOIN {$CFG->prefix}groups_members gm ON g.id = gm.groupid
76 LEFT JOIN {$CFG->prefix}user u ON gm.userid = u.id
77 WHERE g.courseid = {$course->id} $groupingwhere $groupwhere
78 ORDER BY g.name, u.lastname, u.firstname";
81 if ($rs = get_recordset_sql($sql)) {
82 while ($row = rs_fetch_next_record($rs)) {
84 $user->id
= $row->userid
;
85 $user->firstname
= $row->firstname
;
86 $user->lastname
= $row->lastname
;
87 $user->username
= $row->username
;
88 $user->idnumber
= $row->idnumber
;
89 if (!$row->groupingid
) {
90 $row->groupingid
= -1;
92 if (!array_key_exists($row->groupid
, $members[$row->groupingid
])) {
93 $members[$row->groupingid
][$row->groupid
] = array();
95 $members[$row->groupingid
][$row->groupid
][] = $user;
101 // Print the page and form
102 $navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot
.'/user/index.php?id='.$courseid, 'type'=>'misc'),
103 array('name'=>$strgroups, 'link'=>'', 'type'=>'misc'));
104 $navigation = build_navigation($navlinks);
107 print_header_simple($strgroups, ': '.$strgroups, $navigation, '', '', true, '', navmenu($course));
109 $currenttab = 'overview';
113 print_heading(format_string($course->shortname
) .' '.$stroverview, 'center', 3);
115 echo $strfiltergroups;
117 if (!empty($CFG->enablegroupings
)) {
119 $options[0] = get_string('all');
120 foreach ($groupings as $grouping) {
121 $options[$grouping->id
] = strip_tags(format_string($grouping->name
));
123 popup_form($rooturl.'&group='.$groupid.'&grouping=', $options, 'selectgrouping', $groupingid, '', '', '', false, 'self', $strgrouping);
127 $options[0] = get_string('all');
128 foreach ($groups as $group) {
129 $options[$group->id
] = strip_tags(format_string($group->name
));
131 popup_form($rooturl.'&grouping='.$groupingid.'&group=', $options, 'selectgroup', $groupid, '', '', '', false, 'self', $strgroup);
136 foreach ($members as $gpgid=>$groupdata) {
137 if ($groupingid and $groupingid != $gpgid) {
138 continue; // do not show
140 $table = new object();
141 $table->head
= array(get_string('groupscount', 'group', count($groupdata)), get_string('groupmembers', 'group'), get_string('usercount', 'group'));
142 $table->size
= array('20%', '70%', '10%');
143 $table->align
= array('left', 'left', 'center');
144 $table->width
= '90%';
145 $table->data
= array();
146 foreach ($groupdata as $gpid=>$users) {
147 if ($groupid and $groupid != $gpid) {
151 $name = format_string($groups[$gpid]->name
);
152 $jsdescription = addslashes_js(trim(format_text($groups[$gpid]->description
)));
153 if (empty($jsdescription)) {
156 $jsstrdescription = addslashes_js($strdescription);
157 $overlib = "return overlib('$jsdescription', BORDER, 0, FGCLASS, 'description', "
158 ."CAPTIONFONTCLASS, 'caption', CAPTION, '$jsstrdescription');";
159 $line[] = '<span onmouseover="'.s($overlib).'" onmouseout="return nd();">'.$name.'</span>';
161 $fullnames = array();
162 foreach ($users as $user) {
163 $fullnames[] = '<a href="'.$CFG->wwwroot
.'/user/view.php?id='.$user->id
.'&course='.$course->id
.'">'.fullname($user, true).'</a>';
165 $line[] = implode(', ', $fullnames);
166 $line[] = count($users);
167 $table->data
[] = $line;
169 if ($groupid and empty($table->data
)) {
172 if (!empty($CFG->enablegroupings
)) {
174 print_heading($strnotingrouping, '', 3);
176 print_heading(format_string($groupings[$gpgid]->name
), '', 3);
177 print_box(format_text($groupings[$gpgid]->description
), 'generalbox boxwidthnarrow boxaligncenter');
180 print_table($table, false);
184 print_footer($course);