-
Notifications
You must be signed in to change notification settings - Fork 4
/
lib.php
114 lines (107 loc) · 5.2 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
<?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/>.
/**
* Embedded questions progress report callback functions to integrate with Moodle.
*
* @package report_embedquestion
* @copyright 2019 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Standard callback to add the log report to the course-level navigation.
*
* @param navigation_node $navigation The navigation node to extend
* @param stdClass $course The course to object for the report
* @param context $context The context of the course
*/
function report_embedquestion_extend_navigation_course(navigation_node $navigation, stdClass $course, context $context) {
if (has_any_capability(['report/embedquestion:viewmyprogress', 'report/embedquestion:viewallprogress'], $context)) {
if (report_embedquestion\utils::user_can_see_report($context->id)) {
$navigation->add(get_string('pluginname', 'report_embedquestion'),
new moodle_url('/report/embedquestion/index.php', ['courseid' => $course->id]),
navigation_node::TYPE_SETTING, null, 'embedquestionreport', new pix_icon('i/report', ''));
}
}
}
/**
* Standard callback to add the log report to the activity-level navigation.
*
* @param navigation_node $navigation The navigation node to extend
* @param cm_info $cm
*/
function report_embedquestion_extend_navigation_module(navigation_node $navigation, cm_info $cm) {
$context = context_module::instance($cm->id);
if (has_any_capability(['report/embedquestion:viewmyprogress', 'report/embedquestion:viewallprogress'], $context)) {
if (report_embedquestion\utils::user_can_see_report($context->id)) {
$navigation->add(get_string('pluginname', 'report_embedquestion'),
new moodle_url('/report/embedquestion/activity.php', ['cmid' => $cm->id]),
navigation_node::TYPE_SETTING, null, 'embedquestionreport');
}
}
}
/**
* Standard callback to return a list of page types, used by the blocks UI.
*
* @param string $pagetype current page type
* @param context $parentcontext Block's parent context
* @param context $currentcontext Current context of block
* @return array a list of page types
*/
function report_embedquestion_page_type_list(string $pagetype, context $parentcontext, context $currentcontext): array {
return [
'*' => get_string('page-x', 'pagetype'),
'report-*' => get_string('page-report-x', 'pagetype'),
'report-embedquestion-*' => get_string('page-report-embedquestion-x', 'report_embedquestion'),
'report-embedquestion-activity' => get_string('page-report-embedquestion-activity', 'report_embedquestion'),
'report-embedquestion-index' => get_string('page-report-embedquestion-index', 'report_embedquestion'),
];
}
/**
* Called via pluginfile.php -> question_pluginfile to serve files belonging to
* a question in a question_attempt when that attempt an embedded question.
*
* @category files
* @param stdClass $givencourse course settings object
* @param stdClass $context context object
* @param string $component the name of the component we are serving files for.
* @param string $filearea the name of the file area.
* @param int $qubaid the question_usage this image belongs to.
* @param int $slot the relevant slot within the usage.
* @param array $args the remaining bits of the file path.
* @param bool $forcedownload whether the user must be forced to download the file.
* @param array $fileoptions additional options affecting the file serving
*/
function report_embedquestion_question_pluginfile($givencourse, $context, $component,
$filearea, $qubaid, $slot, $args, $forcedownload, $fileoptions) {
global $CFG;
require_once($CFG->dirroot . '/filter/embedquestion/lib.php');
filter_embedquestion_question_pluginfile($givencourse, $context, $component,
$filearea, $qubaid, $slot, $args, $forcedownload, $fileoptions);
}
/**
* Are any of these question used by any embedded question attempt?
*
* This is a callback used by the question engine, before it allows the question to be really deleted.
*
* @param int[] $questionids of question ids.
* @return bool whether any of these questions are used by any embedded question attempt.
*/
function report_embedquestion_questions_in_use($questionids) {
global $CFG;
require_once($CFG->libdir . '/questionlib.php');
return question_engine::questions_in_use($questionids,
new qubaid_join('{report_embedquestion_attempt} reqa', 'reqa.questionusageid'));
}