2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Manage H5P libraries settings page.
21 * @copyright 2019 Amaia Anabitarte <amaia@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 require_once(__DIR__
. '/../config.php');
27 require_login(null, false);
29 $context = context_system
::instance();
30 require_capability('moodle/h5p:updatelibraries', $context);
32 $pagetitle = get_string('h5pmanage', 'core_h5p');
33 $url = new \
moodle_url("/h5p/libraries.php");
35 $PAGE->set_context($context);
37 $PAGE->set_title($pagetitle);
38 $PAGE->set_pagelayout('admin');
39 $PAGE->set_heading($pagetitle);
41 echo $OUTPUT->header();
42 echo $OUTPUT->heading($pagetitle);
43 echo $OUTPUT->box(get_string('librariesmanagerdescription', 'core_h5p'));
45 $form = new \core_h5p\form\
uploadlibraries_form();
46 if ($data = $form->get_data()) {
49 // Get the file from the users draft area.
50 $usercontext = context_user
::instance($USER->id
);
51 $fs = get_file_storage();
52 $files = $fs->get_area_files($usercontext->id
, 'user', 'draft', $data->h5ppackage
, 'id',
54 $file = reset($files);
56 // Validate and save the H5P package.
57 $h5pfactory = new \core_h5p\factory
();
58 // Because we are passing skipcontent = true to save_h5p function, the returning value is false in an error
59 // is encountered, null when successfully saving the package without creating the content.
60 if (\core_h5p\helper
::save_h5p($h5pfactory, $file, new stdClass(), false, true) === false) {
61 echo $OUTPUT->notification(get_string('invalidpackage', 'core_h5p'), 'error');
63 echo $OUTPUT->notification(get_string('uploadsuccess', 'core_h5p'), 'success');
67 echo $OUTPUT->footer();