Moodle PHP Documentation 4.4
Moodle 4.4.1 (Build: 20240610) (db07c09afc5)
core_h5p\api Class Reference

Contains API class for the H5P area. More...

Static Public Member Functions

static can_edit_content (\stored_file $file)
 Check if the user can edit an H5P file.
 
static create_content_from_pluginfile_url (string $url, stdClass $config, factory $factory, stdClass &$messages, bool $preventredirect=true, bool $skipcapcheck=false)
 Create, if it doesn't exist, the H5P DB instance id for a H5P pluginfile URL.
 
static delete_content (\stdClass $content, factory $factory)
 Delete an H5P package.
 
static delete_content_from_pluginfile_url (string $url, factory $factory)
 Delete an H5P package deployed from the defined $url.
 
static delete_library (factory $factory, stdClass $library)
 Delete a library and also all the libraries depending on it and the H5P contents using it.
 
static get_content_from_pathnamehash (string $pathnamehash)
 Returns the H5P content object corresponding to an H5P content file.
 
static get_content_from_pluginfile_url (string $url, bool $preventredirect=true, bool $skipcapcheck=false)
 Get the H5P DB instance id for a H5P pluginfile URL.
 
static get_contenttype_libraries (?string $fields='')
 Get all the H5P content type libraries versions.
 
static get_dependent_libraries (int $libraryid)
 Get all the libraries using a defined library.
 
static get_export_info_from_context_id (int $contextid, factory $factory, string $component, string $filearea)
 Return the H5P export information file when the file has been deployed.
 
static get_library (int $libraryid)
 Get a library from an identifier.
 
static get_library_details (array $params, bool $configurable, string $fields='')
 Returns a library as an object with properties that correspond to the fetched row's field names.
 
static get_original_content_from_pluginfile_url (string $url, bool $preventredirect=true, bool $skipcapcheck=false)
 Get the original file and H5P DB instance for a given H5P pluginfile URL.
 
static is_library_enabled (\stdClass $librarydata)
 Check whether a library is enabled or not.
 
static is_valid_package (\stored_file $file, bool $onlyupdatelibs, bool $skipcontent=false, ?factory $factory=null, bool $deletefiletree=true)
 Check whether an H5P package is valid or not.
 
static set_library_enabled (int $libraryid, bool $isenabled)
 Enable or disable a library.
 

Static Protected Member Functions

static can_access_pluginfile_hash (string $url, bool $preventredirect=true)
 If user can access pathnamehash from an H5P internal URL.
 
static get_pluginfile_hash (string $url)
 Get the pathnamehash from an H5P internal URL.
 

Detailed Description

Contains API class for the H5P area.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later

Member Function Documentation

◆ can_access_pluginfile_hash()

static core_h5p\api::can_access_pluginfile_hash ( string $url,
bool $preventredirect = true )
staticprotected

If user can access pathnamehash from an H5P internal URL.

Parameters
string$urlH5P pluginfile URL poiting to an H5P file.
bool$preventredirectSet to true in scripts that can not redirect (CLI, RSS feeds, etc.), throws exceptions
Return values
boolif user can access pluginfile hash.
Exceptions
moodle_exception
coding_exception
require_login_exception

◆ can_edit_content()

static core_h5p\api::can_edit_content ( \stored_file $file)
static

Check if the user can edit an H5P file.

It will return true in the following situations:

  • The user is the author of the file.
  • The component is different from user (i.e. private files).
  • If the component is contentbank, the user can edit this file (calling the ContentBank API).
  • If the component is mod_xxx or block_xxx, the user has the addinstance capability.
  • If the component implements the can_edit_content in the h5p\canedit class and the callback to this method returns true.
Parameters
stored_file$fileThe H5P file to check.
Return values
booleanWhether the user can edit or not the given file.
Since
Moodle 4.0

◆ create_content_from_pluginfile_url()

static core_h5p\api::create_content_from_pluginfile_url ( string $url,
stdClass $config,
factory $factory,
stdClass & $messages,
bool $preventredirect = true,
bool $skipcapcheck = false )
static

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.
Parameters
string$urlH5P pluginfile URL.
stdClass$configConfiguration for H5P buttons.
factory$factoryThe core_h5p\factory object
stdClass$messagesThe error, exception and info messages, raised while preparing and running an H5P content.
bool$preventredirectSet to true in scripts that can not redirect (CLI, RSS feeds, etc.), throws exceptions
bool$skipcapcheckWhether capabilities should be checked or not to get the pluginfile URL because sometimes they might be controlled before calling this method.
Return values
arrayof [file, h5pid]:
  • file local file for this $url.
  • h5pid is the H5P identifier or false if there isn't any H5P with this URL.

◆ delete_content()

static core_h5p\api::delete_content ( \stdClass $content,
factory $factory )
static

Delete an H5P package.

Parameters
stdClass$contentThe H5P package to delete with, at least content['id].
factory$factoryThe core_h5p\factory object

◆ delete_content_from_pluginfile_url()

static core_h5p\api::delete_content_from_pluginfile_url ( string $url,
factory $factory )
static

Delete an H5P package deployed from the defined $url.

Parameters
string$urlpluginfile URL of the H5P package to delete.
factory$factoryThe core_h5p\factory object

◆ delete_library()

static core_h5p\api::delete_library ( factory $factory,
stdClass $library )
static

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).

Parameters
factory$factoryThe H5P factory.
stdClass$libraryThe library to delete.

◆ get_content_from_pathnamehash()

