Skip to content

Commit

Permalink
MDL-67061 core_h5p: List installed contenttypes/libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
Bas Brands authored and Amaia Anabitarte committed Nov 9, 2019
1 parent f9db589 commit c43f99c
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 7 deletions.
4 changes: 2 additions & 2 deletions h5p/classes/framework.php
Expand Up @@ -510,8 +510,8 @@ public function loadLibraries() {
global $DB;

$results = $DB->get_records('h5p_libraries', [], 'title ASC, majorversion ASC, minorversion ASC',
'machinename AS machine_name, majorversion AS major_version, minorversion AS minor_version,
patchversion AS patch_version');
'id, machinename AS machine_name, majorversion AS major_version, minorversion AS minor_version,
patchversion AS patch_version, runnable, title');

$libraries = array();
foreach ($results as $library) {
Expand Down
17 changes: 16 additions & 1 deletion h5p/libraries.php
Expand Up @@ -43,6 +43,7 @@
echo $OUTPUT->box(get_string('librariesmanagerdescription', 'core_h5p'));

$form = new \core_h5p\form\uploadlibraries_form();
$h5pfactory = new \core_h5p\factory();
if ($data = $form->get_data()) {
require_sesskey();

Expand All @@ -54,7 +55,6 @@
$file = reset($files);

// Validate and save the H5P package.
$h5pfactory = new \core_h5p\factory();
// Because we are passing skipcontent = true to save_h5p function, the returning value is false in an error
// is encountered, null when successfully saving the package without creating the content.
if (\core_h5p\helper::save_h5p($h5pfactory, $file, new stdClass(), false, true) === false) {
Expand All @@ -64,4 +64,19 @@
}
}
$form->display();

// Load installed Libraries.
$framework = $h5pfactory->get_framework();
$libraries = $framework->loadLibraries();
$installed = [];
foreach ($libraries as $libraryname => $versions) {
foreach ($versions as $version) {
$installed[] = $version;
}
}

if (count($installed)) {
echo $OUTPUT->render_from_template('core_h5p/h5plibraries', (object)['contenttypes' => $installed]);
}

echo $OUTPUT->footer();
2 changes: 1 addition & 1 deletion h5p/templates/h5pdiv.mustache
Expand Up @@ -15,7 +15,7 @@
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template core_message/h5pdiv
@template core_h5p/h5pdiv
This template will render an div for h5p content.
Expand Down
2 changes: 1 addition & 1 deletion h5p/templates/h5pembed.mustache
Expand Up @@ -15,7 +15,7 @@
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template core_message/h5pembed
@template core_h5p/h5pembed
This template will render the embed code shown in the H5P content embed popup.
Expand Down
2 changes: 1 addition & 1 deletion h5p/templates/h5perror.mustache
Expand Up @@ -15,7 +15,7 @@
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template core_message/h5perror
@template core_h5p/h5perror
This template will render the embed code shown in the H5P content embed popup.
Expand Down
111 changes: 111 additions & 0 deletions h5p/templates/h5plibraries.mustache
@@ -0,0 +1,111 @@
{{!
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/>.
}}
{{!
@template core_h5p/h5plibraries
Example context (json):
{
"contenttypes": [
{
"title": "Accordion",
"major_version": 1,
"minor_version:": 0,
"patch_version:": 0,
"runnable": 1
},
{
"title": "Collage",
"major_version": 0,
"minor_version:": 3,
"patch_version:": 1,
"runnable": 1
},
{
"title": "FontAwesome",
"major_version": 4,
"minor_version:": 5,
"patch_version:": 0,
"runnable": 0
}
]
}

}}
<h3 class="mt-3">{{#str}} installedh5p, h5p {{/str}}</h3>

<ul class="nav nav-tabs mb-3" id="myTab" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="contenttypes-tab" data-toggle="tab" href="#contenttypes" role="tab" aria-controls="contenttypes" aria-selected="true">
{{#str}} installedcontenttypes, h5p {{/str}}
</a>
</li>
<li class="nav-item">
<a class="nav-link" id="libraries-tab" data-toggle="tab" href="#libraries" role="tab" aria-controls="libraries" aria-selected="false">
{{#str}} installedcontentlibraries, h5p {{/str}}
</a>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane fade show active" id="contenttypes" role="tabpanel" aria-labelledby="contenttypes-tab">
<div class="overview px-3 mb-5">
<table class="admintable generaltable" id="h5pcontenttypes">
<thead>
<tr>
<th>{{#str}}description, core{{/str}}</th>
<th>{{#str}}version, core{{/str}}</th>
</tr>
</thead>
<tbody>
{{#contenttypes}}
{{#runnable}}
<tr class="">
<td>
{{{ title }}}
</td>
<td>{{{ major_version }}}.{{{ minor_version }}}.{{{ patch_version }}}</td>
</tr>
{{/runnable}}
{{/contenttypes}}
</tbody>
</table>
</div>
</div>
<div class="tab-pane fade" id="libraries" role="tabpanel" aria-labelledby="libraries-tab">
<div class="overview px-3 mb-5">
<table class="admintable generaltable" id="h5pcontenttypes">
<thead>
<tr>
<th>{{#str}}description, core{{/str}}</th>
<th>{{#str}}version, core{{/str}}</th>
</tr>
</thead>
<tbody>
{{#contenttypes}}
{{^runnable}}
<tr class="">
<td>
{{{ title }}}
</td>
<td>{{{ major_version }}}.{{{ minor_version }}}.{{{ patch_version }}}</td>
</tr>
{{/runnable}}
{{/contenttypes}}
</tbody>
</table>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion h5p/templates/h5presize.mustache
Expand Up @@ -15,7 +15,7 @@
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template core_message/h5presize
@template core_h5p/h5presize
This template will render the resize JS code.
Expand Down
3 changes: 3 additions & 0 deletions lang/en/h5p.php
Expand Up @@ -86,6 +86,9 @@
$string['h5ppackage'] = 'H5P content type';
$string['h5ppackage_help'] = 'An H5P content type is a file with an H5P or ZIP extension containing all libraries required to display the content.';
$string['hideadvanced'] = 'Hide advanced';
$string['installedcontentlibraries'] = 'Installed H5P libraries';
$string['installedcontenttypes'] = 'Installed H5P content types';
$string['installedh5p'] = 'Installed H5P';
$string['invalidcontextid'] = 'H5P file not found (invalid contextid)';
$string['invalidfile'] = 'File "{$a->%filename}" not allowed. Only files with the following extensions are allowed: {$a->%files-allowed}.';
$string['invalidlanguagefile'] = 'Invalid language file {$a->%file} in library {$a->%library}';
Expand Down

0 comments on commit c43f99c

Please sign in to comment.