MDL-67061 core_h5p: List installed contenttypes/libraries
authorBas Brands <bas@moodle.com>
Wed, 6 Nov 2019 09:58:35 +0000 (10:58 +0100)
committerAmaia Anabitarte <amaia@moodle.com>
Sat, 9 Nov 2019 10:11:07 +0000 (11:11 +0100)
h5p/classes/framework.php
h5p/libraries.php
h5p/templates/h5pdiv.mustache
h5p/templates/h5pembed.mustache
h5p/templates/h5perror.mustache
h5p/templates/h5plibraries.mustache [new file with mode: 0644]
h5p/templates/h5presize.mustache
lang/en/h5p.php

index e5293cf..3c63966 100644 (file)
@@ -510,8 +510,8 @@ class framework implements \H5PFrameworkInterface {
         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) {
index ad9c6e2..66b4e58 100644 (file)
@@ -43,6 +43,7 @@ echo $OUTPUT->heading($pagetitle);
 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();
 
@@ -54,7 +55,6 @@ if ($data = $form->get_data()) {
     $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) {
@@ -64,4 +64,19 @@ if ($data = $form->get_data()) {
     }
 }
 $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();
index 2e914d4..0f95bfc 100644 (file)
@@ -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.
 
index 7f36477..9f26126 100644 (file)
@@ -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.
 
index 76107c9..d455985 100644 (file)
@@ -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.
 
diff --git a/h5p/templates/h5plibraries.mustache b/h5p/templates/h5plibraries.mustache
new file mode 100644 (file)
index 0000000..e9c974d
--- /dev/null
@@ -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>
\ No newline at end of file
index 4400b60..fd58324 100644 (file)
@@ -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.
 
index 221c3c4..7f1decb 100644 (file)
@@ -86,6 +86,9 @@ $string['h5pmanage'] = 'Manage H5P content types';
 $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}';