mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-68636 core_contentbank: Changing get_icon function
This commit is contained in:
parent
f9830e456a
commit
6fc3477cc5
7 changed files with 81 additions and 16 deletions
|
@ -181,12 +181,12 @@ abstract class contenttype {
|
||||||
/**
|
/**
|
||||||
* Returns the HTML code to render the icon for content bank contents.
|
* Returns the HTML code to render the icon for content bank contents.
|
||||||
*
|
*
|
||||||
* @param string $contentname The contentname to add as alt value to the icon.
|
* @param content $content The content to be displayed.
|
||||||
* @return string HTML code to render the icon
|
* @return string HTML code to render the icon
|
||||||
*/
|
*/
|
||||||
public function get_icon(string $contentname): string {
|
public function get_icon(content $content): string {
|
||||||
global $OUTPUT;
|
global $OUTPUT;
|
||||||
return $OUTPUT->pix_icon('f/unknown-64', $contentname, 'moodle', ['class' => 'iconsize-big']);
|
return $OUTPUT->image_url('f/unknown-64', 'moodle')->out(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -86,7 +86,7 @@ class bankcontent implements renderable, templatable {
|
||||||
$contentdata[] = array(
|
$contentdata[] = array(
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'link' => $contenttype->get_view_url($content),
|
'link' => $contenttype->get_view_url($content),
|
||||||
'icon' => $contenttype->get_icon($name)
|
'icon' => $contenttype->get_icon($content)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$data->contents = $contentdata;
|
$data->contents = $contentdata;
|
||||||
|
|
|
@ -73,12 +73,32 @@ class contenttype extends \core_contentbank\contenttype {
|
||||||
/**
|
/**
|
||||||
* Returns the HTML code to render the icon for H5P content types.
|
* Returns the HTML code to render the icon for H5P content types.
|
||||||
*
|
*
|
||||||
* @param string $contentname The contentname to add as alt value to the icon.
|
* @param content $content The content to be displayed.
|
||||||
* @return string HTML code to render the icon
|
* @return string HTML code to render the icon
|
||||||
*/
|
*/
|
||||||
public function get_icon(string $contentname): string {
|
public function get_icon(\core_contentbank\content $content): string {
|
||||||
global $OUTPUT;
|
global $OUTPUT, $DB;
|
||||||
return $OUTPUT->pix_icon('f/h5p-64', $contentname, 'moodle', ['class' => 'iconsize-big']);
|
|
||||||
|
$iconurl = $OUTPUT->image_url('f/h5p-64', 'moodle')->out(false);
|
||||||
|
$file = $content->get_file();
|
||||||
|
if (!empty($file)) {
|
||||||
|
$h5p = \core_h5p\api::get_content_from_pathnamehash($file->get_pathnamehash());
|
||||||
|
if (!empty($h5p)) {
|
||||||
|
\core_h5p\local\library\autoloader::register();
|
||||||
|
if ($h5plib = $DB->get_record('h5p_libraries', ['id' => $h5p->mainlibraryid])) {
|
||||||
|
$h5pfilestorage = new \core_h5p\file_storage();
|
||||||
|
$h5picon = $h5pfilestorage->get_icon_url(
|
||||||
|
$h5plib->id,
|
||||||
|
$h5plib->machinename,
|
||||||
|
$h5plib->majorversion,
|
||||||
|
$h5plib->minorversion);
|
||||||
|
if (!empty($h5picon)) {
|
||||||
|
$iconurl = $h5picon;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $iconurl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -105,4 +105,46 @@ class contenttype_h5p_contenttype_plugin_testcase extends advanced_testcase {
|
||||||
$this->assertFalse($coursetype->can_upload());
|
$this->assertFalse($coursetype->can_upload());
|
||||||
$this->assertFalse($systemtype->can_upload());
|
$this->assertFalse($systemtype->can_upload());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests get_icon result.
|
||||||
|
*
|
||||||
|
* @covers ::get_icon
|
||||||
|
*/
|
||||||
|
public function test_get_icon() {
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
$this->resetAfterTest();
|
||||||
|
$systemcontext = context_system::instance();
|
||||||
|
$this->setAdminUser();
|
||||||
|
$contenttype = new contenttype_h5p\contenttype($systemcontext);
|
||||||
|
|
||||||
|
// Add an H5P fill the blanks file to the content bank.
|
||||||
|
$filepath = $CFG->dirroot . '/h5p/tests/fixtures/filltheblanks.h5p';
|
||||||
|
$generator = $this->getDataGenerator()->get_plugin_generator('core_contentbank');
|
||||||
|
$contents = $generator->generate_contentbank_data('contenttype_h5p', 1, 0, $systemcontext, true, $filepath);
|
||||||
|
$filltheblanks = array_shift($contents);
|
||||||
|
|
||||||
|
// Add an H5P find the words file to the content bank.
|
||||||
|
$filepath = $CFG->dirroot . '/h5p/tests/fixtures/find-the-words.h5p';
|
||||||
|
$generator = $this->getDataGenerator()->get_plugin_generator('core_contentbank');
|
||||||
|
$contents = $generator->generate_contentbank_data('contenttype_h5p', 1, 0, $systemcontext, true, $filepath);
|
||||||
|
$findethewords = array_shift($contents);
|
||||||
|
|
||||||
|
// Check before deploying the icon for both contents is the same: default one.
|
||||||
|
// Because we don't know specific H5P content type yet.
|
||||||
|
$defaulticon = $contenttype->get_icon($filltheblanks);
|
||||||
|
$this->assertEquals($defaulticon, $contenttype->get_icon($findethewords));
|
||||||
|
$this->assertContains('h5p', $defaulticon);
|
||||||
|
|
||||||
|
// Deploy one of the contents though the player to create the H5P DB entries and know specific content type.
|
||||||
|
$h5pplayer = new \core_h5p\player($findethewords->get_file_url(), new \stdClass(), true);
|
||||||
|
$h5pplayer->add_assets_to_page();
|
||||||
|
$h5pplayer->output();
|
||||||
|
|
||||||
|
// Once the H5P has been deployed, we know the specific H5P content type, so the icon returned is not default one.
|
||||||
|
$findicon = $contenttype->get_icon($findethewords);
|
||||||
|
$this->assertNotEquals($defaulticon, $findicon);
|
||||||
|
$this->assertContains('find', $findicon, '', true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,11 +23,11 @@
|
||||||
{
|
{
|
||||||
"name": "accordion.h5p",
|
"name": "accordion.h5p",
|
||||||
"link": "http://something/contentbank/contenttype/h5p/view.php?url=http://something/pluginfile.php/1/contentbank/public/accordion.h5p",
|
"link": "http://something/contentbank/contenttype/h5p/view.php?url=http://something/pluginfile.php/1/contentbank/public/accordion.h5p",
|
||||||
"icon" : "<img class='icon iconsize-big' alt='accordion.h5p' aria-hidden='true' src='http://something/theme/image.php/boost/core/1581597850/f/h5p-64'>"
|
"icon" : "http://something/theme/image.php/boost/core/1581597850/f/h5p-64"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "resume.pdf",
|
"name": "resume.pdf",
|
||||||
"icon": "<img class='icon iconsize-big' alt='resume.pdf' aria-hidden='true' src='http://something/theme/image.php/boost/core/1584597850/f/pdf-64'>"
|
"icon": "http://something/theme/image.php/boost/core/1584597850/f/pdf-64"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"tools": [
|
"tools": [
|
||||||
|
@ -65,7 +65,7 @@
|
||||||
<div class="cb-file position-relative mb-2" data-file="{{{name}}}">
|
<div class="cb-file position-relative mb-2" data-file="{{{name}}}">
|
||||||
<div class="p-2">
|
<div class="p-2">
|
||||||
<div class="cb-thumbnail mb-1 text-center">
|
<div class="cb-thumbnail mb-1 text-center">
|
||||||
{{{ icon }}}
|
<img class="icon iconsize-big" alt="{{{name}}}" title="{{{name}}}" src="{{{ icon }}}">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{#link}}
|
{{#link}}
|
||||||
|
|
|
@ -106,7 +106,10 @@ class core_contenttype_contenttype_testcase extends \advanced_testcase {
|
||||||
|
|
||||||
$systemcontext = \context_system::instance();
|
$systemcontext = \context_system::instance();
|
||||||
$testable = new contenttype($systemcontext);
|
$testable = new contenttype($systemcontext);
|
||||||
$icon = $testable->get_icon('new content');
|
$record = new stdClass();
|
||||||
|
$record->name = 'New content';
|
||||||
|
$content = $testable->create_content($record);
|
||||||
|
$icon = $testable->get_icon($content);
|
||||||
$this->assertContains('archive', $icon);
|
$this->assertContains('archive', $icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ class contenttype extends \core_contentbank\contenttype {
|
||||||
* @param content $content The content to delete.
|
* @param content $content The content to delete.
|
||||||
* @return string URL where to visualize the given content.
|
* @return string URL where to visualize the given content.
|
||||||
*/
|
*/
|
||||||
public function get_view_url(content $content): string {
|
public function get_view_url(\core_contentbank\content $content): string {
|
||||||
$fileurl = $this->get_file_url($content->get_id());
|
$fileurl = $this->get_file_url($content->get_id());
|
||||||
$url = $fileurl."?forcedownload=1";
|
$url = $fileurl."?forcedownload=1";
|
||||||
|
|
||||||
|
@ -53,13 +53,13 @@ class contenttype extends \core_contentbank\contenttype {
|
||||||
/**
|
/**
|
||||||
* Returns the HTML code to render the icon for content bank contents.
|
* Returns the HTML code to render the icon for content bank contents.
|
||||||
*
|
*
|
||||||
* @param string $contentname The contentname to add as alt value to the icon.
|
* @param content $content The content to delete.
|
||||||
* @return string HTML code to render the icon
|
* @return string HTML code to render the icon
|
||||||
*/
|
*/
|
||||||
public function get_icon(string $contentname): string {
|
public function get_icon(\core_contentbank\content $content): string {
|
||||||
global $OUTPUT;
|
global $OUTPUT;
|
||||||
|
|
||||||
return $OUTPUT->pix_icon('f/archive-64', $contentname, 'moodle', ['class' => 'iconsize-big']);
|
return $OUTPUT->image_url('f/archive-64', 'moodle')->out(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue