forked from aspiredu/moodle-local_aspiredu
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlib.php
More file actions
164 lines (144 loc) · 6.47 KB
/
lib.php
File metadata and controls
164 lines (144 loc) · 6.47 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
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
157
158
159
160
161
162
163
164
<?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/>.
/**
* AspirEDU Integration
*
* @package local_aspiredu
* @author AspirEDU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
define('LOCAL_ASPIREDU_ADMINACCCOURSEINSTCOURSE', 1);
define('LOCAL_ASPIREDU_ADMINACCCINSTCOURSE', 2);
define('LOCAL_ASPIREDU_ADMINCOURSEINSTCOURSE', 3);
define('LOCAL_ASPIREDU_ADMINACCCOURSE', 4);
define('LOCAL_ASPIREDU_ADMINACC', 5);
define('LOCAL_ASPIREDU_INSTCOURSE', 6);
function local_aspiredu_check_links_visibility_permission($context, $settings) {
global $COURSE;
$contextsystem = context_system::instance();
$isadmin = (has_capability('moodle/site:config', $contextsystem) ||
has_capability('local/aspiredu:viewdropoutdetective', $contextsystem) ||
has_capability('local/aspiredu:viewinstructorinsight', $contextsystem)) ? true : false;
if (!$settings) {
return false;
}
if ($isadmin and $settings == LOCAL_ASPIREDU_INSTCOURSE) {
// Admins links disabled.
return false;
}
// Course permissions.
if ($context->contextlevel >= CONTEXT_COURSE and $COURSE->id != SITEID) {
if ($isadmin and $settings != LOCAL_ASPIREDU_ADMINACC and $settings != LOCAL_ASPIREDU_ADMINACCCINSTCOURSE) {
return true;
}
if (!$isadmin and $settings != LOCAL_ASPIREDU_ADMINACCCOURSE and $settings != LOCAL_ASPIREDU_ADMINACC) {
return true;
}
}
// Site permissions.
if ($context->contextlevel == CONTEXT_SYSTEM or $COURSE->id == SITEID) {
if ($isadmin and $settings != LOCAL_ASPIREDU_ADMINCOURSEINSTCOURSE) {
return true;
}
}
return false;
}
/**
* Display the AspirEdu settings in the course settings block
*
* @param settings_navigation $nav The settings navigatin object
* @param stdclass $context Course context
*/
function local_aspiredu_extend_settings_navigation(settings_navigation $nav, $context) {
global $COURSE;
$showcoursesettings = get_config('local_aspiredu', 'showcoursesettings');
if ($showcoursesettings and $context->contextlevel >= CONTEXT_COURSE and
($branch = $nav->get('courseadmin')) and has_capability('moodle/course:update', $context)) {
$url = new moodle_url('/local/aspiredu/course.php', array('id' => $context->instanceid));
$branch->add(
get_string('coursesettings', 'local_aspiredu'), $url, $nav::TYPE_CONTAINER, null, 'aspiredu'.$context->instanceid);
}
$dropoutdetectivelinks = get_config('local_aspiredu', 'dropoutdetectivelinks');
$instructorinsightlinks = get_config('local_aspiredu', 'instructorinsightlinks');
$reportsnode = null;
if (local_aspiredu_check_links_visibility_permission($context, $dropoutdetectivelinks)) {
$displayed = false;
$canview = has_capability('local/aspiredu:viewdropoutdetective', $context);
$branch = ($nav->get('courseadmin')) ? $nav->get('courseadmin') : $nav->get('frontpage');
if ($branch and $canview) {
$subbranch = ($branch->get('coursereports')) ? $branch->get('coursereports') : $branch->get('frontpagereports');
if ($subbranch) {
$url = new moodle_url('/local/aspiredu/aspiredu.php', array('id' => $COURSE->id, 'product' => 'dd'));
$subbranch->add(
get_string('dropoutdetective', 'local_aspiredu'),
$url,
$nav::TYPE_CONTAINER,
null,
'aspiredudd'.$context->instanceid,
new pix_icon('i/stats', '')
);
$displayed = true;
}
}
if ($canview and !$displayed) {
$reportsnode = $nav->add(get_string('reports'), null, $nav::NODETYPE_BRANCH, null, 'aspiredureports');
$url = new moodle_url('/local/aspiredu/aspiredu.php', array('id' => $COURSE->id, 'product' => 'dd'));
$reportsnode->add(
get_string('dropoutdetective', 'local_aspiredu'),
$url,
$nav::TYPE_CONTAINER,
null,
'aspiredudd'.$context->instanceid,
new pix_icon('i/stats', '')
);
}
}
if (local_aspiredu_check_links_visibility_permission($context, $instructorinsightlinks)) {
$displayed = false;
$canview = has_capability('local/aspiredu:viewinstructorinsight', $context);
$branch = ($nav->get('courseadmin')) ? $nav->get('courseadmin') : $nav->get('frontpage');
if ($branch and $canview) {
$subbranch = ($branch->get('coursereports')) ? $branch->get('coursereports') : $branch->get('frontpagereports');
if ($subbranch) {
$url = new moodle_url('/local/aspiredu/aspiredu.php', array('id' => $COURSE->id, 'product' => 'ii'));
$subbranch->add(
get_string('instructorinsight', 'local_aspiredu'),
$url,
$nav::TYPE_CONTAINER,
null,
'aspireduii'.$context->instanceid,
new pix_icon('i/stats', '')
);
$displayed = true;
}
}
if ($canview and !$displayed) {
if (!$reportsnode) {
$reportsnode = $nav->add(get_string('reports'), null, $nav::NODETYPE_BRANCH, null, 'aspiredureports');
}
$url = new moodle_url('/local/aspiredu/aspiredu.php', array('id' => $COURSE->id, 'product' => 'ii'));
$reportsnode->add(
get_string('instructorinsight', 'local_aspiredu'),
$url,
$nav::TYPE_CONTAINER,
null,
'aspireduii'.$context->instanceid,
new pix_icon('i/stats', '')
);
}
}
}