Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.2.x will end 22 April 2024 (12 months).
  • Bug fixes for security issues in 4.2.x will end 7 October 2024 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.1.x is supported too.

Differences Between: [Versions 310 and 402] [Versions 311 and 402] [Versions 39 and 402] [Versions 400 and 402] [Versions 401 and 402]

Contains helper class for the H5P area.

Copyright: 2019 Sara Arjona <sara@moodle.com>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 509 lines (20 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: helper  - X-Ref

Helper class for the H5P area.

save_h5p(factory $factory, \stored_file $file, \stdClass $config, bool $onlyupdatelibs = false,bool $skipcontent = false)   X-Ref
Store an H5P file.

param: factory $factory The \core_h5p\factory object
param: \stored_file $file Moodle file instance
param: \stdClass $config Button options config
param: bool $onlyupdatelibs Whether new libraries can be installed or only the existing ones can be updated
param: bool $skipcontent Should the content be skipped (so only the libraries will be saved)?
return: int|false|null The H5P identifier or null if there is an error when saving or false if it's not a valid H5P package

get_messages(\stdClass $messages, factory $factory)   X-Ref
Get the error messages stored in our H5P framework.

param: \stdClass $messages The error, exception and info messages, raised while preparing and running an H5P content.
param: factory $factory The \core_h5p\factory object
return: \stdClass with framework error messages.

get_display_options(core $core, \stdClass $config)   X-Ref
Get the representation of display options as int.

param: core $core The \core_h5p\core object
param: stdClass $config Button options config
return: int The representation of display options as int

decode_display_options(core $core, int $displayint = null)   X-Ref
Convert the int representation of display options into stdClass

param: core $core The \core_h5p\core object
param: int $displayint integer value representing display options
return: int The representation of display options as int

can_deploy_package(\stored_file $file)   X-Ref
Checks if the author of the .h5p file is "trustable". If the file hasn't been uploaded by a user with the
required capability, the content won't be deployed.

param: stored_file $file The .h5p file to be deployed
return: bool Returns true if the file can be deployed, false otherwise.

can_update_library(\stored_file $file)   X-Ref
Checks if the content-type libraries can be upgraded.
The H5P content-type libraries can only be upgraded if the author of the .h5p file can manage content-types or if all the
content-types exist, to avoid users without the required capability to upload malicious content.

param: stored_file $file The .h5p file to be deployed
return: bool Returns true if the content-type libraries can be created/updated, false otherwise.

create_fake_stored_file_from_path(string $filepath, int $userid = 0,\context $context = null)   X-Ref
Convenience to take a fixture test file and create a stored_file.

param: string $filepath The filepath of the file
param: int   $userid  The author of the file
param: \context $context The context where the file will be created
return: \stored_file The file created

get_h5p_tools_info()   X-Ref
Get information about different H5P tools and their status.

return: array Data to render by the template

convert_info_into_array(string $tool,\moodle_url $link,int $status,string $statusaction = '')   X-Ref
Convert information into needed mustache template data array

param: string $tool The name of the tool
param: \moodle_url $link The URL to management page
param: int $status The current status of the tool
param: string $statusaction A link to 'Run now' option for the task
return: array

get_cache_buster()   X-Ref
Get a query string with the theme revision number to include at the end
of URLs. This is used to force the browser to reload the asset when the
theme caches are cleared.

return: string

get_core_settings(?string $component = null)   X-Ref
Get the settings needed by the H5P library.

param: string|null $component
return: array The settings.

get_core_assets(?string $component = null)   X-Ref
Get the core H5P assets, including all core H5P JavaScript and CSS.

param: string|null $component
return: Array core H5P assets.

get_cache_librarykey(string $library)   X-Ref
Prepare the library name to be used as a cache key (remove whitespaces and replace dots to underscores).

param: string $library Library name.
return: string Library name in a cache simple key format (a-zA-Z0-9_).

parse_js_array(string $jscontent)   X-Ref
Parse a JS array to a PHP array.

param: string $jscontent The JS array to parse to PHP array.
return: array The JS array converted to PHP array.

get_export_info(string $exportfilename, \moodle_url $url = null, ?factory $factory = null)   X-Ref
Get the information related to the H5P export file.
The information returned will be:
- filename, filepath, mimetype, filesize, timemodified and fileurl.

param: string $exportfilename The H5P export filename (with slug).
param: \moodle_url $url The URL of the exported file.
param: factory $factory The \core_h5p\factory object
return: array|null The information export file otherwise null.