From a99dab944fe6c8da49dbd50c23b161b7a2b3e410 Mon Sep 17 00:00:00 2001 From: Victor Deniz Falcon Date: Tue, 28 Apr 2020 21:43:05 +0100 Subject: [PATCH] MDL-67810 core_contentbank: contentype_h5p modified to support add menu --- .../contenttype/h5p/classes/contenttype.php | 49 +++++++++++++++++-- contentbank/contenttype/h5p/db/access.php | 10 ++++ .../h5p/lang/en/contenttype_h5p.php | 2 + contentbank/contenttype/h5p/version.php | 2 +- 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/contentbank/contenttype/h5p/classes/contenttype.php b/contentbank/contenttype/h5p/classes/contenttype.php index d48941dfc70..1c1f2ea1df9 100644 --- a/contentbank/contenttype/h5p/classes/contenttype.php +++ b/contentbank/contenttype/h5p/classes/contenttype.php @@ -25,7 +25,11 @@ namespace contenttype_h5p; use core\event\contentbank_content_viewed; -use html_writer; +use stdClass; +use core_h5p\editor_ajax; +use core_h5p\file_storage; +use core_h5p\local\library\autoloader; +use H5PCore; /** * H5P content bank manager class @@ -65,8 +69,7 @@ class contenttype extends \core_contentbank\contenttype { $event->trigger(); $fileurl = $content->get_file_url(); - $html = html_writer::tag('h2', $content->get_name()); - $html .= \core_h5p\player::display($fileurl, new \stdClass(), true); + $html = \core_h5p\player::display($fileurl, new \stdClass(), true); return $html; } @@ -107,7 +110,7 @@ class contenttype extends \core_contentbank\contenttype { * @return array */ protected function get_implemented_features(): array { - return [self::CAN_UPLOAD]; + return [self::CAN_UPLOAD, self::CAN_EDIT]; } /** @@ -127,4 +130,42 @@ class contenttype extends \core_contentbank\contenttype { protected function is_access_allowed(): bool { return true; } + + /** + * Returns the list of different H5P content types the user can create. + * + * @return array An object for each H5P content type: + * - string typename: descriptive name of the H5P content type. + * - string typeeditorparams: params required by the H5P editor. + * - url typeicon: H5P content type icon. + */ + public function get_contenttype_types(): array { + // Get the H5P content types available. + autoloader::register(); + $editorajax = new editor_ajax(); + $h5pcontenttypes = $editorajax->getLatestLibraryVersions(); + + $types = []; + $h5pfilestorage = new file_storage(); + foreach ($h5pcontenttypes as $h5pcontenttype) { + $library = [ + 'name' => $h5pcontenttype->machine_name, + 'majorVersion' => $h5pcontenttype->major_version, + 'minorVersion' => $h5pcontenttype->minor_version, + ]; + $key = H5PCore::libraryToString($library); + $type = new stdClass(); + $type->key = $key; + $type->typename = $h5pcontenttype->title; + $type->typeeditorparams = 'library=' . $key; + $type->typeicon = $h5pfilestorage->get_icon_url( + $h5pcontenttype->id, + $h5pcontenttype->machine_name, + $h5pcontenttype->major_version, + $h5pcontenttype->minor_version); + $types[] = $type; + } + + return $types; + } } diff --git a/contentbank/contenttype/h5p/db/access.php b/contentbank/contenttype/h5p/db/access.php index 95db4aad8a2..97076ae751c 100644 --- a/contentbank/contenttype/h5p/db/access.php +++ b/contentbank/contenttype/h5p/db/access.php @@ -44,4 +44,14 @@ $capabilities = [ 'editingteacher' => CAP_ALLOW, ] ], + 'contenttype/h5p:useeditor' => [ + 'riskbitmask' => RISK_SPAM, + 'captype' => 'write', + 'contextlevel' => CONTEXT_COURSE, + 'archetypes' => [ + 'manager' => CAP_ALLOW, + 'coursecreator' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + ] + ], ]; diff --git a/contentbank/contenttype/h5p/lang/en/contenttype_h5p.php b/contentbank/contenttype/h5p/lang/en/contenttype_h5p.php index 179e80f2612..7e2e49e78ff 100644 --- a/contentbank/contenttype/h5p/lang/en/contenttype_h5p.php +++ b/contentbank/contenttype/h5p/lang/en/contenttype_h5p.php @@ -22,8 +22,10 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ +$string['description'] = 'H5P Interactive Content'; $string['pluginname'] = 'H5P'; $string['pluginname_help'] = 'Content bank to upload and share H5P content'; $string['privacy:metadata'] = 'The H5P content bank plugin does not store any personal data.'; $string['h5p:access'] = 'Access H5P content in the content bank'; $string['h5p:upload'] = 'Upload new H5P content'; +$string['h5p:useeditor'] = 'Create or edit content using the H5P editor'; diff --git a/contentbank/contenttype/h5p/version.php b/contentbank/contenttype/h5p/version.php index 548ef1345c1..fe0e68be844 100644 --- a/contentbank/contenttype/h5p/version.php +++ b/contentbank/contenttype/h5p/version.php @@ -24,6 +24,6 @@ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2020041500.00; // The current plugin version (Date: YYYYMMDDXX) +$plugin->version = 2020051500.01; // The current plugin version (Date: YYYYMMDDXX) $plugin->requires = 2020041500.00; // Requires this Moodle version $plugin->component = 'contenttype_h5p'; // Full name of the plugin (used for diagnostics).