Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

Contains API class for the H5P area.

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

Defines 1 class


Class: api  - X-Ref

Contains API class for the H5P area.

delete_library(factory $factory, \stdClass $library)   X-Ref
Delete a library and also all the libraries depending on it and the H5P contents using it. For the H5P content, only the
database entries in {h5p} are removed (the .h5p files are not removed in order to let users to deploy them again).

param: factory   $factory The H5P factory.
param: \stdClass $library The library to delete.

get_dependent_libraries(int $libraryid)   X-Ref
Get all the libraries using a defined library.

param: int    $libraryid The library to get its dependencies.
return: array  List of libraryid with all the libraries required by a defined library.

get_library(int $libraryid)   X-Ref
Get a library from an identifier.

param: int    $libraryid The library identifier.
return: \stdClass The library object having the library identifier defined.

get_library_details(array $params, bool $configurable, string $fields = '')   X-Ref
Returns a library as an object with properties that correspond to the fetched row's field names.

param: array $params An associative array with the values of the machinename, majorversion and minorversion fields.
param: bool $configurable A library that has semantics so it can be configured in the editor.
param: string $fields Library attributes to retrieve.
return: \stdClass|null An object with one attribute for each field name in $fields param.

get_contenttype_libraries(?string $fields = '')   X-Ref
Get all the H5P content type libraries versions.

param: string|null $fields Library fields to return.
return: array An array with an object for each content type library installed.

get_content_from_pluginfile_url(string $url, bool $preventredirect = true)   X-Ref
Get the H5P DB instance id for a H5P pluginfile URL. If it doesn't exist, it's not created.

param: string $url H5P pluginfile URL.
param: bool $preventredirect Set to true in scripts that can not redirect (CLI, RSS feeds, etc.), throws exceptions
return: array of [file, stdClass|false]:

create_content_from_pluginfile_url(string $url, \stdClass $config, factory $factory,\stdClass &$messages, bool $preventredirect = true)   X-Ref
Create, if it doesn't exist, the H5P DB instance id for a H5P pluginfile URL. If it exists:
- If the content is not the same, remove the existing content and re-deploy the H5P content again.
- If the content is the same, returns the H5P identifier.

param: string $url H5P pluginfile URL.
param: stdClass $config Configuration for H5P buttons.
param: factory $factory The \core_h5p\factory object
param: stdClass $messages The error, exception and info messages, raised while preparing and running an H5P content.
param: bool $preventredirect Set to true in scripts that can not redirect (CLI, RSS feeds, etc.), throws exceptions
return: array of [file, h5pid]:

delete_content(\stdClass $content, factory $factory)   X-Ref
Delete an H5P package.

param: stdClass $content The H5P package to delete with, at least content['id].
param: factory $factory The \core_h5p\factory object

delete_content_from_pluginfile_url(string $url, factory $factory)   X-Ref
Delete an H5P package deployed from the defined $url.

param: string $url pluginfile URL of the H5P package to delete.
param: factory $factory The \core_h5p\factory object

can_access_pluginfile_hash(string $url, bool $preventredirect = true)   X-Ref
If user can access pathnamehash from an H5P internal URL.

param: string $url H5P pluginfile URL poiting to an H5P file.
param: bool $preventredirect Set to true in scripts that can not redirect (CLI, RSS feeds, etc.), throws exceptions
return: bool if user can access pluginfile hash.

get_pluginfile_hash(string $url)   X-Ref
Get the pathnamehash from an H5P internal URL.

param: string $url H5P pluginfile URL poiting to an H5P file.
return: string|false pathnamehash for the file in the internal URL.

get_content_from_pathnamehash(string $pathnamehash)   X-Ref
Returns the H5P content object corresponding to an H5P content file.

param: string $pathnamehash The pathnamehash of the file associated to an H5P content.
return: null|\stdClass H5P content object or null if not found.

get_export_info_from_context_id(int $contextid,factory $factory,string $component,string $filearea)   X-Ref
Return the H5P export information file when the file has been deployed.
Otherwise, return null if H5P file:
i) has not been deployed.
ii) has changed the content.

The information returned will be:
- filename, filepath, mimetype, filesize, timemodified and fileurl.

param: int $contextid ContextId of the H5P activity.
param: factory $factory The \core_h5p\factory object.
param: string $component component
param: string $filearea file area
return: array|null Return file info otherwise null.