MDL-65788 tool_policy: Prevent two modals rendering for guests.
[moodle.git] / blocks / participants / block_participants.php
CommitLineData
4ca6cfbf 1<?php
f25a6839
SH
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 * Participants block
19 *
20 * @package block_participants
21 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
0f3fe4b6 24
93b47710
MN
25defined('MOODLE_INTERNAL') || die();
26
27require_once($CFG->dirroot . '/course/lib.php');
28
29/**
30 * Participants block
31 *
32 * @package block_participants
33 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 */
3ef642d9 36class block_participants extends block_list {
9b4b78fd 37 function init() {
882f4e13 38 $this->title = get_string('pluginname', 'block_participants');
0f3fe4b6 39 }
40
41 function get_content() {
224aa44a 42
6b608f8f 43 global $CFG, $OUTPUT;
224aa44a 44
45 if (empty($this->instance)) {
46 $this->content = '';
47 return $this->content;
48 }
49
dd4bee83 50 $this->content = new stdClass();
165088f6 51 $this->content->items = array();
52 $this->content->icons = array();
53 $this->content->footer = '';
3179b000 54
44cbe13a
RT
55 // user/index.php expect course context, so get one if page has module context.
56 $currentcontext = $this->page->context->get_course_context(false);
3179b000 57
44cbe13a
RT
58 if (empty($currentcontext)) {
59 $this->content = '';
60 return $this->content;
61 } else if ($this->page->course->id == SITEID) {
93b47710 62 if (!course_can_view_participants(context_system::instance())) {
165088f6 63 $this->content = '';
64 return $this->content;
65 }
66 } else {
93b47710 67 if (!course_can_view_participants($currentcontext)) {
165088f6 68 $this->content = '';
69 return $this->content;
70 }
0f3fe4b6 71 }
44cbe13a 72
663640f5 73 $icon = $OUTPUT->pix_icon('i/users', '');
224aa44a 74 $this->content->items[] = '<a title="'.get_string('listofallpeople').'" href="'.
710363c9 75 $CFG->wwwroot.'/user/index.php?contextid='.$currentcontext->id.'">'.$icon.get_string('participants').'</a>';
0f3fe4b6 76
77 return $this->content;
78 }
224aa44a 79
0d6b9d4f 80 // my moodle can only have SITEID and it's redundant here, so take it away
81 function applicable_formats() {
9591bc3c 82 return array('all' => true, 'my' => false, 'tag' => false);
0d6b9d4f 83 }
52788321 84
0f3fe4b6 85}