| 1 |
efrain |
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 |
|
| 1441 |
ariadna |
17 |
use core\output\html_writer;
|
|
|
18 |
use core\user;
|
|
|
19 |
|
| 1 |
efrain |
20 |
/**
|
|
|
21 |
* Mentees block.
|
|
|
22 |
*
|
|
|
23 |
* @package block_mentees
|
|
|
24 |
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
|
|
|
25 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
26 |
*/
|
|
|
27 |
|
|
|
28 |
class block_mentees extends block_base {
|
|
|
29 |
|
|
|
30 |
function init() {
|
|
|
31 |
$this->title = get_string('pluginname', 'block_mentees');
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
function applicable_formats() {
|
|
|
35 |
return array('all' => true, 'tag' => false);
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
function specialization() {
|
|
|
39 |
$this->title = isset($this->config->title) ? $this->config->title : get_string('newmenteesblock', 'block_mentees');
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
function instance_allow_multiple() {
|
|
|
43 |
return true;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
function get_content() {
|
| 1441 |
ariadna |
47 |
global $USER, $DB;
|
| 1 |
efrain |
48 |
|
|
|
49 |
if ($this->content !== NULL) {
|
|
|
50 |
return $this->content;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
$this->content = new stdClass();
|
|
|
54 |
|
|
|
55 |
// get all the mentees, i.e. users you have a direct assignment to
|
|
|
56 |
$userfieldsapi = \core_user\fields::for_name();
|
| 1441 |
ariadna |
57 |
$userfieldssql = $userfieldsapi->get_sql('u', false, '', '', false);
|
|
|
58 |
|
|
|
59 |
[$usersort] = users_order_by_sql('u', null, $this->context, $userfieldssql->mappings);
|
|
|
60 |
|
|
|
61 |
if ($users = $DB->get_records_sql("SELECT u.id, $userfieldssql->selects
|
| 1 |
efrain |
62 |
FROM {role_assignments} ra, {context} c, {user} u
|
|
|
63 |
WHERE ra.userid = ?
|
|
|
64 |
AND ra.contextid = c.id
|
|
|
65 |
AND c.instanceid = u.id
|
| 1441 |
ariadna |
66 |
AND c.contextlevel = ?
|
|
|
67 |
ORDER BY $usersort", [$USER->id, CONTEXT_USER])) {
|
| 1 |
efrain |
68 |
|
|
|
69 |
$this->content->text = '<ul>';
|
| 1441 |
ariadna |
70 |
foreach ($users as $user) {
|
|
|
71 |
$userprofileurl = user::get_profile_url($user);
|
|
|
72 |
$userfullname = user::get_fullname($user, $this->context);
|
|
|
73 |
$this->content->text .= '<li>' . html_writer::link($userprofileurl, $userfullname) . '</li>';
|
| 1 |
efrain |
74 |
}
|
|
|
75 |
$this->content->text .= '</ul>';
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
$this->content->footer = '';
|
|
|
79 |
|
|
|
80 |
return $this->content;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
/**
|
|
|
84 |
* Returns true if the block can be docked.
|
|
|
85 |
* The mentees block can only be docked if it has a non-empty title.
|
|
|
86 |
* @return bool
|
|
|
87 |
*/
|
|
|
88 |
public function instance_can_be_docked() {
|
|
|
89 |
return parent::instance_can_be_docked() && isset($this->config->title) && !empty($this->config->title);
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
/**
|
|
|
93 |
* Return the plugin config settings for external functions.
|
|
|
94 |
*
|
|
|
95 |
* @return stdClass the configs for both the block instance and plugin
|
|
|
96 |
* @since Moodle 3.8
|
|
|
97 |
*/
|
|
|
98 |
public function get_config_for_external() {
|
|
|
99 |
// Return all settings for all users since it is safe (no private keys, etc..).
|
|
|
100 |
$configs = !empty($this->config) ? $this->config : new stdClass();
|
|
|
101 |
|
|
|
102 |
return (object) [
|
|
|
103 |
'instance' => $configs,
|
|
|
104 |
'plugin' => new stdClass(),
|
|
|
105 |
];
|
|
|
106 |
}
|
|
|
107 |
}
|
|
|
108 |
|