mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 12:32:08 +02:00
MDL-67060 core_h5p: Improving H5P libraries list
This commit is contained in:
parent
4e90332195
commit
d3ee08dba3
@ -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.
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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}}
|
||||
<tr class="">
|
||||
<td>
|
||||
{{#icon}}
|
||||
<img alt=""
|
||||
class="icon iconsize-big"
|
||||
src="{{{ icon }}}">
|
||||
{{/icon}}
|
||||
{{^icon}}
|
||||
{{#pix}} b/h5p_library, core {{/pix}}
|
||||
{{/icon}}
|
||||
{{{ title }}}
|
||||
</td>
|
||||
<td>{{{ major_version }}}.{{{ minor_version }}}.{{{ patch_version }}}</td>
|
||||
|
@ -27,6 +27,7 @@ namespace core_h5p\local\tests;
|
||||
|
||||
use core_h5p\file_storage;
|
||||
use core_h5p\autoloader;
|
||||
use core_h5p\helper;
|
||||
use file_archive;
|
||||
use zip_archive;
|
||||
|
||||
@ -553,4 +554,67 @@ class h5p_file_storage_testcase extends \advanced_testcase {
|
||||
file_storage::LIBRARY_FILEAREA);
|
||||
$this->assertCount(7, $files);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_icon_url() function behaviour.
|
||||
*
|
||||
* @dataProvider get_icon_url_provider
|
||||
* @param string $filename The name of the H5P file to load.
|
||||
* @param bool $expected Whether the icon should exist or not.
|
||||
*/
|
||||
public function test_get_icon_url(string $filename, bool $expected): void {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
$factory = new \core_h5p\factory();
|
||||
|
||||
$admin = get_admin();
|
||||
|
||||
// Prepare a valid .H5P file.
|
||||
$path = __DIR__ . '/fixtures/'.$filename;
|
||||
|
||||
// Libraries can be updated when the file has been created by admin, even when the current user is not the admin.
|
||||
$this->setUser($admin);
|
||||
$file = helper::create_fake_stored_file_from_path($path, (int)$admin->id);
|
||||
$factory->get_framework()->set_file($file);
|
||||
$config = (object)[
|
||||
'frame' => 1,
|
||||
'export' => 1,
|
||||
'embed' => 0,
|
||||
'copyright' => 0,
|
||||
];
|
||||
|
||||
$h5pid = helper::save_h5p($factory, $file, $config);
|
||||
$h5p = $DB->get_record('h5p', ['id' => $h5pid]);
|
||||
$h5plib = $DB->get_record('h5p_libraries', ['id' => $h5p->mainlibraryid]);
|
||||
$iconurl = $this->h5p_file_storage->get_icon_url(
|
||||
$h5plib->id,
|
||||
$h5plib->machinename,
|
||||
$h5plib->majorversion,
|
||||
$h5plib->minorversion
|
||||
);
|
||||
if ($expected) {
|
||||
$this->assertContains(file_storage::ICON_FILENAME, $iconurl);
|
||||
} else {
|
||||
$this->assertFalse($iconurl);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for test_get_icon_url().
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_icon_url_provider(): array {
|
||||
return [
|
||||
'Icon included' => [
|
||||
'filltheblanks.h5p',
|
||||
true,
|
||||
],
|
||||
'Icon not included' => [
|
||||
'greeting-card-887.h5p',
|
||||
false,
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
71
pix/b/h5p_library.svg
Normal file
71
pix/b/h5p_library.svg
Normal file
@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xml:space="preserve"
|
||||
style="enable-background:new 0 0 400 225;"
|
||||
viewBox="0 0 400 225"
|
||||
y="0px"
|
||||
x="0px"
|
||||
id="Layer_1"
|
||||
version="1.1"><metadata
|
||||
id="metadata37"><rdf:RDF><cc:Work
|
||||
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title>tweeter feed</dc:title></cc:Work></rdf:RDF></metadata><defs
|
||||
id="defs35">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</defs>
|
||||
<style
|
||||
id="style2"
|
||||
type="text/css">
|
||||
.st0{fill:none;}
|
||||
.st1{fill:#8DB7E2;}
|
||||
.st2{fill:#FFFFFF;}
|
||||
.st3{opacity:0.2;}
|
||||
.st4{fill:#2574A9;}
|
||||
.st5{fill:#2376C1;}
|
||||
</style>
|
||||
<title
|
||||
id="title4">tweeter feed</title>
|
||||
<g
|
||||
transform="translate(7.6293945e-6)"
|
||||
id="g879"><rect
|
||||
style="fill:#ffffff;fill-opacity:1"
|
||||
id="rect873"
|
||||
width="186.86441"
|
||||
height="186.86441"
|
||||
x="106.56779"
|
||||
y="19.067795"
|
||||
rx="24.788136"
|
||||
ry="24.788136" /><g
|
||||
id="g848"
|
||||
transform="matrix(0.4649826,0,0,0.4649826,119.81375,77.393814)"
|
||||
style="fill:#2e5fbf;fill-opacity:1">
|
||||
<path
|
||||
id="path844"
|
||||
d="M 325.7,14.7 C 317.6,6.9 305.3,3 289,3 H 245.5 234 v 31 h -66 l -5.4,22.2 c 4.5,-2.1 10.9,-4.2 15.3,-5.3 4.4,-1.1 8.8,-0.9 13.1,-0.9 14.6,0 26.5,4.5 35.6,13.3 9.1,8.8 13.6,20 13.6,33.4 0,9.4 -2.3,18.5 -7,27.2 -4.7,8.7 -11.3,15.4 -19.9,20 -3.1,1.6 -6.5,3.1 -10.2,4.1 H 245.5 259 V 95 h 25 c 18.2,0 31.7,-4.2 40.6,-12.5 8.9,-8.3 13.3,-19.9 13.3,-34.6 0,-14.3 -4.1,-25.4 -12.2,-33.2 z m -37,45.9 c -3.5,3 -9.6,4.4 -18.3,4.4 H 259 V 33 h 13.2 c 8.4,0 14.2,1.5 17.2,4.7 3.1,3.2 4.6,6.9 4.6,11.5 0,4.7 -1.8,8.4 -5.3,11.4 z"
|
||||
style="fill:#2e5fbf;fill-opacity:1" />
|
||||
<path
|
||||
id="path846"
|
||||
d="m 176.5,76.3 c -7.9,0 -14.7,4.6 -18,11.2 L 119,81.9 136.8,3 H 113.2 101 V 65 H 51 V 3 H 7 V 148 H 51 V 95 h 50 v 53 h 12.2 42 c -6.7,-2 -12.5,-4.6 -17.2,-8.1 -4.8,-3.6 -8.7,-7.7 -11.7,-12.3 -3,-4.6 -5.3,-9.7 -7.3,-16.5 l 39.6,-5.7 c 3.3,6.6 10.1,11.1 17.9,11.1 11.1,0 20.1,-9 20.1,-20.1 0,-11.1 -9.1,-20.1 -20.1,-20.1 z"
|
||||
style="fill:#2e5fbf;fill-opacity:1" />
|
||||
</g></g><rect
|
||||
style="fill:none"
|
||||
y="0"
|
||||
x="0"
|
||||
id="rect6"
|
||||
height="225"
|
||||
width="400"
|
||||
class="st0" />
|
||||
</svg>
|
After Width: | Height: | Size: 2.4 KiB |
Loading…
x
Reference in New Issue
Block a user