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