Search moodle.org's
Developer Documentation

See Release Notes

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

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

(no description)

File Size: 1866 lines (79 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

framework:: (64 methods):
  getPlatformInfo()
  fetchExternalData()
  setLibraryTutorialUrl()
  setErrorMessage()
  setInfoMessage()
  getMessages()
  t()
  getLibraryFileUrl()
  getUploadedH5pFolderPath()
  getUploadedH5pPath()
  loadAddons()
  getLibraryConfig()
  loadLibraries()
  getAdminUrl()
  getLibraryId()
  getWhitelist()
  isPatchedLibrary()
  isInDevMode()
  mayUpdateLibraries()
  get_file()
  set_file()
  saveLibraryData()
  insertContent()
  updateContent()
  resetContentUserData()
  saveLibraryDependencies()
  copyLibraryUsage()
  deleteContentData()
  deleteLibraryUsage()
  saveLibraryUsage()
  getLibraryUsage()
  loadLibrary()
  loadLibrarySemantics()
  alterLibrarySemantics()
  deleteLibraryDependencies()
  lockDependencyStorage()
  unlockDependencyStorage()
  deleteLibrary()
  loadContent()
  loadContentDependencies()
  getOption()
  setOption()
  updateContentFields()
  clearFilteredParameters()
  getNumNotFiltered()
  getNumContent()
  isContentSlugAvailable()
  getLibraryStats()
  getNumAuthors()
  saveCachedAssets()
  deleteCachedAssets()
  getLibraryContentCount()
  afterExportCreated()
  hasPermission()
  replaceContentTypeCache()
  libraryHasUpgrade()
  get_language()
  set_message()
  library_parameter_values_to_csv()
  get_latest_library_version()
  replaceContentHubMetadataCache()
  getContentHubMetadataCache()
  getContentHubMetadataChecked()
  setContentHubMetadataChecked()


Class: framework  - X-Ref

Moodle's implementation of the H5P framework interface.

getPlatformInfo()   X-Ref
Returns info for the current platform.
Implements getPlatformInfo.

return: array An associative array containing:

fetchExternalData($url, $data = null, $blocking = true, $stream = null, $fulldata = false, $headers = [],$files = [], $method = 'POST')   X-Ref
Fetches a file from a remote server using HTTP GET
Implements fetchExternalData.

param: string  $url  Where you want to get or send data.
param: array  $data  Data to post to the URL.
param: bool  $blocking  Set to 'FALSE' to instantly time out (fire and forget).
param: string  $stream  Path to where the file should be saved.
param: bool  $fulldata  Return additional response data such as headers and potentially other data
param: array  $headers  Headers to send
param: array  $files Files to send
param: string  $method
return: string|array The content (response body), or an array with data. NULL if something went wrong

setLibraryTutorialUrl($libraryname, $url)   X-Ref
Set the tutorial URL for a library. All versions of the library is set.
Implements setLibraryTutorialUrl.

param: string $libraryname
param: string $url

setErrorMessage($message, $code = null)   X-Ref
Set an error message.
Implements setErrorMessage.

param: string $message The error message
param: string $code An optional code

setInfoMessage($message)   X-Ref
Set an info message.
Implements setInfoMessage.

param: string $message The info message

getMessages($type)   X-Ref
Return messages.
Implements getMessages.

param: string $type The message type, e.g. 'info' or 'error'
return: string[] Array of messages

t($message, $replacements = array()   X-Ref
Translation function.
The purpose of this function is to map the strings used in the core h5p methods
and replace them with the translated ones. If a translation for a particular string
is not available, the default message (key) will be returned.
Implements t.

param: string $message The english string to be translated
param: array $replacements An associative array of replacements to make after translation
return: string Translated string or the english string if a translation is not available

getLibraryFileUrl($libraryfoldername, $filename)   X-Ref
Get URL to file in the specifimake_pluginfile_urlc library.
Implements getLibraryFileUrl.

param: string $libraryfoldername The name or path of the library's folder
param: string $filename The file name
return: string URL to file

getUploadedH5pFolderPath($setpath = null)   X-Ref
Get the Path to the last uploaded h5p.
Implements getUploadedH5PFolderPath.

param: string $setpath The path to the folder of the last uploaded h5p
return: string Path to the folder where the last uploaded h5p for this session is located

getUploadedH5pPath($setpath = null)   X-Ref
Get the path to the last uploaded h5p file.
Implements getUploadedH5PPath.

param: string $setpath The path to the last uploaded h5p
return: string Path to the last uploaded h5p

loadAddons()   X-Ref
Load addon libraries.
Implements loadAddons.

return: array The array containing the addon libraries

getLibraryConfig($libraries = null)   X-Ref
Load config for libraries.
Implements getLibraryConfig.

param: array|null $libraries List of libraries
return: array|null The library config if it exists, null otherwise

loadLibraries()   X-Ref
Get a list of the current installed libraries.
Implements loadLibraries.

return: array Associative array containing one entry per machine name.

getAdminUrl()   X-Ref
Returns the URL to the library admin page.
Implements getAdminUrl.

return: string URL to admin page

getLibraryId($machinename, $majorversion = null, $minorversion = null)   X-Ref
Return the library's ID.
Implements getLibraryId.

param: string $machinename The librarys machine name
param: string $majorversion Major version number for library (optional)
param: string $minorversion Minor version number for library (optional)
return: int|bool Identifier, or false if non-existent

getWhitelist($islibrary, $defaultcontentwhitelist, $defaultlibrarywhitelist)   X-Ref
Get allowed file extension list.
Implements getWhitelist.

The default extension list is part of h5p, but admins should be allowed to modify it.

param: boolean $islibrary TRUE if this is the whitelist for a library. FALSE if it is the whitelist
param: string $defaultcontentwhitelist A string of file extensions separated by whitespace.
param: string $defaultlibrarywhitelist A string of file extensions separated by whitespace.
return: string A string containing the allowed file extensions separated by whitespace.

isPatchedLibrary($library)   X-Ref
Is the library a patched version of an existing library?
Implements isPatchedLibrary.

param: array $library An associative array containing:
return: boolean TRUE if the library is a patched version of an existing library FALSE otherwise

isInDevMode()   X-Ref
Is H5P in development mode?
Implements isInDevMode.

return: boolean TRUE if H5P development mode is active FALSE otherwise

mayUpdateLibraries()   X-Ref
Is the current user allowed to update libraries?
Implements mayUpdateLibraries.

return: boolean TRUE if the user is allowed to update libraries,

get_file()   X-Ref
Get the .h5p file.

return: \stored_file The .h5p file.

set_file(\stored_file $file)   X-Ref
Set the .h5p file.

param: stored_file $file The .h5p file.

saveLibraryData(&$librarydata, $new = true)   X-Ref
Store data about a library.
Implements saveLibraryData.

Also fills in the libraryId in the libraryData object if the object is new.

param: array $librarydata Associative array containing:
param: bool $new Whether it is a new or existing library.

insertContent($content, $contentmainid = null)   X-Ref
Insert new content.
Implements insertContent.

param: array $content An associative array containing:
param: int $contentmainid Main id for the content if this is a system that supports versions
return: int The ID of the newly inserted content

updateContent($content, $contentmainid = null)   X-Ref
Update old content or insert new content.
Implements updateContent.

param: array $content An associative array containing:
param: int $contentmainid Main id for the content if this is a system that supports versions
return: int The ID of the newly inserted or updated content

resetContentUserData($contentid)   X-Ref
Resets marked user data for the given content.
Implements resetContentUserData.

param: int $contentid The h5p content id

saveLibraryDependencies($libraryid, $dependencies, $dependencytype)   X-Ref
Save what libraries a library is depending on.
Implements saveLibraryDependencies.

param: int $libraryid Library Id for the library we're saving dependencies for
param: array $dependencies List of dependencies as associative arrays containing:
param: string $dependencytype The type of dependency

copyLibraryUsage($contentid, $copyfromid, $contentmainid = null)   X-Ref
Give an H5P the same library dependencies as a given H5P.
Implements copyLibraryUsage.

param: int $contentid Id identifying the content
param: int $copyfromid Id identifying the content to be copied
param: int $contentmainid Main id for the content, typically used in frameworks

deleteContentData($contentid)   X-Ref
Deletes content data.
Implements deleteContentData.

param: int $contentid Id identifying the content

deleteLibraryUsage($contentid)   X-Ref
Delete what libraries a content item is using.
Implements deleteLibraryUsage.

param: int $contentid Content Id of the content we'll be deleting library usage for

saveLibraryUsage($contentid, $librariesinuse)   X-Ref
Saves what libraries the content uses.
Implements saveLibraryUsage.

param: int $contentid Id identifying the content
param: array $librariesinuse List of libraries the content uses

getLibraryUsage($id, $skipcontent = false)   X-Ref
Get number of content/nodes using a library, and the number of dependencies to other libraries.
Implements getLibraryUsage.

param: int $id Library identifier
param: boolean $skipcontent Optional. Set as true to get number of content instances for library
return: array The array contains two elements, keyed by 'content' and 'libraries'.

loadLibrary($machinename, $majorversion, $minorversion)   X-Ref
Loads a library.
Implements loadLibrary.

param: string $machinename The library's machine name
param: int $majorversion The library's major version
param: int $minorversion The library's minor version
return: array|bool Returns FALSE if the library does not exist

loadLibrarySemantics($name, $majorversion, $minorversion)   X-Ref
Loads library semantics.
Implements loadLibrarySemantics.

param: string $name Machine name for the library
param: int $majorversion The library's major version
param: int $minorversion The library's minor version
return: string The library's semantics as json

alterLibrarySemantics(&$semantics, $name, $majorversion, $minorversion)   X-Ref
Makes it possible to alter the semantics, adding custom fields, etc.
Implements alterLibrarySemantics.

param: array $semantics Associative array representing the semantics
param: string $name The library's machine name
param: int $majorversion The library's major version
param: int $minorversion The library's minor version

deleteLibraryDependencies($libraryid)   X-Ref
Delete all dependencies belonging to given library.
Implements deleteLibraryDependencies.

param: int $libraryid Library identifier

lockDependencyStorage()   X-Ref
Start an atomic operation against the dependency storage.
Implements lockDependencyStorage.


unlockDependencyStorage()   X-Ref
Start an atomic operation against the dependency storage.
Implements unlockDependencyStorage.


deleteLibrary($library)   X-Ref
Delete a library from database and file system.
Implements deleteLibrary.

param: \stdClass $library Library object with id, name, major version and minor version

loadContent($id)   X-Ref
Load content.
Implements loadContent.

param: int $id Content identifier
return: array Associative array containing:

loadContentDependencies($id, $type = null)   X-Ref
Load dependencies for the given content of the given type.
Implements loadContentDependencies.

param: int $id Content identifier
param: int $type The dependency type
return: array List of associative arrays containing:

getOption($name, $default = false)   X-Ref
Get stored setting.
Implements getOption.

To avoid updating the cache libraries when using the Hub selector,
{@see \Moodle\H5PEditorAjax::isContentTypeCacheUpdated}, the setting content_type_cache_updated_at
always return the current time.

param: string $name Identifier for the setting
param: string $default Optional default value if settings is not set
return: mixed Return  Whatever has been stored as the setting

setOption($name, $value)   X-Ref
Stores the given setting.
For example when did we last check h5p.org for updates to our libraries.
Implements setOption.

param: string $name Identifier for the setting
param: mixed $value Data Whatever we want to store as the setting

updateContentFields($id, $fields)   X-Ref
This will update selected fields on the given content.
Implements updateContentFields().

param: int $id Content identifier
param: array $fields Content fields, e.g. filtered

clearFilteredParameters($libraryids)   X-Ref
Will clear filtered params for all the content that uses the specified.
libraries. This means that the content dependencies will have to be rebuilt and the parameters re-filtered.
Implements clearFilteredParameters().

param: array $libraryids Array of library ids

getNumNotFiltered()   X-Ref
Get number of contents that has to get their content dependencies rebuilt.
and parameters re-filtered.
Implements getNumNotFiltered().

return: int The number of contents that has to get their content dependencies rebuilt

getNumContent($libraryid, $skip = null)   X-Ref
Get number of contents using library as main library.
Implements getNumContent().

param: int $libraryid The library ID
param: array $skip The array of h5p content ID's that should be ignored
return: int The number of contents using library as main library

isContentSlugAvailable($slug)   X-Ref
Determines if content slug is used.
Implements isContentSlugAvailable.

param: string $slug The content slug
return: boolean Whether the content slug is used

getLibraryStats($type)   X-Ref
Generates statistics from the event log per library.
Implements getLibraryStats.

param: string $type Type of event to generate stats for
return: array Number values indexed by library name and version

getNumAuthors()   X-Ref
Aggregate the current number of H5P authors.
Implements getNumAuthors.

return: int The current number of H5P authors

saveCachedAssets($key, $libraries)   X-Ref
Stores hash keys for cached assets, aggregated JavaScripts and
stylesheets, and connects it to libraries so that we know which cache file
to delete when a library is updated.
Implements saveCachedAssets.

param: string $key Hash key for the given libraries
param: array $libraries List of dependencies(libraries) used to create the key

deleteCachedAssets($libraryid)   X-Ref
Locate hash keys for given library and delete them.
Used when cache file are deleted.
Implements deleteCachedAssets.

param: int $libraryid Library identifier
return: array List of hash keys removed

getLibraryContentCount()   X-Ref
Get the amount of content items associated to a library.
Implements getLibraryContentCount.

return array The number of content items associated to a library

afterExportCreated($content, $filename)   X-Ref
Will trigger after the export file is created.
Implements afterExportCreated.

param: array $content The content
param: string $filename The file name

hasPermission($permission, $id = null)   X-Ref
Check whether a user has permissions to execute an action, such as embed H5P content.
Implements hasPermission.

param: H5PPermission $permission Permission type
param: int $id Id need by platform to determine permission
return: boolean true if the user can execute the action defined in $permission; false otherwise

replaceContentTypeCache($contenttypecache)   X-Ref
Replaces existing content type cache with the one passed in.
Implements replaceContentTypeCache.

param: object $contenttypecache Json with an array called 'libraries' containing the new content type cache

libraryHasUpgrade($library)   X-Ref
Checks if the given library has a higher version.
Implements libraryHasUpgrade.

param: array $library An associative array containing:
return: boolean Whether the library has a higher version

get_language()   X-Ref
Get current H5P language code.

return: string Language Code

set_message(string $type, string $newmessage = null, string $code = null)   X-Ref
Store messages until they can be printed to the current user.

param: string $type Type of messages, e.g. 'info', 'error', etc
param: string $newmessage The message
param: string $code The message code

library_parameter_values_to_csv(array $librarydata, string $key, string $searchparam = 'path')   X-Ref
Convert list of library parameter values to csv.

param: array $librarydata Library data as found in library.json files
param: string $key Key that should be found in $librarydata
param: string $searchparam The library parameter (Default: 'path')
return: string Library parameter values separated by ', '

get_latest_library_version(string $machinename)   X-Ref
Get the latest library version.

param: string $machinename The library's machine name
return: stdClass|null An object with the latest library version

replaceContentHubMetadataCache($metadata, $lang)   X-Ref
Replace content hub metadata cache

param: JsonSerializable $metadata Metadata as received from content hub
param: string $lang Language in ISO 639-1
return: mixed

getContentHubMetadataCache($lang = 'en')   X-Ref
Get content hub metadata cache from db

param: string  $lang Language code in ISO 639-1
return: JsonSerializable Json string

getContentHubMetadataChecked($lang = 'en')   X-Ref
Get time of last content hub metadata check

param: string  $lang Language code iin ISO 639-1 format
return: string|null Time in RFC7231 format

setContentHubMetadataChecked($time, $lang = 'en')   X-Ref
Set time of last content hub metadata check

param: int|null  $time Time in RFC7231 format
param: string  $lang Language code iin ISO 639-1 format
return: bool True if successful