-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.php
154 lines (139 loc) · 5.62 KB
/
lib.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
<?php
// This file is part of local_checkmarkreport for Moodle - http://moodle.org/
//
// It 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.
//
// It 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/>.
/**
* Library of interface functions and constants for module checkmarkreport
*
* All the core Moodle functions, neeeded to allow the module to work
* integrated in Moodle should be placed here.
* All the checkmarkreport specific functions, needed to implement all the module
* logic, should go to locallib.php. This will help to save some memory when
* Moodle is performing actions across all modules.
*
* @package local_checkmarkreport
* @author Philipp Hager
* @copyright 2014 Academic Moodle Cooperation {@link http://www.academic-moodle-cooperation.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Function injects navigation node linking to current courses checkmarkreport in navigation tree near grades node!
*
* @param global_navigation $nav Global navigation object
*
* @return void
*/
function local_checkmarkreport_extend_navigation(global_navigation $nav) {
global $PAGE, $USER;
// Only add this settings item on non-site course pages.
if (!$PAGE->course or $PAGE->course->id == SITEID) {
return;
}
// Only let users with the appropriate capability see this settings item.
if (!has_capability('local/checkmarkreport:view', context_course::instance($PAGE->course->id), $USER->id)) {
return;
}
// This is super fast!
$modinfo = get_fast_modinfo($PAGE->course, -1);
if (empty($modinfo->instances['checkmark'])) {
return;
}
if ($nav->find('checkmarkreport' . $PAGE->course->id, navigation_node::TYPE_CUSTOM)) {
// Already added!
return;
}
// Prepare our node!
$url = new moodle_url('/local/checkmarkreport/index.php', ['id' => $PAGE->course->id]);
$icon = new pix_icon('i/report', get_string('pluginname', 'local_checkmarkreport'));
$node = navigation_node::create(get_string('pluginname', 'local_checkmarkreport'),
$url,
navigation_node::TYPE_CUSTOM,
get_string('pluginname', 'local_checkmarkreport'),
'checkmarkreport' . $PAGE->course->id,
$icon);
$coursenode = $nav->find($PAGE->course->id, global_navigation::TYPE_UNKNOWN);
if ($grade = $coursenode->find('grades', navigation_node::TYPE_UNKNOWN)) {
$keys = $grade->parent->get_children_key_list();
foreach ($keys as $i => $key) {
if ($key == 'grades') {
$i++;
break;
}
}
if (key_exists($i, $keys)) {
$grade->parent->add_node($node, $keys[$i]);
} else {
$grade->parent->add_node($node);
}
} else {
$coursenode->add_node($node);
}
return;
}
/**
* Return the tab data for the checkmarkreport
*
* @param context_course $coursecontext
* @param int $id course ID
*
* @return mixed[] array with all the tab data
*/
function local_checkmarkreport_get_tabs($coursecontext, $id) {
global $USER, $CFG;
$tabs = [];
$availabletabs = [];
if (has_capability('local/checkmarkreport:view_courseoverview', $coursecontext, $USER->id)) {
$tabs[] = new tabobject('overview',
$CFG->wwwroot . '/local/checkmarkreport/index.php?id=' . $id .
'&tab=overview',
get_string('overview', 'local_checkmarkreport'),
get_string('overview_alt', 'local_checkmarkreport'),
false);
$availabletabs[] = 'overview';
}
if (has_capability('local/checkmarkreport:view_students_overview', $coursecontext, $USER->id)) {
$tabs[] = new tabobject('useroverview',
$CFG->wwwroot . '/local/checkmarkreport/index.php?id=' . $id .
'&tab=useroverview',
get_string('useroverview', 'local_checkmarkreport'),
get_string('useroverview_alt', 'local_checkmarkreport'),
false);
$availabletabs[] = 'useroverview';
}
// Here we check for capability and enrolment, to prevent admins from getting empty views or errors!
if (has_capability('local/checkmarkreport:view_own_overview', $coursecontext, $USER->id)
&& is_enrolled($coursecontext, null, 'local/checkmarkreport:view_own_overview', true)) {
$tabs[] = new tabobject('userview',
$CFG->wwwroot . '/local/checkmarkreport/index.php?id=' . $id .
'&tab=userview',
get_string('userview', 'local_checkmarkreport'),
get_string('userview_alt', 'local_checkmarkreport'),
false);
$availabletabs[] = 'userview';
}
if (count($tabs) > 1) {
$newtab = optional_param('tab', null, PARAM_ALPHAEXT);
if (!empty($newtab)) {
$tab = $newtab;
} else if (!isset($tab)) {
$tab = current($availabletabs);
}
} else if (count($tabs) == 1) {
$tab = current($availabletabs);
} else {
$tab = 'noaccess';
}
return [$tabs, $availabletabs, $tab];
}