23
23
use file_exception ;
24
24
use moodle_exception ;
25
25
use moodle_url ;
26
+ use qtype_questionpy \constants ;
26
27
use qtype_questionpy \local \form \elements \file_upload_element ;
27
28
use qtype_questionpy \local \form \elements \file_upload_options ;
28
29
use qtype_questionpy_question ;
40
41
class options_file_service implements handles_qpy_url_type {
41
42
// TODO: Support subdirectories.
42
43
43
- /** @var string */
44
- public const FILEAREA_UPLOADS = 'options ' ;
45
-
46
-
47
44
/**
48
45
* Saves all the files in the given draft item to the permanent file area for the given question.
49
46
*
@@ -61,7 +58,7 @@ public function save_draft_area_files(int $contextid, int $questionid, int $user
61
58
$ existingfiles = $ fs ->get_area_files (
62
59
$ contextid ,
63
60
'qtype_questionpy ' ,
64
- self :: FILEAREA_UPLOADS ,
61
+ constants:: FILEAREA_OPTIONS ,
65
62
$ questionid ,
66
63
includedirs: false
67
64
);
@@ -85,18 +82,6 @@ public function save_draft_area_files(int $contextid, int $questionid, int $user
85
82
}
86
83
}
87
84
88
- /**
89
- * Deletes all files in the permanent file area of the given question.
90
- *
91
- * @param int $contextid
92
- * @param int $questionid
93
- * @return void
94
- */
95
- public function delete_all_saved_files_belonging_to_question (int $ contextid , int $ questionid ): void {
96
- $ fs = get_file_storage ();
97
- $ fs ->delete_area_files ($ contextid , 'qtype_questionpy ' , self ::FILEAREA_UPLOADS , $ questionid );
98
- }
99
-
100
85
/**
101
86
* Populates the given draft area with files listed in `$filemetas` and stored in the permanent question file area.
102
87
*
@@ -113,7 +98,7 @@ public function delete_all_saved_files_belonging_to_question(int $contextid, int
113
98
*/
114
99
public function prepare_draft_area (int $ contextid , int $ questionid , array $ filemetas , int $ userid , int $ draftitemid ): void {
115
100
$ fs = get_file_storage ();
116
- $ files = $ fs ->get_area_files ($ contextid , 'qtype_questionpy ' , self :: FILEAREA_UPLOADS , $ questionid , includedirs: false );
101
+ $ files = $ fs ->get_area_files ($ contextid , 'qtype_questionpy ' , constants:: FILEAREA_OPTIONS , $ questionid , includedirs: false );
117
102
118
103
foreach ($ filemetas as $ filemetadata ) {
119
104
$ matchingfiles = array_filter ($ files , fn ($ file ) => $ file ->get_filename () === $ filemetadata ->fileref );
@@ -223,7 +208,7 @@ public function check_upload_restrictions(
223
208
$ existingfiles = $ questionid ? $ fs ->get_area_files (
224
209
$ contextid ,
225
210
'qtype_questionpy ' ,
226
- self :: FILEAREA_UPLOADS ,
211
+ constants:: FILEAREA_OPTIONS ,
227
212
$ questionid ,
228
213
includedirs: false
229
214
) : [];
@@ -258,7 +243,7 @@ public function check_upload_restrictions(
258
243
*/
259
244
public function get_saved_file (int $ contextid , int $ questionid , string $ fileref ): ?stored_file {
260
245
$ fs = get_file_storage ();
261
- $ files = $ fs ->get_area_files ($ contextid , 'qtype_questionpy ' , self :: FILEAREA_UPLOADS , $ questionid , includedirs: false );
246
+ $ files = $ fs ->get_area_files ($ contextid , 'qtype_questionpy ' , constants:: FILEAREA_OPTIONS , $ questionid , includedirs: false );
262
247
foreach ($ files as $ file ) {
263
248
if ($ file ->get_filename () === $ fileref ) {
264
249
return $ file ;
@@ -296,7 +281,7 @@ public function resolve_qpy_url(string $path, qtype_questionpy_question $questio
296
281
return moodle_url::make_pluginfile_url (
297
282
$ question ->contextid ,
298
283
'qtype_questionpy ' ,
299
- self :: FILEAREA_UPLOADS ,
284
+ constants:: FILEAREA_OPTIONS ,
300
285
$ question ->id ,
301
286
'/ ' ,
302
287
$ path
0 commit comments