-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.php
More file actions
104 lines (91 loc) · 3.63 KB
/
lib.php
File metadata and controls
104 lines (91 loc) · 3.63 KB
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
<?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/>.
/**
* Moodle hooks for local_learningdashboard
*
* @package local_learningdashboard
* @copyright 2026 Wunderbyte GmbH
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Renders the popup.
*
* @param renderer_base $renderer
* @return string The HTML
*/
function local_learningdashboard_render_navbar_output(\renderer_base $renderer) {
global $CFG, $USER;
$context = context_system::instance();
// Check if user is admin or has learning dashboard permissions.
$isadmin = is_siteadmin($USER->id);
$hasviewtrainer = has_capability('local/learningdashboard:viewtrainer', $context);
$hasviewstudent = has_capability('local/learningdashboard:viewstudent', $context);
$hasmanage = has_capability('local/learningdashboard:manage', $context);
if ($isadmin || $hasviewtrainer || $hasviewstudent || $hasmanage) {
$output = '<div><a href="' . $CFG->wwwroot . '/local/learningdashboard/index.php" class="nav-link icon-no-margin">
<i class="icon fa fa-chart-line fa-fw navicon" title="Learning Dashboard"></i></a></div>';
} else {
$output = '';
}
return $output;
}
/**
* Get SQL WHERE clause for course filtering.
*
* Returns a WHERE clause fragment and parameters array for filtering courses
* based on admin settings. If no courses are configured, returns empty string
* and empty array (no filtering applied).
*
* @param string $coursealias The table alias for the course table (default 'c').
* @return array [whereClause, params] SQL WHERE fragment and parameters.
*/
function local_learningdashboard_get_course_filter_sql($coursealias = 'c'): array {
$includedcourses = get_config('local_learningdashboard', 'includedcourses');
if (empty($includedcourses)) {
return ['', []];
}
// Handle JSON, serialized, and comma-separated formats.
$courseids = [];
// Try JSON decode first.
$decoded = json_decode($includedcourses, true);
if (is_array($decoded)) {
$courseids = $decoded;
} else {
// Try unserialize for backwards compatibility.
$unserialized = @unserialize($includedcourses);
if (is_array($unserialized)) {
$courseids = $unserialized;
} else if (strpos($includedcourses, ',') !== false) {
// Handle comma-separated values.
$courseids = array_map('trim', explode(',', $includedcourses));
} else {
// If it's a plain string/number, treat it as a single course ID.
$courseids = [$includedcourses];
}
}
if (empty($courseids)) {
return ['', []];
}
// Create named placeholders for IN clause.
$placeholders = [];
$params = [];
foreach ($courseids as $index => $courseid) {
$placeholders[] = ':filtercourse' . $index;
$params['filtercourse' . $index] = (int)$courseid;
}
$whereclaused = $coursealias . '.id IN (' . implode(',', $placeholders) . ')';
return [$whereclaused, $params];
}