-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.php
424 lines (385 loc) · 16.6 KB
/
index.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
<?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/>.
/**
* My Feedback Report.
*
* @package report_myfeedback
* @copyright 2022 UCL
* @author Jessica Gramp <[email protected]>
* @author Delvon Forrester <[email protected]>
* credits Based on original work report_mygrades by David Bezemer <[email protected]> which in turn is based on
* block_myfeedback by Karen Holland, Mei Jin, Jiajia Chen. Also uses SQL originating from Richard Havinga
* <[email protected]>. The code for using an external database is taken from Juan leyva's
* <http://www.twitter.com/jleyvadelgado> configurable reports block.
* The idea for this reporting tool originated with Dr Jason Davies <[email protected]> and
* Dr John Mitchell <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../../config.php');
global $PAGE, $COURSE, $USER, $OUTPUT, $currentdb, $CFG;
require_once($CFG->libdir . '/gradelib.php');
require_once($CFG->dirroot . '/grade/report/overview/lib.php');
require_once($CFG->dirroot . '/grade/lib.php');
require_once($CFG->dirroot . '/grade/querylib.php');
require_once($CFG->dirroot . '/user/profile/lib.php');
require_once($CFG->dirroot . '/user/lib.php');
raise_memory_limit(MEMORY_EXTRA); // CATALYST CUSTOM.
$url = new moodle_url('/report/myfeedback/index.php');
$PAGE->set_url($url);
$PAGE->set_pagelayout('report');
$PAGE->set_context(context_course::instance($COURSE->id));
$PAGE->navigation->add(get_string('pluginname', 'report_myfeedback'), $url);
$PAGE->set_heading($COURSE->fullname);
$PAGE->set_title(get_string('pluginname', 'report_myfeedback'));
$PAGE->requires->css(new moodle_url('/report/myfeedback/style/tooltip.css'));
$PAGE->requires->js_call_amd('report_myfeedback/tooltip', 'init');
require_login();
$dots = get_string('choosedots');
$userid = optional_param('userid', 0, PARAM_INT); // User id.
$yearview = optional_param('myselect', 0, PARAM_ALPHANUMEXT); // Academic year for archive.
$modview = optional_param_array('modselect', [], PARAM_NOTAGS); // The selected course for Mod tutor Dashboard.
$deptview = optional_param('deptselect', $dots, PARAM_NOTAGS); // For top level category on Dept admin dashboard.
$progview = optional_param('progselect', $dots, PARAM_NOTAGS); // For second level category on Dept admin dashboard.
$progmodview = optional_param('progmodselect', $dots, PARAM_NOTAGS); // For the course on the Dept admin dashboard.
$searchuser = optional_param('searchuser', '', PARAM_NOTAGS); // For the user search input on My students tab.
$searchusage = optional_param('searchusage', '', PARAM_NOTAGS); // For the search input on Usage dashboard.
if (($userid && $USER->id != $userid) || $modview) {
require_sesskey();
}
$sesskeyqs = '&sesskey=' . sesskey();
$_SESSION['viewmod'] = $modview;
if ($yearview) {
// Keep the academic year for the logged-in session.
$_SESSION['viewyear'] = $yearview;
}
$yrr = get_config('report_myfeedback'); // For the archive.
$livedomain = isset($yrr->livedomain) ? $yrr->livedomain : get_string('livedomaindefault', 'report_myfeedback');
$archivedomain = isset($yrr->archivedomain) ? $yrr->archivedomain : get_string('archivedomaindefault', 'report_myfeedback');
// Save filter selection to cookies so they are available to the JS form sort on future page loads.
if ($deptview != $dots) {
// Save the top level category for life of cookie.
setcookie('curdept', $deptview);
$_COOKIE['curdept'] = $deptview;
}
if ($progview != $dots) {
// Second level category on dept admin dashbard.
setcookie('curprog', $progview);
$_COOKIE['curprog'] = $progview;
}
if ($progmodview != $dots) {
// Course level.
setcookie('curmodprog', $progmodview);
$_COOKIE['curmodprog'] = $progmodview;
}
echo $OUTPUT->header();
// Initialize the report and set the database to get info from.
$report = new report_myfeedback\local\report();
$report->init();
$report->setup_external_db();
// Get a progress bar when report is getting info.
echo $OUTPUT->render_from_template('report_myfeedback/progress', [
'progressimg' => new moodle_url('/report/myfeedback/pix/progress.gif'),
]);
if (empty($userid)) {
$userid = $USER->id;
$usercontext = context_user::instance($userid, MUST_EXIST);
} else {
$usercontext = context_user::instance($userid, MUST_EXIST);
}
// Show the Module leader view or other view if the user is not looking at a student report.
$viewtutee = false;
if ($userid != $USER->id) {
$viewtutee = true;
}
$ucontext = context_user::instance($USER->id, MUST_EXIST);
// If user don't have the report capability they can't access it.
$user = $currentdb->get_record('user', ['id' => $userid, 'deleted' => 0]);
$userlinked = "<a href='" . $CFG->wwwroot . "/user/view.php?id=" . $userid . "'>" . $user->firstname .
" " . $user->lastname . "</a>";
$_SESSION['user_name'] = $user->firstname . ' ' . $user->lastname;
if (empty($user->username)) {
echo $OUTPUT->notification(get_string('userdeleted'));
die();
}
// Set user roles to determine what pages they can access:
// ... report/myfeedback:modtutor for tutors
// ... moodle/user:viewalldetails for personal tutor
// ... report/myfeedback:progadmin for dept admin
// ... report/myfeedback:student for students
// ... report/myfeedback:usage to see usage reports.
$moduletutor = false;
$personaltutor = false;
$progadmin = false;
$usage = false;
$prog = false;
$isstudent = false;
$ownreport = '';
$showstudentstab = true;
if ($userid != $USER->id) {
$ownreport = '<span class="ownreport"><a href=' . $CFG->wwwroot . '/report/myfeedback/index.php?userid='
. $USER->id . $sesskeyqs . '>' .
get_string('ownreport', 'report_myfeedback') . '</a></span>';
$showstudentstab = false;
}
$reportheading = get_string('dashboard', 'report_myfeedback') . get_string('for', 'report_myfeedback') . $user->firstname . ' ' .
$user->lastname . $ownreport;
if ($ptutorcap = $report->get_dashboard_capability($USER->id, 'report/myfeedback:personaltutor')) {
$personaltutor = true;
$reportheading = get_string('dashboard', 'report_myfeedback') . get_string('for', 'report_myfeedback')
. $user->firstname . ' ' . $user->lastname . get_string('personaltutorview', 'report_myfeedback') . $ownreport;
}
$ptutorid = $report->get_personal_tutor_id();
// Get the personal tutor details of the user.
$mytutorid = $report->get_my_personal_tutor($ptutorid, $usercontext->id);
// Added this here because when the dept admin is not accessing a student there is no course to get the context
// so the report_heading does not have the dept admin view.
if ($progadminid = $report->get_dashboard_capability($USER->id, 'report/myfeedback:progadmin')) {
$prog = true;
$reportheading = get_string('dashboard', 'report_myfeedback') . get_string('for', 'report_myfeedback')
. $user->firstname . ' ' . $user->lastname . get_string('progadminview', 'report_myfeedback') . $ownreport;
}
// Added this here because the usage report is not accessing a student so there is no course to get the context
// so the report_heading does not have the dept admin view.
if ($report->get_dashboard_capability($USER->id, 'report/myfeedback:usage')) {
$usage = true;
}
if ($student = $report->get_dashboard_capability($USER->id, 'report/myfeedback:student')) {
$isstudent = true;
}
// TODO - should we only do this if we are wanting to look at a student's report though?
// ... It would be redundant if we're just viewing our own report, or the usage dashboard.
// This capability is something that everyone who has been enrolled on a course has on that course.
// Here we want to check the courses and see if the logged in user has modtutor or prog admin capability
// for the user they are trying to look at so they can see their report.
$mods = get_user_capability_course(
'moodle/course:viewparticipants',
$userid,
$doanything = false,
$fields = 'shortname,visible'
);
if ($mods) {
foreach ($mods as $value) {
if ($value->visible) {
$coursecontext = context_course::instance($value->id);
if (has_capability('report/myfeedback:student', $coursecontext, $userid)) {
$isstudent = true; // For roles where they copy from default student role.
}
if (has_capability('report/myfeedback:modtutor', $coursecontext, $USER->id, $doanything = false)) {
$moduletutor = true;
$reportheading = get_string('dashboard', 'report_myfeedback') . get_string('for', 'report_myfeedback')
. $user->firstname . ' ' . $user->lastname . get_string('moduleleaderview', 'report_myfeedback') . $ownreport;
}
// If looking at a student account and you have progadmin capability then you are not barred from that user.
if (has_capability('report/myfeedback:progadmin', $coursecontext, $USER->id, $doanything = false)) {
$progadmin = true;
$reportheading = get_string('dashboard', 'report_myfeedback') . get_string('for', 'report_myfeedback')
. $user->firstname . ' ' . $user->lastname . get_string('progadminview', 'report_myfeedback') . $ownreport;
}
}
}
}
// If user doesn't have the moodle capability to see the specific user they can't access it.
$canaccessuser = false;
if ($progadmin || $moduletutor || $userid == $USER->id || has_capability('moodle/user:viewdetails', $usercontext)) {
// Has access to the user.
$canaccessuser = true;
} else {
echo $OUTPUT->notification(get_string('usernotavailable', 'error'));
die();
}
// Only log the action if the related user is changed in the session.
if (array_key_exists('viewed', $_SESSION)) {
if ($_SESSION['viewed'] != $userid) {
// Trigger a viewed event.
$event = \report_myfeedback\event\myfeedbackreport_viewed::create(
['context' => context_system::instance(0), 'relateduserid' => $userid]
);
$event->trigger();
$_SESSION['viewed'] = $userid;
}
} else {
$event = \report_myfeedback\event\myfeedbackreport_viewed::create(
['context' => context_system::instance(0), 'relateduserid' => $userid]
);
$event->trigger();
$_SESSION['viewed'] = $userid;
}
// Display the different tabs based on the logged-in user's roles.
$thistab = optional_param('currenttab', '', PARAM_TEXT);
if ((($thistab == 'overview' || $thistab == 'feedback' || $thistab == 'ptutor') && $userid == $USER->id) || $userid == $USER->id) {
$reportheading = get_string('dashboard', 'report_myfeedback') . get_string('for', 'report_myfeedback') . $user->firstname
. ' ' . $user->lastname . $ownreport;
}
if ($thistab == 'mytutees') {
$reportheading = get_string('tabs_mytutees', 'report_myfeedback') . $ownreport;
}
if ($thistab == 'tutor') {
$reportheading = get_string('tabs_tutor', 'report_myfeedback') . $ownreport;
}
if ($thistab == 'mymodules') {
$reportheading = get_string('tabs_mtutor', 'report_myfeedback') . $ownreport;
}
if ($thistab == 'progadmin') {
$reportheading = get_string('progadmin_dashboard', 'report_myfeedback') . $ownreport;
}
if ($thistab == 'usage') {
$reportheading = get_string('usage_dashboard', 'report_myfeedback') . $ownreport;
}
echo '<div class="heading">';
echo $OUTPUT->heading($reportheading);
echo '</div>';
// Get the year on the programme for the user from their profile.
// This requires that the below profile field is added.
$year = 1;
profile_load_data($user);
if (isset($user->profile_field_courseyear)) {
$year = $user->profile_field_courseyear;
}
// Tabs setup.
$currenttab = optional_param('currenttab', 'overview', PARAM_TEXT);
$thispageurl = 'index.php';
$tabs = [];
// If departmental admin and not viewing a tutee's report.
if ($prog && !$viewtutee) {
$tabs[] = new tabobject('progadmin',
new moodle_url($thispageurl, [
'userid' => $userid,
'currenttab' => 'progadmin',
'sesskey' => sesskey(),
]),
get_string('progadmin_dashboard', 'report_myfeedback')
);
}
// If tutor and not viewing a tutee's report.
if ($moduletutor && !$viewtutee) {
$tabs[] = new tabobject('mymodules',
new moodle_url($thispageurl, [
'userid' => $userid,
'currenttab' => 'mymodules',
'sesskey' => sesskey(),
]),
get_string('tabs_mtutor', 'report_myfeedback'));
}
// If personal tutor and not viewing a tutee's report.
if ($personaltutor && !$viewtutee) {
$tabs[] = new tabobject('tutor',
new moodle_url($thispageurl, [
'userid' => $userid,
'currenttab' => 'tutor',
'sesskey' => sesskey(),
]),
get_string('tabs_tutor', 'report_myfeedback')
);
}
if ($personaltutor && !$viewtutee) {
$currenttab = optional_param('currenttab', 'tutor', PARAM_TEXT);
}
if ($moduletutor && !$viewtutee) {
$currenttab = optional_param('currenttab', 'mymodules', PARAM_TEXT);
}
if ($prog && !$viewtutee) {
$currenttab = optional_param('currenttab', 'progadmin', PARAM_TEXT);
}
if ($usage && !$viewtutee) {
$currenttab = optional_param('currenttab', 'usage', PARAM_TEXT);
}
if ($showstudentstab) {
if ($prog || $moduletutor || $personaltutor) {
$tabs[] = new tabobject('mytutees',
new moodle_url($thispageurl, [
'userid' => $userid,
'currenttab' => 'mytutees',
'sesskey' => sesskey(),
]),
get_string('tabs_mytutees', 'report_myfeedback')
);
}
}
if ($viewtutee || $isstudent || is_siteadmin() || (!$prog && !$moduletutor && !$personaltutor && !$usage)) {
$tabs[] = new tabobject('overview',
new moodle_url($thispageurl, [
'userid' => $userid,
'currenttab' => 'overview',
'sesskey' => sesskey(),
]),
get_string('tabs_overview', 'report_myfeedback')
);
$tabs[] = new tabobject('feedback',
new moodle_url($thispageurl, [
'userid' => $userid,
'currenttab' => 'feedback',
'sesskey' => sesskey(),
]),
get_string('tabs_feedback', 'report_myfeedback')
);
if ($mytutorid && !$personaltutor) {
$tabs[] = new tabobject('ptutor',
new moodle_url($thispageurl, [
'userid' => $userid,
'currenttab' => 'ptutor',
'sesskey' => sesskey(),
]),
get_string('tabs_ptutor', 'report_myfeedback'));
}
$currenttab = optional_param('currenttab', 'overview', PARAM_TEXT);
}
// If usage and not viewing a tutee's report.
if ($usage && !$viewtutee) {
$tabs[] = new tabobject('usage',
new moodle_url($thispageurl, [
'userid' => $userid,
'currenttab' => 'usage',
'sesskey' => sesskey(),
]),
get_string('usage_dashboard', 'report_myfeedback')
);
}
echo $OUTPUT->tabtree($tabs, $currenttab);
// Stop the progress bar when page loads.
$PAGE->requires->js_call_amd('report_myfeedback/main', 'init');
switch ($currenttab) {
case 'overview':
require_once('student/overview.php');
break;
case 'feedback':
require_once('student/feedback.php');
break;
case 'ptutor':
require_once('student/personaltutor.php');
break;
case 'mytutees':
require_once('mytutees.php');
break;
case 'tutor':
require_once('tutor/personaltutoring.php');
break;
case 'mymodules':
require_once('tutor/mymodules.php');
break;
case 'shortname':
require_once('tutor/modules.php');
break;
case 'progadmin':
require_once('programmeadmin/index.php');
break;
case 'usage':
require_once('usage/index.php');
break;
default:
break;
}
// End of tabs setup.
echo $OUTPUT->footer();