MDL-32230 block_rss_client: remove extra cleaning step
[moodle.git] / group / overview.php
blob75efcc791a7f1834362e8753d81e84f5fd142b6c
1 <?php
2 /**
3 * Print an overview of groupings & group membership
5 * @author Matt Clarkson mattc@catalyst.net.nz
6 * @version 0.0.1
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package groups
9 */
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));
26 if ($groupid !== 0) {
27 $url->param('group', $groupid);
29 if ($groupingid !== 0) {
30 $url->param('grouping', $groupingid);
32 $PAGE->set_url($url);
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');
50 // Get all groupings
51 $groupings = $DB->get_records('groupings', array('courseid'=>$courseid), 'name');
52 $members = array();
53 foreach ($groupings as $grouping) {
54 $members[$grouping->id] = array();
56 $members[-1] = array(); //groups not in a grouping
58 // Get all groups
59 $groups = $DB->get_records('groups', array('courseid'=>$courseid), 'name');
61 $params = array('courseid'=>$courseid);
62 if ($groupid) {
63 $groupwhere = "AND g.id = :groupid";
64 $params['groupid'] = $groupid;
65 } else {
66 $groupwhere = "";
69 if ($groupingid) {
70 $groupingwhere = "AND gg.groupingid = :groupingid";
71 $params['groupingid'] = $groupingid;
72 } else {
73 $groupingwhere = "";
75 $sql = "SELECT g.id AS groupid, gg.groupingid, u.id AS userid, u.firstname, u.lastname, u.idnumber, u.username
76 FROM {groups} g
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();
97 if(isset($user->id)){
98 $members[$row->groupingid][$row->groupid][] = $user;
101 $rs->close();
103 navigation_node::override_active_url(new moodle_url('/group/index.php', array('id'=>$courseid)));
104 $PAGE->navbar->add(get_string('overview', 'group'));
106 /// Print header
107 $PAGE->set_title($strgroups);
108 $PAGE->set_heading($course->fullname);
109 $PAGE->set_pagelayout('standard');
110 echo $OUTPUT->header();
112 // Add tabs
113 $currenttab = 'overview';
114 require('tabs.php');
116 /// Print overview
117 echo $OUTPUT->heading(format_string($course->shortname, true, array('context' => $context)) .' '.$stroverview, 3);
119 echo $strfiltergroups;
121 $options = array();
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);
132 $options = array();
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);
143 /// Print table
144 $printed = false;
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) {
158 continue;
160 $line = array();
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)) {
168 $line[] = $name;
169 } else {
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.'&amp;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)) {
182 continue;
184 if ($gpgid < 0) {
185 echo $OUTPUT->heading($strnotingrouping, 3);
186 } else {
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);
195 $printed = true;
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();