MDL-10383 - groups/groupings refactoring and improvements - basic UI for groupings...
[moodle.git] / group / groupings.php
CommitLineData
62d63838 1<?php // $Id$
2 // Allows a creator to edit groupings
3
4require_once '../config.php';
5require_once $CFG->dirroot.'/group/lib.php';
6
7$courseid = required_param('id', PARAM_INT);
8
9if (!$course = get_record('course', 'id', $courseid)) {
10 print_error('nocourseid');
11}
12
13require_login($course);
14$context = get_context_instance(CONTEXT_COURSE, $course->id);
15require_capability('moodle/course:managegroups', $context);
16
17$strgrouping = get_string('grouping', 'group');
18$strgroups = get_string('groups');
19$strname = get_string('name');
20$strdelete = get_string('delete');
21$stredit = get_string('edit');
22$srtnewgrouping = get_string('creategrouping', 'group');
23$strgroups = get_string('groups');
24$strgroupings = get_string('groupings', 'group');
25$struses = get_string('activities');
26$strparticipants = get_string('participants');
27$strmanagegrping = get_String('addgroupstogrouping', 'group');
28
29$navlinks = array(array('name'=>$strparticipants, 'link'=>$CFG->wwwroot.'/user/index.php?id='.$courseid, 'type'=>'misc'),
30 array('name'=>$strgroups, 'link'=>$CFG->wwwroot.'/group/index.php?id='.$courseid, 'type'=>'misc'),
31 array('name'=>$strgroupings, 'link'=>'', 'type'=>'misc'));
32$navigation = build_navigation($navlinks);
33
34/// Print header
35print_header_simple($strgroupings, ': '.$strgroupings, $navigation, '', '', true, '', navmenu($course));
36
37print_heading($strgroupings);
38
39$data = array();
40if ($groupings = get_records('groupings', 'courseid', $course->id)) {
41 foreach($groupings as $grouping) {
42 $line = array();
43 $line[0] = format_string($grouping->name);
44
45 if ($groups = groups_get_all_groups($courseid, 0, $grouping->id)) {
46 $groupnames = array();
47 foreach ($groups as $group) {
48 $groupnames[] = format_string($group->name);
49 }
50 $line[1] = implode(', ', $groupnames);
51 } else {
52 $line[1] = get_string('none');
53 }
54 $line[2] = (int)count_records('course_modules', 'course', $course->id, 'groupingid', $grouping->id);
55
56 $buttons = "<a title=\"$stredit\" href=\"grouping.php?id=$grouping->id\"><img".
57 " src=\"$CFG->pixpath/t/edit.gif\" class=\"iconsmall\" alt=\"$stredit\" /></a> ";
58 $buttons .= "<a title=\"$strdelete\" href=\"grouping.php?id=$grouping->id&amp;delete=1\"><img".
59 " src=\"$CFG->pixpath/t/delete.gif\" class=\"iconsmall\" alt=\"$strdelete\" /></a> ";
60 $buttons .= "<a title=\"$strmanagegrping\" href=\"assign.php?id=$grouping->id\"><img".
61 " src=\"$CFG->pixpath/i/group.gif\" class=\"iconsmall\" alt=\"$strmanagegrping\" /></a> ";
62
63 $line[3] = $buttons;
64 $data[] = $line;
65 }
66}
67$table->head = array($strgrouping, $strgroups, $struses, $stredit);
68$table->size = array('30%', '50%', '10%', '10%');
69$table->align = array('left', 'left', 'center', 'center');
70$table->width = '90%';
71$table->data = $data;
72print_table($table);
73
74echo '<div class="buttons">';
75print_single_button('grouping.php', array('courseid'=>$courseid), $srtnewgrouping);
76echo '</div>';
77
78print_footer($course);
79
80?>