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');
12 require_once($CFG->libdir
. '/filelib.php');
14 $courseid = required_param('id', PARAM_INT
);
15 $groupid = optional_param('group', 0, PARAM_INT
);
16 $groupingid = optional_param('grouping', 0, PARAM_INT
);
18 $returnurl = $CFG->wwwroot
.'/group/index.php?id='.$courseid;
19 $rooturl = $CFG->wwwroot
.'/group/overview.php?id='.$courseid;
21 if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
22 print_error('invalidcourse');
25 $url = new moodle_url('/group/overview.php', array('id'=>$courseid));
27 $url->param('group', $groupid);
29 if ($groupingid !== 0) {
30 $url->param('grouping', $groupingid);
34 // Make sure that the user has permissions to manage groups.
35 require_login($course);
37 $context = get_context_instance(CONTEXT_COURSE
, $courseid);
38 require_capability('moodle/course:managegroups', $context);
40 $strgroups = get_string('groups');
41 $strparticipants = get_string('participants');
42 $stroverview = get_string('overview', 'group');
43 $strgrouping = get_string('grouping', 'group');
44 $strgroup = get_string('group', 'group');
45 $strnotingrouping = get_string('notingrouping', 'group');
46 $strfiltergroups = get_string('filtergroups', 'group');
47 $strnogroups = get_string('nogroups', 'group');
48 $strdescription = get_string('description');
51 $groupings = $DB->get_records('groupings', array('courseid'=>$courseid), 'name');
53 foreach ($groupings as $grouping) {
54 $members[$grouping->id
] = array();
56 $members[-1] = array(); //groups not in a grouping
59 $groups = $DB->get_records('groups', array('courseid'=>$courseid), 'name');
61 $params = array('courseid'=>$courseid);
63 $groupwhere = "AND g.id = :groupid";
64 $params['groupid'] = $groupid;
70 $groupingwhere = "AND gg.groupingid = :groupingid";
71 $params['groupingid'] = $groupingid;
75 $sql = "SELECT g.id AS groupid, gg.groupingid, u.id AS userid, u.firstname, u.lastname, u.idnumber, u.username
77 LEFT JOIN {groupings_groups} gg ON g.id = gg.groupid
78 LEFT JOIN {groups_members} gm ON g.id = gm.groupid
79 LEFT JOIN {user} u ON gm.userid = u.id
80 WHERE g.courseid = :courseid $groupwhere $groupingwhere
81 ORDER BY g.name, u.lastname, u.firstname";
83 $rs = $DB->get_recordset_sql($sql, $params);
84 foreach ($rs as $row) {
85 $user = new stdClass();
86 $user->id
= $row->userid
;
87 $user->firstname
= $row->firstname
;
88 $user->lastname
= $row->lastname
;
89 $user->username
= $row->username
;
90 $user->idnumber
= $row->idnumber
;
91 if (!$row->groupingid
) {
92 $row->groupingid
= -1;
94 if (!array_key_exists($row->groupid
, $members[$row->groupingid
])) {
95 $members[$row->groupingid
][$row->groupid
] = array();
98 $members[$row->groupingid
][$row->groupid
][] = $user;
103 navigation_node
::override_active_url(new moodle_url('/group/index.php', array('id'=>$courseid)));
104 $PAGE->navbar
->add(get_string('overview', 'group'));
107 $PAGE->set_title($strgroups);
108 $PAGE->set_heading($course->fullname
);
109 $PAGE->set_pagelayout('standard');
110 echo $OUTPUT->header();
113 $currenttab = 'overview';
117 echo $OUTPUT->heading(format_string($course->shortname
, true, array('context' => $context)) .' '.$stroverview, 3);
119 echo $strfiltergroups;
122 $options[0] = get_string('all');
123 foreach ($groupings as $grouping) {
124 $options[$grouping->id
] = strip_tags(format_string($grouping->name
));
126 $popupurl = new moodle_url($rooturl.'&group='.$groupid);
127 $select = new single_select($popupurl, 'grouping', $options, $groupingid, array());
128 $select->label
= $strgrouping;
129 $select->formid
= 'selectgrouping';
130 echo $OUTPUT->render($select);
133 $options[0] = get_string('all');
134 foreach ($groups as $group) {
135 $options[$group->id
] = strip_tags(format_string($group->name
));
137 $popupurl = new moodle_url($rooturl.'&grouping='.$groupingid);
138 $select = new single_select($popupurl, 'group', $options, $groupid, array());
139 $select->label
= $strgroup;
140 $select->formid
= 'selectgroup';
141 echo $OUTPUT->render($select);
145 $hoverevents = array();
146 foreach ($members as $gpgid=>$groupdata) {
147 if ($groupingid and $groupingid != $gpgid) {
148 continue; // do not show
150 $table = new html_table();
151 $table->head
= array(get_string('groupscount', 'group', count($groupdata)), get_string('groupmembers', 'group'), get_string('usercount', 'group'));
152 $table->size
= array('20%', '70%', '10%');
153 $table->align
= array('left', 'left', 'center');
154 $table->width
= '90%';
155 $table->data
= array();
156 foreach ($groupdata as $gpid=>$users) {
157 if ($groupid and $groupid != $gpid) {
161 $name = print_group_picture($groups[$gpid], $course->id
, false, true, false) . format_string($groups[$gpid]->name
);
162 $description = file_rewrite_pluginfile_urls($groups[$gpid]->description
, 'pluginfile.php', $context->id
, 'group', 'description', $gpid);
163 $options = new stdClass
;
164 $options->noclean
= true;
165 $options->overflowdiv
= true;
166 $jsdescription = trim(format_text($description, $groups[$gpid]->descriptionformat
, $options));
167 if (empty($jsdescription)) {
170 $line[] = html_writer
::tag('span', $name, array('id'=>'group_'.$gpid));
171 $hoverevents['group_'.$gpid] = $jsdescription;
173 $fullnames = array();
174 foreach ($users as $user) {
175 $fullnames[] = '<a href="'.$CFG->wwwroot
.'/user/view.php?id='.$user->id
.'&course='.$course->id
.'">'.fullname($user, true).'</a>';
177 $line[] = implode(', ', $fullnames);
178 $line[] = count($users);
179 $table->data
[] = $line;
181 if ($groupid and empty($table->data
)) {
185 echo $OUTPUT->heading($strnotingrouping, 3);
187 echo $OUTPUT->heading(format_string($groupings[$gpgid]->name
), 3);
188 $description = file_rewrite_pluginfile_urls($groupings[$gpgid]->description
, 'pluginfile.php', $context->id
, 'grouping', 'description', $gpgid);
189 $options = new stdClass
;
190 $options->noclean
= true;
191 $options->overflowdiv
= true;
192 echo $OUTPUT->box(format_text($description, $groupings[$gpgid]->descriptionformat
, $options), 'generalbox boxwidthnarrow boxaligncenter');
194 echo html_writer
::table($table);
198 if (count($hoverevents)>0) {
199 $PAGE->requires
->string_for_js('description', 'moodle');
200 $PAGE->requires
->js_init_call('M.core_group.init_hover_events', array($hoverevents));
203 echo $OUTPUT->footer();