-
Notifications
You must be signed in to change notification settings - Fork 2
/
block_ual_mymoodle.php
156 lines (132 loc) · 4.53 KB
/
block_ual_mymoodle.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?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/>.
/**
* Main block file
*
* @package block
* @subpackage ual_mymoodle
* @copyright 2012 University of London Computer Centre
* @author Ian Wild {@link http://moodle.org/user/view.php?id=325899}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* This class builds a block displaying the programmes, courses and units a user is enrolled on.
*
* @copyright 2012 Ian Wild
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_ual_mymoodle extends block_base {
/** @var int Trim characters from the right */
const TRIM_RIGHT = 1;
/** @var int Trim characters from the left */
const TRIM_LEFT = 2;
/** @var int Trim characters from the center */
const TRIM_CENTER = 3;
/**
* Standard init function, sets block title and version number
*
* @return void
*/
public function init() {
$this->title = get_string('ual_mymoodle', 'block_ual_mymoodle');
}
/**
* Standard specialization function
*
* @return void
*/
public function specialization() {
$this->title = get_string('ual_mymoodle', 'block_ual_mymoodle');
}
/**
* Returns the attributes to set for this block
*
* This function returns an array of HTML attributes for this block including
* the defaults.
* {@link block_tree::html_attributes()} is used to get the default arguments
* and then we check whether the user has enabled hover expansion and add the
* appropriate hover class if it has.
*
* @return array An array of HTML attributes
*/
function html_attributes() {
$attributes = parent::html_attributes();
$attributes['class'] .= ' course_menu';
return $attributes;
}
/**
* Standard get content function returns $this->content containing the block HTML etc
*
* @return stdClass
*/
public function get_content() {
global $CFG, $USER, $PAGE, $OUTPUT;
if ($this->content !== null) {
return $this->content;
}
if (empty($this->instance)) {
return null;
}
$showcode = 0;
$trimmode = 1;
$trimlength = 50;
if (!empty($this->config->showcode)) {
$showcode = (int)$this->config->showcode;
}
if (!empty($this->config->trimmode)) {
$trimmode = (int)$this->config->trimmode;
}
if (!empty($this->config->trimlength)) {
$trimlength = (int)$this->config->trimlength;
}
// Load userdefined title and make sure it's never empty.
if (empty($this->config->title)) {
$this->title = get_string('ual_mymoodle', 'block_ual_mymoodle');
} else {
$this->title = $this->config->title;
}
$this->content = new stdClass();
$this->content->text = '';
$this->content->footer = '';
if (isloggedin() && !isguestuser()) { // Show the block.
$this->content = new stdClass();
// TODO: add capability check here?
$renderer = $this->page->get_renderer('block_ual_mymoodle');
$this->content->text = $renderer->course_hierarchy($showcode, $trimmode, $trimlength);
$this->content->footer = '';
}
return $this->content;
}
/**
* Standard function - does the block allow configuration for specific instances of itself
* rather than sitewide?
*
* @return bool false
*/
public function instance_allow_config() {
return false;
}
/**
* Standard function - there will already be a 'sticky' course level block on a course page so prevent an
* editing teacher from adding one.
*
* @return bool false
*/
public function instance_allow_multiple() {
return false;
}
}