-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib.php
108 lines (90 loc) · 3.34 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
<?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/>.
/**
* Availability plugin for integration with Examus proctoring system.
*
* @package availability_examus
* @copyright 2019-2020 Maksim Burnin <[email protected]>
* @copyright based on work by 2017 Max Pomazuev
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use availability_examus\condition;
use availability_examus\state;
/**
* Hooks into navbar rendering, add link to log, if user has such capability
* @return string
*/
function availability_examus_render_navbar_output() {
global $PAGE;
$context = context_system::instance();
if (!has_capability('availability/examus:logaccess', $context)) {
return '';
}
$title = get_string('log_section', 'availability_examus');
$url = new \moodle_url('/availability/condition/examus/index.php');
$icon = new \pix_icon('i/log', '');
$node = navigation_node::create($title, $url, navigation_node::TYPE_CUSTOM, null, null, $icon);
$PAGE->flatnav->add($node);
return '';
}
/**
* Hooks into head rendering. Adds proctoring fader/shade and accompanying javascript
* This is used to prevent users from seeing questions before it is known that
* attempt is viewed thorough Examus WebApp
*
* @return string
*/
function availability_examus_before_standard_html_head() {
global $DB, $USER;
if (isset(state::$attempt['attempt_id'])) {
$attemptid = state::$attempt['attempt_id'];
$attempt = $DB->get_record('quiz_attempts', ['id' => $attemptid]);
if (!$attempt || $attempt->state != 'inprogress') {
return '';
}
} else {
return '';
}
$cmid = state::$attempt['cm_id'];
$courseid = state::$attempt['course_id'];
$modinfo = get_fast_modinfo($courseid);
$cm = $modinfo->get_cm($cmid);
if (!condition::user_in_proctored_groups($cm, $USER->id)) {
return '';
}
$condition = condition::get_examus_condition($cm);
if (!$condition) {
return '';
}
if ($condition->noprotection) {
return '';
}
// Check that theres more rules, which pass.
// If we have no examus accesstoken (condition fails),
// but the module is still avalible, this means we should not
// enfoce proctoring.
$availibilityinfo = new \core_availability\info_module($cm);
$reason = '';
$isavailiblegeneral = $availibilityinfo->is_available($reason, false, $USER->id);
$isavailibleexamus = condition::is_available_internal($courseid, $cm->id, $USER->id);
if (!$isavailibleexamus && $isavailiblegeneral) {
return '';
}
ob_start();
include(dirname(__FILE__).'/proctoring_fader.php');
$output = ob_get_clean();
return $output;
}