-
Notifications
You must be signed in to change notification settings - Fork 2
/
groups.php
149 lines (130 loc) · 7.2 KB
/
groups.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Relationship's Groups listing page
*
* @package local_relationship
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__.'/../../config.php');
require($CFG->dirroot.'/local/relationship/lib.php');
require_once($CFG->dirroot.'/local/relationship/locallib.php');
require_once($CFG->libdir.'/adminlib.php');
require_login();
$relationshipid = required_param('relationshipid', PARAM_INT);
$relationship = $DB->get_record('relationship', array('id' => $relationshipid), '*', MUST_EXIST);
$context = context::instance_by_id($relationship->contextid, MUST_EXIST);
require_capability('local/relationship:view', $context);
$manager = has_capability('local/relationship:manage', $context);
$canassign = has_capability('local/relationship:assign', $context);
$editable = $manager && empty($relationship->component);
$baseurl = new moodle_url('/local/relationship/groups.php', array('relationshipid' => $relationship->id));
$returnurl = new moodle_url('/local/relationship/index.php', array('contextid' => $context->id));
relationship_set_header($context, $baseurl, $relationship, 'groups');
relationship_set_title($relationship, 'groups');
$relationshipgroups = relationship_get_groups($relationshipid);
$relationshipcohort = relationship_get_cohort_by_roleshortname($relationshipid, 'student');
$data = array();
foreach ($relationshipgroups as $relationshipgroup) {
$line = array();
$line[] = format_string($relationshipgroup->name);
$line[] = $relationshipgroup->size;
$line[] = $relationshipgroup->userlimit;
if ($relationshipgroup->uniformdistribution) {
$status = get_string('yes');
$uniformdistribution = 0;
$text = get_string('disable', 'local_relationship');
} else {
$status = get_string('no');
$uniformdistribution = 1;
$text = get_string('enable', 'local_relationship');
}
if ($editable) {
$url = new moodle_url('/local/relationship/edit_group.php', array('relationshipgroupid' => $relationshipgroup->id, 'uniformdistribution' => $uniformdistribution));
$line[] = $status.' ('.html_writer::link($url, $text).')';
} else {
$line[] = $status;
}
$buttons = array();
if ($editable) {
$buttons[] = html_writer::link(new moodle_url('/local/relationship/edit_group.php', array('relationshipgroupid' => $relationshipgroup->id, 'delete' => 1)),
html_writer::span($OUTPUT->pix_icon('t/delete', get_string('delete'), 'moodle', ['class' => 'iconsmall'])));
$buttons[] = html_writer::link(new moodle_url('/local/relationship/edit_group.php', array('relationshipgroupid' => $relationshipgroup->id)),
html_writer::span($OUTPUT->pix_icon('t/edit', get_string('edit'), 'moodle', ['class' => 'iconsmall'])));
}
if ($manager || $canassign) {
$buttons[] = html_writer::link(new moodle_url('/local/relationship/assign.php', array('relationshipgroupid' => $relationshipgroup->id)),
html_writer::span($OUTPUT->pix_icon('t/assignroles', get_string('assign', 'local_relationship'), 'moodle', ['class' => 'iconsmall'])));
if($relationshipcohort && empty($relationshipcohort->component) && !$relationshipcohort->uniformdistribution && !$relationshipgroup->uniformdistribution) {
$buttons[] = html_writer::link(new moodle_url('/local/relationship/mass_assign.php', array('relationshipgroupid' => $relationshipgroup->id)),
html_writer::span($OUTPUT->pix_icon('t/add', get_string('massassign', 'local_relationship'), 'moodle', ['class' => 'iconsmall'])));
}
}
$line[] = implode(' ', $buttons);
$data[] = $line;
}
$table = new html_table();
$table->head = array(get_string('name', 'local_relationship'),
get_string('memberscount', 'local_relationship'),
get_string('limit', 'local_relationship').$OUTPUT->help_icon('userlimit', 'local_relationship'),
get_string('uniformdistribute', 'local_relationship').$OUTPUT->help_icon('uniformdistribute', 'local_relationship'),
get_string('edit'));
$table->colclasses = array('leftalign name',
'leftalign size',
'centeralign uniformdistribute',
'leftalign name');
$table->id = 'relationships';
$table->attributes['class'] = 'admintable generaltable';
$table->data = $data;
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide');
echo html_writer::table($table);
if ($editable) {
$sql = "SELECT rc.id, rc.roleid, count(*) AS count
FROM {relationship_cohorts} rc
JOIN {cohort} ch ON (ch.id = rc.cohortid)
JOIN {cohort_members} cm ON (cm.cohortid = ch.id)
LEFT JOIN {relationship_members} rm ON (rm.relationshipcohortid = rc.id AND rm.userid = cm.userid)
WHERE rc.relationshipid = :relationshipid
AND rc.uniformdistribution = 1
AND ISNULL(rm.userid)
GROUP BY rc.id, rc.roleid";
$rcs = $DB->get_records_sql($sql, array('relationshipid' => $relationshipid));
if (!empty($rcs)) {
echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthnarrow');
echo $OUTPUT->heading(get_string('remaining', 'local_relationship'));
$rdata = array();
foreach ($rcs AS $rc) {
$role = $DB->get_record('role', array('id' => $rc->roleid));
$rdata[] = array(role_get_name($role), $rc->count);
}
$rtable = new html_table();
$rtable->head = array(get_string('role'),
get_string('remaining', 'local_relationship'));
$rtable->attributes['class'] = 'generaltable';
$rtable->data = $rdata;
echo html_writer::table($rtable);
$distributeremaining = new single_button(new moodle_url('/local/relationship/edit_group.php', array('relationshipid' => $relationshipid, 'distributeremaining' => 1)), get_string('distributeremaining', 'local_relationship'));
echo $OUTPUT->render($distributeremaining);
echo $OUTPUT->box_end();
}
$addgroup = new single_button(new moodle_url('/local/relationship/edit_group.php', array('relationshipid' => $relationshipid)), get_string('addgroup', 'local_relationship'));
$addgroups = new single_button(new moodle_url('/local/relationship/autogroup.php', array('relationshipid' => $relationshipid)), get_string('autogroup', 'local_relationship'));
echo html_writer::tag('div', $OUTPUT->render($addgroup).$OUTPUT->render($addgroups), array('class' => 'buttons'));
} else if ($manager) {
echo $OUTPUT->heading(get_string('noeditable', 'local_relationship'));
}
echo $OUTPUT->box_end();
echo $OUTPUT->footer();