MDL-63050 cachestore_redis: Update hExists to check empty
[moodle.git] / blocks / mentees / block_mentees.php
blob0c2ff91557508bf1de2fc568a10c6efd84e17a8f
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.
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/>.
17 /**
18 * Mentees block.
20 * @package block_mentees
21 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 class block_mentees extends block_base {
27 function init() {
28 $this->title = get_string('pluginname', 'block_mentees');
31 function applicable_formats() {
32 return array('all' => true, 'tag' => false);
35 function specialization() {
36 $this->title = isset($this->config->title) ? $this->config->title : get_string('newmenteesblock', 'block_mentees');
39 function instance_allow_multiple() {
40 return true;
43 function get_content() {
44 global $CFG, $USER, $DB;
46 if ($this->content !== NULL) {
47 return $this->content;
50 $this->content = new stdClass();
52 // get all the mentees, i.e. users you have a direct assignment to
53 $allusernames = get_all_user_name_fields(true, 'u');
54 if ($usercontexts = $DB->get_records_sql("SELECT c.instanceid, c.instanceid, $allusernames
55 FROM {role_assignments} ra, {context} c, {user} u
56 WHERE ra.userid = ?
57 AND ra.contextid = c.id
58 AND c.instanceid = u.id
59 AND c.contextlevel = ".CONTEXT_USER, array($USER->id))) {
61 $this->content->text = '<ul>';
62 foreach ($usercontexts as $usercontext) {
63 $this->content->text .= '<li><a href="'.$CFG->wwwroot.'/user/view.php?id='.$usercontext->instanceid.'&amp;course='.SITEID.'">'.fullname($usercontext).'</a></li>';
65 $this->content->text .= '</ul>';
68 $this->content->footer = '';
70 return $this->content;
73 /**
74 * Returns true if the block can be docked.
75 * The mentees block can only be docked if it has a non-empty title.
76 * @return bool
78 public function instance_can_be_docked() {
79 return parent::instance_can_be_docked() && isset($this->config->title) && !empty($this->config->title);