This repository has been archived by the owner on Mar 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathblock_course_favourites.php
129 lines (105 loc) · 5.01 KB
/
block_course_favourites.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
<?php
// 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/>.
/**
* Course favourites block main block class.
*
* @package blocks-course_favourites
* @copyright © 2014 The Regents of the University of California
* @copyright 2010 Remote Learner - http://www.remote-learner.net/
* @author Carson Tam <[email protected]>, Akin Delamarre <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once($CFG->dirroot . '/blocks/course_favourites/lib.php');
class block_course_favourites extends block_list {
function init() {
$this->title = get_string('course_favourites', 'block_course_favourites');
}
function get_content() {
global $CFG, $DB, $USER, $COURSE, $OUTPUT;
if ($this->content !== NULL) {
return $this->content;
}
$this->content = new stdClass;
$this->content->items = array();
$this->content->icons = array();
$this->content->footer = '';
if (!isloggedin() or isguestuser()) {
return $this->content;
}
$icon = $OUTPUT->pix_icon('course_favourites', get_string('coursecategory'), 'block_course_favourites');
$sql = "SELECT ra.id
FROM {$CFG->prefix}role_assignments ra
INNER JOIN {$CFG->prefix}context ctx ON ra.contextid = ctx.id
WHERE ctx.contextlevel = " . CONTEXT_COURSE . "
AND ra.userid = {$USER->id}";
// Verify if the user has a role in any course
if (!empty($CFG->block_course_favourites_musthaverole) && !$DB->record_exists_sql($sql)) {
$this->content->items[] = get_string('nocoursesforyou', 'block_course_favourites');
$this->content->footer = '<a href="' . $CFG->wwwroot . '/blocks/course_favourites/usersettings.php?' .
'courseid=' . $COURSE->id . '">' . get_string('settings', 'block_course_favourites') .
'</a>';
$this->content->icons[] = '';
} else {
$noselection = true;
// Verify further whether the user has created their favourites list
if (($sortorder = $DB->get_field('block_course_favourites', 'sortorder', array('userid' => $USER->id)))) {
$noselection = false;
// Print list of courses work done here.....
$crsfavs = get_user_fav_courses($USER->id);
$class = '';
if (!empty($crsfavs)) {
foreach ($crsfavs as $crsfav) {
if ($crsfav->visible) {
$class = '';
} else {
$class = 'class="dimmed"';
}
$this->content->items[] = '<a ' . $class . ' title="' . $crsfav->shortname . '" '.
'href="' . $CFG->wwwroot . '/course/view.php?id=' .
$crsfav->id . '">' . $icon . format_string($crsfav->fullname) . '</a>';
}
}
$this->content->footer = '<a href="'.$CFG->wwwroot.'/blocks/course_favourites/usersettings.php?' .
'courseid=' . $COURSE->id . '">' . get_string('settings', 'block_course_favourites') .
'</a>';
}
// print intro/help message if no selection has been created by the user
if ($noselection) {
$this->content->items[] = get_string('noselecedcoursesforyou', 'block_course_favourites');
$this->content->icons[] = '';
$this->content->footer = '<a href="' . $CFG->wwwroot . '/blocks/course_favourites/usersettings.php?' .
'courseid=' . $COURSE->id . '">' . get_string('settings', 'block_course_favourites') .
'</a>';
}
}
if (!empty($footer)) {
$this->content->footer = $footer;
}
return $this->content;
}
function has_config() {
return true;
}
/**
* Which page types this block may appear on.
*
* @return array page-type prefix => true/false.
*/
function applicable_formats() {
return array('all' => true);
}
public function instance_allow_multiple() {
return false;
}
}