|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00011 require_once('../config.php'); 00012 require_once($CFG->libdir . '/filelib.php'); 00013 00014 $courseid = required_param('id', PARAM_INT); 00015 $groupid = optional_param('group', 0, PARAM_INT); 00016 $groupingid = optional_param('grouping', 0, PARAM_INT); 00017 00018 $returnurl = $CFG->wwwroot.'/group/index.php?id='.$courseid; 00019 $rooturl = $CFG->wwwroot.'/group/overview.php?id='.$courseid; 00020 00021 if (!$course = $DB->get_record('course', array('id'=>$courseid))) { 00022 print_error('invalidcourse'); 00023 } 00024 00025 $url = new moodle_url('/group/overview.php', array('id'=>$courseid)); 00026 if ($groupid !== 0) { 00027 $url->param('group', $groupid); 00028 } 00029 if ($groupingid !== 0) { 00030 $url->param('grouping', $groupingid); 00031 } 00032 $PAGE->set_url($url); 00033 00034 // Make sure that the user has permissions to manage groups. 00035 require_login($course); 00036 00037 $context = get_context_instance(CONTEXT_COURSE, $courseid); 00038 require_capability('moodle/course:managegroups', $context); 00039 00040 $strgroups = get_string('groups'); 00041 $strparticipants = get_string('participants'); 00042 $stroverview = get_string('overview', 'group'); 00043 $strgrouping = get_string('grouping', 'group'); 00044 $strgroup = get_string('group', 'group'); 00045 $strnotingrouping = get_string('notingrouping', 'group'); 00046 $strfiltergroups = get_string('filtergroups', 'group'); 00047 $strnogroups = get_string('nogroups', 'group'); 00048 $strdescription = get_string('description'); 00049 00050 // Get all groupings 00051 $groupings = $DB->get_records('groupings', array('courseid'=>$courseid), 'name'); 00052 $members = array(); 00053 foreach ($groupings as $grouping) { 00054 $members[$grouping->id] = array(); 00055 } 00056 $members[-1] = array(); //groups not in a grouping 00057 00058 // Get all groups 00059 $groups = $DB->get_records('groups', array('courseid'=>$courseid), 'name'); 00060 00061 $params = array('courseid'=>$courseid); 00062 if ($groupid) { 00063 $groupwhere = "AND g.id = :groupid"; 00064 $params['groupid'] = $groupid; 00065 } else { 00066 $groupwhere = ""; 00067 } 00068 00069 if ($groupingid) { 00070 $groupingwhere = "AND gg.groupingid = :groupingid"; 00071 $params['groupingid'] = $groupingid; 00072 } else { 00073 $groupingwhere = ""; 00074 } 00075 $sql = "SELECT g.id AS groupid, gg.groupingid, u.id AS userid, u.firstname, u.lastname, u.idnumber, u.username 00076 FROM {groups} g 00077 LEFT JOIN {groupings_groups} gg ON g.id = gg.groupid 00078 LEFT JOIN {groups_members} gm ON g.id = gm.groupid 00079 LEFT JOIN {user} u ON gm.userid = u.id 00080 WHERE g.courseid = :courseid $groupwhere $groupingwhere 00081 ORDER BY g.name, u.lastname, u.firstname"; 00082 00083 $rs = $DB->get_recordset_sql($sql, $params); 00084 foreach ($rs as $row) { 00085 $user = new stdClass(); 00086 $user->id = $row->userid; 00087 $user->firstname = $row->firstname; 00088 $user->lastname = $row->lastname; 00089 $user->username = $row->username; 00090 $user->idnumber = $row->idnumber; 00091 if (!$row->groupingid) { 00092 $row->groupingid = -1; 00093 } 00094 if (!array_key_exists($row->groupid, $members[$row->groupingid])) { 00095 $members[$row->groupingid][$row->groupid] = array(); 00096 } 00097 if(isset($user->id)){ 00098 $members[$row->groupingid][$row->groupid][] = $user; 00099 } 00100 } 00101 $rs->close(); 00102 00103 navigation_node::override_active_url(new moodle_url('/group/index.php', array('id'=>$courseid))); 00104 $PAGE->navbar->add(get_string('overview', 'group')); 00105 00107 $PAGE->set_title($strgroups); 00108 $PAGE->set_heading($course->fullname); 00109 $PAGE->set_pagelayout('standard'); 00110 echo $OUTPUT->header(); 00111 00112 // Add tabs 00113 $currenttab = 'overview'; 00114 require('tabs.php'); 00115 00117 echo $OUTPUT->heading(format_string($course->shortname, true, array('context' => $context)) .' '.$stroverview, 3); 00118 00119 echo $strfiltergroups; 00120 00121 $options = array(); 00122 $options[0] = get_string('all'); 00123 foreach ($groupings as $grouping) { 00124 $options[$grouping->id] = strip_tags(format_string($grouping->name)); 00125 } 00126 $popupurl = new moodle_url($rooturl.'&group='.$groupid); 00127 $select = new single_select($popupurl, 'grouping', $options, $groupingid, array()); 00128 $select->label = $strgrouping; 00129 $select->formid = 'selectgrouping'; 00130 echo $OUTPUT->render($select); 00131 00132 $options = array(); 00133 $options[0] = get_string('all'); 00134 foreach ($groups as $group) { 00135 $options[$group->id] = strip_tags(format_string($group->name)); 00136 } 00137 $popupurl = new moodle_url($rooturl.'&grouping='.$groupingid); 00138 $select = new single_select($popupurl, 'group', $options, $groupid, array()); 00139 $select->label = $strgroup; 00140 $select->formid = 'selectgroup'; 00141 echo $OUTPUT->render($select); 00142 00144 $printed = false; 00145 $hoverevents = array(); 00146 foreach ($members as $gpgid=>$groupdata) { 00147 if ($groupingid and $groupingid != $gpgid) { 00148 continue; // do not show 00149 } 00150 $table = new html_table(); 00151 $table->head = array(get_string('groupscount', 'group', count($groupdata)), get_string('groupmembers', 'group'), get_string('usercount', 'group')); 00152 $table->size = array('20%', '70%', '10%'); 00153 $table->align = array('left', 'left', 'center'); 00154 $table->width = '90%'; 00155 $table->data = array(); 00156 foreach ($groupdata as $gpid=>$users) { 00157 if ($groupid and $groupid != $gpid) { 00158 continue; 00159 } 00160 $line = array(); 00161 $name = print_group_picture($groups[$gpid], $course->id, false, true, false) . format_string($groups[$gpid]->name); 00162 $description = file_rewrite_pluginfile_urls($groups[$gpid]->description, 'pluginfile.php', $context->id, 'group', 'description', $gpid); 00163 $options = new stdClass; 00164 $options->noclean = true; 00165 $options->overflowdiv = true; 00166 $jsdescription = trim(format_text($description, $groups[$gpid]->descriptionformat, $options)); 00167 if (empty($jsdescription)) { 00168 $line[] = $name; 00169 } else { 00170 $line[] = html_writer::tag('span', $name, array('id'=>'group_'.$gpid)); 00171 $hoverevents['group_'.$gpid] = $jsdescription; 00172 } 00173 $fullnames = array(); 00174 foreach ($users as $user) { 00175 $fullnames[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$user->id.'&course='.$course->id.'">'.fullname($user, true).'</a>'; 00176 } 00177 $line[] = implode(', ', $fullnames); 00178 $line[] = count($users); 00179 $table->data[] = $line; 00180 } 00181 if ($groupid and empty($table->data)) { 00182 continue; 00183 } 00184 if ($gpgid < 0) { 00185 echo $OUTPUT->heading($strnotingrouping, 3); 00186 } else { 00187 echo $OUTPUT->heading(format_string($groupings[$gpgid]->name), 3); 00188 $description = file_rewrite_pluginfile_urls($groupings[$gpgid]->description, 'pluginfile.php', $context->id, 'grouping', 'description', $gpgid); 00189 $options = new stdClass; 00190 $options->noclean = true; 00191 $options->overflowdiv = true; 00192 echo $OUTPUT->box(format_text($description, $groupings[$gpgid]->descriptionformat, $options), 'generalbox boxwidthnarrow boxaligncenter'); 00193 } 00194 echo html_writer::table($table); 00195 $printed = true; 00196 } 00197 00198 if (count($hoverevents)>0) { 00199 $PAGE->requires->string_for_js('description', 'moodle'); 00200 $PAGE->requires->js_init_call('M.core_group.init_hover_events', array($hoverevents)); 00201 } 00202 00203 echo $OUTPUT->footer();