-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock_library_resources.php
61 lines (44 loc) · 1.95 KB
/
block_library_resources.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
<?php
class block_library_resources extends block_list {
function init() {
$this->title = get_string('pluginname', 'block_library_resources');
}
function get_content() {
if ($this->content !== NULL) {
return $this->content;
}
global $USER, $COURSE, $DB;
$this->content = new stdClass;
$this->content->items = array();
$this->content->icons = array();
$this->content->footer = '';
if ($COURSE->id !== SITEID) {
$sn = $COURSE->shortname;
$shortname = explode('-', $sn);
$dept = reset($shortname);
$params = array('dept_code' => $dept);
$links = $DB->get_records('block_library_resources', $params);
if ($links) {
foreach ($links as $link) {
$html_link = html_writer::link($link->url, $link->link_name);
$this->content->items[] = $html_link;
}
} else {
$default_url = get_string('default_link_url', 'block_library_resources');
$default_name = get_string('default_link_name', 'block_library_resources');
$html_link = html_writer::link($default_url, $default_name);
$this->content->items[] = $html_link;
}
}
$context = context_system::instance();
if (is_siteadmin($USER->id) or has_capability('block/library_resources:manage', $context)) {
$str = get_string('new', 'block_library_resources');
$url = new moodle_url('/blocks/library_resources/create.php');
$this->content->items[] = html_writer::link($url, $str);
$str = get_string('manage', 'block_library_resources');
$url = new moodle_url('/blocks/library_resources/manage.php');
$this->content->items[] = html_writer::link($url, $str);
}
return $this->content;
}
}