mirror of
https://github.com/moodle/moodle.git
synced 2025-01-31 12:45:04 +01:00
Merge branch 'MDL-68955' of https://github.com/Chocolate-lightning/moodle
This commit is contained in:
commit
e5a2b74d8b
@ -60,6 +60,7 @@ $string['deleteallattempts'] = 'Delete all H5P attempts';
|
||||
$string['displayexport'] = 'Allow download';
|
||||
$string['displayembed'] = 'Embed button';
|
||||
$string['displaycopyright'] = 'Copyright button';
|
||||
$string['dnduploadh5pactivity'] = 'Add an H5P activity';
|
||||
$string['duration'] = 'Duration';
|
||||
$string['enabletracking'] = 'Enable attempt tracking';
|
||||
$string['false'] = 'False';
|
||||
|
@ -487,3 +487,57 @@ function h5pactivity_set_mainfile(stdClass $data): void {
|
||||
0, ['subdirs' => 0, 'maxfiles' => 1]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the ability to handle drag and drop file uploads
|
||||
* @return array containing details of the files / types the mod can handle
|
||||
*/
|
||||
function h5pactivity_dndupload_register(): array {
|
||||
return [
|
||||
'files' => [
|
||||
[
|
||||
'extension' => 'h5p',
|
||||
'message' => get_string('dnduploadh5pactivity', 'h5pactivity')
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a file that has been uploaded
|
||||
* @param object $uploadinfo details of the file / content that has been uploaded
|
||||
* @return int instance id of the newly created mod
|
||||
*/
|
||||
function h5pactivity_dndupload_handle($uploadinfo): int {
|
||||
global $CFG;
|
||||
|
||||
$context = context_module::instance($uploadinfo->coursemodule);
|
||||
file_save_draft_area_files($uploadinfo->draftitemid, $context->id, 'mod_h5pactivity', 'package', 0);
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($context->id, 'mod_h5pactivity', 'package', 0, 'sortorder, itemid, filepath, filename', false);
|
||||
$file = reset($files);
|
||||
|
||||
// Create a default h5pactivity object to pass to h5pactivity_add_instance()!
|
||||
$h5p = get_config('h5pactivity');
|
||||
$h5p->intro = '';
|
||||
$h5p->introformat = FORMAT_HTML;
|
||||
$h5p->course = $uploadinfo->course->id;
|
||||
$h5p->coursemodule = $uploadinfo->coursemodule;
|
||||
$h5p->grade = $CFG->gradepointdefault;
|
||||
|
||||
// Add some special handling for the H5P options checkboxes.
|
||||
$factory = new \core_h5p\factory();
|
||||
$core = $factory->get_core();
|
||||
if (isset($uploadinfo->displayopt)) {
|
||||
$config = (object) $uploadinfo->displayopt;
|
||||
} else {
|
||||
$config = \core_h5p\helper::decode_display_options($core);
|
||||
}
|
||||
$h5p->displayoptions = \core_h5p\helper::get_display_options($core, $config);
|
||||
|
||||
$h5p->cmidnumber = '';
|
||||
$h5p->name = $uploadinfo->displayname;
|
||||
$h5p->reference = $file->get_filename();
|
||||
|
||||
return h5pactivity_add_instance($h5p, null);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user