forked from UFSC/moodle-local-relationship
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cohorts.php
108 lines (93 loc) · 4.38 KB
/
cohorts.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
<?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 Cohorts 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_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);
$editable = $manager && empty($relationship->component);
$baseurl = new moodle_url('/local/relationship/cohorts.php', array('relationshipid' => $relationship->id));
$returnurl = new moodle_url('/local/relationship/index.php', array('contextid' => $context->id));
relationship_set_header($context, $baseurl, $relationship, 'cohorts');
relationship_set_title($relationship, 'cohorts');
$relationshipcohorts = relationship_get_cohorts($relationshipid);
$data = array();
foreach ($relationshipcohorts as $rch) {
$line = array();
$line[] = $rch->cohort ? $rch->cohort->name : '?';
$line[] = $rch->cohort ? $DB->count_records('cohort_members', array('cohortid'=>$rch->cohort->id)) : '?';
$line[] = $rch->role_name;
$line[] = $rch->allowdupsingroups ? get_string('yes') : get_string('no');
$line[] = $rch->uniformdistribution ? get_string('yes') : get_string('no');
if ($editable) {
$buttons = array();
$buttons[] = html_writer::link(new moodle_url('/local/relationship/edit_cohort.php', array('relationshipcohortid' => $rch->id, 'delete' => 1)),
html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/delete'), 'alt' => get_string('delete'), 'title' => get_string('delete'), 'class' => 'iconsmall')));
$buttons[] = html_writer::link(new moodle_url('/local/relationship/edit_cohort.php', array('relationshipcohortid' => $rch->id)),
html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/edit'), 'alt' => get_string('edit'), 'title' => get_string('edit'), 'class' => 'iconsmall')));
$line[] = implode(' ', $buttons);
}
$data[] = $line;
}
$table = new html_table();
$table->head = array(
get_string('cohort', 'cohort'),
get_string('size'),
get_string('role'),
get_string('allowdupsingroups', 'local_relationship').$OUTPUT->help_icon('allowdupsingroups', 'local_relationship'),
get_string('uniformdistribute', 'local_relationship').$OUTPUT->help_icon('uniformdistribute', 'local_relationship'),
get_string('edit')
);
$table->colclasses = array(
'leftalign',
'leftalign',
'leftalign',
'centeralign',
'leftalign',
'leftalign'
);
$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) {
$cohorts = relationship_get_cohort_options($relationshipid);
foreach ($relationshipcohorts AS $rc) {
unset($cohorts[$rc->cohortid]);
}
if (empty($cohorts)) {
echo $OUTPUT->heading(get_string('nocohorts', 'local_relationship'), 4);
} else {
$add = new single_button(new moodle_url('/local/relationship/edit_cohort.php',
array('relationshipid' => $relationshipid)), get_string('add'));
echo $OUTPUT->render($add);
}
} else if ($manager) {
echo $OUTPUT->heading(get_string('noeditable', 'local_relationship', 4));
}
echo $OUTPUT->box_end();
echo $OUTPUT->footer();