static core_h5p\api::get_content_from_pathnamehash ( string $pathnamehash)
static

Returns the H5P content object corresponding to an H5P content file.

Parameters
string$pathnamehashThe pathnamehash of the file associated to an H5P content.
Return values
null|stdClassH5P content object or null if not found.

◆ get_content_from_pluginfile_url()

static core_h5p\api::get_content_from_pluginfile_url ( string $url,
bool $preventredirect = true,
bool $skipcapcheck = false )
static

Get the H5P DB instance id for a H5P pluginfile URL.

If it doesn't exist, it's not created.

Parameters
string$urlH5P pluginfile URL.
bool$preventredirectSet to true in scripts that can not redirect (CLI, RSS feeds, etc.), throws exceptions
bool$skipcapcheckWhether capabilities should be checked or not to get the pluginfile URL because sometimes they might be controlled before calling this method.
Return values
arrayof [file, stdClass|false]:
  • file local file for this $url.
  • stdClass is an H5P object or false if there isn't any H5P with this URL.

◆ get_contenttype_libraries()

static core_h5p\api::get_contenttype_libraries ( ?string $fields = '')
static

Get all the H5P content type libraries versions.

Parameters
string | null$fieldsLibrary fields to return.
Return values
arrayAn array with an object for each content type library installed.

◆ get_dependent_libraries()

static core_h5p\api::get_dependent_libraries ( int $libraryid)
static

Get all the libraries using a defined library.

Parameters
int$libraryidThe library to get its dependencies.
Return values
arrayList of libraryid with all the libraries required by a defined library.

◆ get_export_info_from_context_id()

static core_h5p\api::get_export_info_from_context_id ( int $contextid,
factory $factory,
string $component,
string $filearea )
static

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.
Parameters
int$contextidContextId of the H5P activity.
factory$factoryThe core_h5p\factory object.
string$componentcomponent
string$fileareafile area
Return values
array|nullReturn file info otherwise null.

◆ get_library()

static core_h5p\api::get_library ( int $libraryid)
static

Get a library from an identifier.

Parameters
int$libraryidThe library identifier.
Return values
stdClassThe library object having the library identifier defined.
Exceptions
dml_exceptionA DML specific exception is thrown if the libraryid doesn't exist.

◆ get_library_details()

static core_h5p\api::get_library_details ( array $params,
bool $configurable,
string $fields = '' )
static

Returns a library as an object with properties that correspond to the fetched row's field names.

Parameters
array$paramsAn associative array with the values of the machinename, majorversion and minorversion fields.
bool$configurableA library that has semantics so it can be configured in the editor.
string$fieldsLibrary attributes to retrieve.
Return values
stdClass|nullAn object with one attribute for each field name in $fields param.

◆ get_original_content_from_pluginfile_url()

static core_h5p\api::get_original_content_from_pluginfile_url ( string $url,
bool $preventredirect = true,
bool $skipcapcheck = false )
static

Get the original file and H5P DB instance for a given H5P pluginfile URL.

If it doesn't exist, it's not created. If the file has been added as a reference, this method will return the original linked file.

Parameters
string$urlH5P pluginfile URL.
bool$preventredirectSet to true in scripts that can not redirect (CLI, RSS feeds, etc.), throws exceptions.
bool$skipcapcheckWhether capabilities should be checked or not to get the pluginfile URL because sometimes they might be controlled before calling this method.
Return values
arrayof [stored_file|false, stdClass|false, stored_file|false]:
  • stored_file: original local file for the given url (if it has been added as a reference, this method will return the linked file) or false if there isn't any H5P file with this URL.
  • stdClass: an H5P object or false if there isn't any H5P with this URL.
  • stored_file: file associated to the given url (if it's different from original) or false when both files (original and file) are the same.
Since
Moodle 4.0

◆ get_pluginfile_hash()

static core_h5p\api::get_pluginfile_hash ( string $url)
staticprotected

Get the pathnamehash from an H5P internal URL.

Parameters
string$urlH5P pluginfile URL poiting to an H5P file.
Return values
string|falsepathnamehash for the file in the internal URL.
Exceptions
moodle_exception

◆ is_library_enabled()

static core_h5p\api::is_library_enabled ( \stdClass $librarydata)
static

Check whether a library is enabled or not.

When machinename is passed, it will return false if any of the versions for this machinename is disabled. If the library doesn't exist, it will return true.

Parameters
stdClass$librarydataSupported fields for library: 'id' and 'machichename'.
Return values
bool
Exceptions
moodle_exception

◆ is_valid_package()

static core_h5p\api::is_valid_package ( \stored_file $file,
bool $onlyupdatelibs,
bool $skipcontent = false,
?factory $factory = null,
bool $deletefiletree = true )
static

Check whether an H5P package is valid or not.

Parameters
stored_file$fileThe file with the H5P content.
bool$onlyupdatelibsWhether new libraries can be installed or only the existing ones can be updated
bool$skipcontentShould the content be skipped (so only the libraries will be saved)?
factory | null$factoryThe core_h5p\factory object
bool$deletefiletreeShould the temporary files be deleted before returning?
Return values
boolTrue if the H5P file is valid (expected format, valid libraries...); false otherwise.

◆ set_library_enabled()

static core_h5p\api::set_library_enabled ( int $libraryid,
bool $isenabled )
static

Enable or disable a library.

Parameters
int$libraryidThe id of the library to enable/disable.
bool$isenabledTrue if the library should be enabled; false otherwise.

The documentation for this class was generated from the following file: