Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Static Public Member Functions | Static Protected Member Functions | List of all members
core_h5p\api Class Reference

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

Static Public Member Functions

static create_content_from_pluginfile_url (string $url, stdClass $config, factory $factory, stdClass &$messages, bool $preventredirect=true)
 Create, if it doesn't exist, the H5P DB instance id for a H5P pluginfile URL. More...
 
static delete_content (\stdClass $content, factory $factory)
 Delete an H5P package. More...
 
static delete_content_from_pluginfile_url (string $url, factory $factory)
 Delete an H5P package deployed from the defined $url. More...
 
static delete_library (factory $factory, stdClass $library)
 Delete a library and also all the libraries depending on it and the H5P contents using it. More...
 
static get_content_from_pathnamehash (string $pathnamehash)
 Returns the H5P content object corresponding to an H5P content file. More...
 
static get_content_from_pluginfile_url (string $url, bool $preventredirect=true)
 Get the H5P DB instance id for a H5P pluginfile URL. More...
 
static get_contenttype_libraries (?string $fields='')
 Get all the H5P content type libraries versions. More...
 
static get_dependent_libraries (int $libraryid)
 Get all the libraries using a defined library. More...
 
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. More...
 
static get_library (int $libraryid)
 Get a library from an identifier. More...
 
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. More...
 

Static Protected Member Functions

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

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

◆ 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 
)
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
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 
)
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
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_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

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