-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.php
More file actions
136 lines (124 loc) · 4.55 KB
/
lib.php
File metadata and controls
136 lines (124 loc) · 4.55 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
<?php
// This file is part of the QuestionPy Moodle plugin - https://questionpy.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/>.
/**
* This file contains the moodle hooks for the QuestionPy submission plugin.
*
* @package assignsubmission_qpy
* @copyright 2025 Martin Gauk, TU Berlin, innoCampus - www.questionpy.org
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Serves assignment submissions and other files.
*
* @param mixed $course course or id of the course
* @param mixed $cm course module or id of the course module
* @param context $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @param array $options - List of options affecting file serving.
* @return bool false if file not found, does not return if found - just send the file
* @throws coding_exception
* @throws dml_exception
* @throws moodle_exception
* @throws require_login_exception
*/
function assignsubmission_qpy_pluginfile(
$course,
$cm,
context $context,
$filearea,
$args,
$forcedownload,
array $options = []
): bool {
// Almost entirely identical to assignsubmission_file_pluginfile.
global $DB;
$itemid = (int)array_shift($args);
$submission = $DB->get_record(
'assign_submission',
['id' => $itemid],
'userid, assignment, groupid',
MUST_EXIST
);
\assignsubmission_qpy\helper::get_assignment_and_check_access($context, $cm, $course, $submission);
$relativepath = implode('/', $args);
$fullpath = "/{$context->id}/assignsubmission_qpy/$filearea/$itemid/$relativepath";
$fs = get_file_storage();
if (!($file = $fs->get_file_by_hash(sha1($fullpath))) || $file->is_directory()) {
return false;
}
// Download MUST be forced - security!
send_stored_file($file, 0, 0, true, $options);
}
/**
* Serves files within question attempts.
*
* Called via pluginfile.php -> question_pluginfile to serve files belonging to
* a question in a question_attempt when that attempt is a quiz attempt.
*
* @param stdClass $course course settings object
* @param \core\context $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 attempt usage id.
* @param int $slot the id of a question in this quiz attempt.
* @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 $options additional options affecting the file serving
* @return bool false if file not found, does not return if found - justsend the file
* @package mod_quiz
* @category files
*/
function assignsubmission_qpy_question_pluginfile(
$course,
$context,
$component,
$filearea,
$qubaid,
$slot,
$args,
$forcedownload,
array $options = []
): bool {
global $DB;
$submission = $DB->get_record_sql(
'SELECT s.*
FROM {assignsubmission_qpy} q
JOIN {assign_submission} s ON (s.id = q.submission)
WHERE q.questionusageid = :usageid',
['usageid' => $qubaid],
MUST_EXIST
);
$assign = \assignsubmission_qpy\helper::get_assignment_and_check_access($context, null, $course, $submission);
$quba = \question_engine::load_questions_usage_by_activity($qubaid);
$displayoptions = \assignsubmission_qpy\helper::get_question_display_options(
$assign,
$submission,
review: true,
mayshowhistory: false
);
if (!$quba->check_file_access($slot, $displayoptions, $component, $filearea, $args, $forcedownload)) {
send_file_not_found();
}
$fs = get_file_storage();
$relativepath = implode('/', $args);
$fullpath = "/$context->id/$component/$filearea/$relativepath";
if (!($file = $fs->get_file_by_hash(sha1($fullpath))) || $file->is_directory()) {
return false;
}
send_stored_file($file, 0, 0, $forcedownload, $options);
}