forked from learnweb/moodle-mod_groupmembers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.php
98 lines (91 loc) · 4.12 KB
/
renderer.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
<?php
// This file is part of a plugin for 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/>.
/**
* Renderer definition for mod_groupmembers
*
* @package mod_groupmembers
* @copyright 2017 Dennis M. Riehle, WWU Münster
* @copyright 2017 Jan C. Dageförde, WWU Münster
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__. '/lib.php');
require_once($CFG->libdir. '/weblib.php');
/**
* Renderer definition for mod_groupmembers
*
* @package mod_groupmembers
* @copyright 2017 Dennis M. Riehle, WWU Münster
* @copyright 2017 Jan C. Dageförde, WWU Münster
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_groupmembers_renderer extends plugin_renderer_base {
/**
* Render the groups table(s)
*
* @param array $groups Array of groups as created by \mod_groupmembers\groups::get_groups_and_members()
* @param bool $showemail Setting whether email addresses should be suppressed
* @return string Rendered template
*/
public function render_allgroups(array $groups, $showemail) {
global $USER, $COURSE, $CFG;
$data = array(
'groups' => []
);
foreach ($groups as $group) {
$members = array();
foreach ($group['members'] as $member) {
$memberemail = null;
$memberemailtext = null;
$memberemailhidden = false;
$membermessage = null;
if ($USER->id != $member->id) {
if ($member->maildisplay == core_user::MAILDISPLAY_HIDE) {
// Email address should not be rendered unless user has at least enabled display to course members.
// User has chosen not to reveal an email address. This can be made explicit by the template.
$memberemailhidden = true;
} else if ($showemail == GROUPMEMBERS_SHOWEMAIL_ALLGROUPS ||
($showemail == GROUPMEMBERS_SHOWEMAIL_OWNGROUP && $group['ismember'])) {
// Since user allows showing, the final decision is up to the module's settings ($showemail).
$memberemail = obfuscate_email($member->email);
$memberemailtext = obfuscate_text($member->email);
}
if (!empty($CFG->messaging) &&
has_capability('moodle/site:sendmessage', \context_system::instance())) {
$membermessage = new moodle_url('/message/index.php', ['id' => $member->id]);
}
}
$members[] = array(
'id' => $member->id,
'picture' => $this->output->user_picture($member),
'displayname' => fullname($member),
'maillink' => $memberemail,
'mailtext' => $memberemailtext,
'mailhidden' => $memberemailhidden,
'profileurl' => new moodle_url('/user/view.php', ['id' => $member->id, 'course' => $COURSE->id]),
'messageurl' => $membermessage
);
}
$data['groups'][] = array(
'id' => $group['group']->id,
'name' => $group['group']->name,
'members' => $members,
'ismember' => $group['ismember']
);
}
return $this->render_from_template('mod_groupmembers/allgroups', $data);
}
}