diff --git a/h5p/classes/file_storage.php b/h5p/classes/file_storage.php index 4af223480c0..ee2f215d03b 100644 --- a/h5p/classes/file_storage.php +++ b/h5p/classes/file_storage.php @@ -45,6 +45,8 @@ class file_storage implements \H5PFileStorage { public const CACHED_ASSETS_FILEAREA = 'cachedassets'; /** The export file area */ public const EXPORT_FILEAREA = 'export'; + /** The icon filename */ + public const ICON_FILENAME = 'icon.svg'; /** * @var \context $context Currently we use the system context everywhere. @@ -347,6 +349,40 @@ class file_storage implements \H5PFileStorage { // This is to be implemented when the h5p editor is introduced / created. } + /** + * Get the file URL or given library and then return it. + * + * @param int $itemid + * @param string $machinename + * @param int $majorversion + * @param int $minorversion + * @return string url or false if the file doesn't exist + */ + public function get_icon_url(int $itemid, string $machinename, int $majorversion, int $minorversion) { + $filepath = '/' . "{$machinename}-{$majorversion}.{$minorversion}" . '/'; + if ($file = $this->fs->get_file( + $this->context->id, + self::COMPONENT, + self::LIBRARY_FILEAREA, + $itemid, + $filepath, + self::ICON_FILENAME) + ) { + $iconurl = \moodle_url::make_pluginfile_url( + $this->context->id, + self::COMPONENT, + self::LIBRARY_FILEAREA, + $itemid, + $filepath, + $file->get_filename()); + + // Return image URL. + return $iconurl->out(); + } + + return false; + } + /** * Checks to see if content has the given file. * Used when saving content. diff --git a/h5p/libraries.php b/h5p/libraries.php index 66b4e581fbe..bffce142d14 100644 --- a/h5p/libraries.php +++ b/h5p/libraries.php @@ -67,10 +67,17 @@ $form->display(); // Load installed Libraries. $framework = $h5pfactory->get_framework(); +$filestorage = $h5pfactory->get_core()->fs; $libraries = $framework->loadLibraries(); $installed = []; foreach ($libraries as $libraryname => $versions) { foreach ($versions as $version) { + $version->icon = $filestorage->get_icon_url( + $version->id, + $version->machine_name, + $version->major_version, + $version->minor_version + ); $installed[] = $version; } } diff --git a/h5p/templates/h5plibraries.mustache b/h5p/templates/h5plibraries.mustache index 3ac8ee5436c..a6125fb0eee 100644 --- a/h5p/templates/h5plibraries.mustache +++ b/h5p/templates/h5plibraries.mustache @@ -25,7 +25,8 @@ "major_version": 1, "minor_version:": 0, "patch_version:": 0, - "runnable": 1 + "runnable": 1, + "icon": "icon.svg" }, { "title": "Collage", @@ -39,7 +40,8 @@ "major_version": 4, "minor_version:": 5, "patch_version:": 0, - "runnable": 0 + "runnable": 1, + "icon": "icon.svg" } ] } @@ -74,6 +76,14 @@ {{#runnable}}