Moodle PHP Documentation 4.2
Moodle 4.2.8 (Build: 20240610) (2d41ac46f45)
core_h5p\file_storage Class Reference

Class to handle storage and export of H5P Content. More...

Inheritance diagram for core_h5p\file_storage:
Moodle\H5PFileStorage

Public Member Functions

 __construct ()
 Initial setup for file_storage.
 
 cacheAssets (&$files, $key)
 Will concatenate all JavaScrips and Stylesheets into two files in order to improve page performance.
 
 cloneContent ($id, $newid)
 Creates a stored copy of the content folder.
 
 cloneContentFile ($file, $fromid, $tocontent)
 Copy a file from another content or editor tmp dir.
 
 delete_library (array $library)
 Deletes a library from the file system.
 
 deleteCachedAssets ($keys)
 Remove the aggregated cache files.
 
 deleteContent ($content)
 Remove content folder.
 
 deleteExport ($filename)
 Removes given export file.
 
 deleteLibrary ($library)
 Delete library folder.
 
 exportContent ($id, $target)
 Fetch content folder and save in target directory.
 
 exportLibrary ($library, $target)
 Fetch library folder and save in target directory.
 
 get_export_file (string $filename)
 Get files ready for export.
 
 get_icon_url (int $itemid, string $machinename, int $majorversion, int $minorversion)
 Get the file URL or given library and then return it.
 
 getCachedAssets ($key)
 Will check if there are cache assets available for content.
 
 getContent ($filepath)
 Read file content of given file and then return it.
 
 getContentFile ($file, $content)
 Checks to see if an H5P content has the given file.
 
 getTmpPath ()
 Get path to a new unique tmp folder.
 
 getUpgradeScript ($machinename, $majorversion, $minorversion)
 Check if upgrades script exist for library.
 
 hasExport ($filename)
 Check if the given export file exists.
 
 hasPresave ($libraryname, $developmentpath=null)
 Check if the library has a presave.js in the root folder.
 
 hasWriteAccess ()
 Check if server setup has write permission to the required folders.
 
 moveContentDirectory ($source, $contentid=null)
 Copy content from one directory to another.
 
 removeContentFile ($file, $contentid)
 Remove content files that are no longer used.
 
 saveContent ($source, $content)
 Store the content folder.
 
 saveExport ($source, $filename)
 Save export in file system.
 
 saveFile ($file, $contentid)
 Save files uploaded through the editor.
 
 saveFileFromZip ($path, $file, $stream)
 Store the given stream into the given file.
 
 saveLibrary ($library)
 Stores a H5P library in the Moodle filesystem.
 

Static Public Member Functions

static generate_custom_styles ()
 Generate H5P custom styles if any.
 
static get_custom_styles ()
 Get H5P custom styles if any.
 

Public Attributes

const CACHED_ASSETS_FILEAREA = 'cachedassets'
 The cached assest file area.
 
const COMPONENT = 'core_h5p'
 The component for H5P.
 
const CONTENT_FILEAREA = 'content'
 The content file area.
 
const CSS_FILEAREA = 'css'
 The export css file area.
 
const EDITOR_FILEAREA = 'editor'
 The editor file area.
 
const EXPORT_FILEAREA = 'export'
 The export file area.
 
const ICON_FILENAME = 'icon.svg'
 The icon filename.
 
const LIBRARY_FILEAREA = 'libraries'
 The library file area.
 

Protected Attributes

context $context
 $context Currently we use the system context everywhere.
 
file_storage $fs
 $fs File storage.
 

Detailed Description

Class to handle storage and export of H5P Content.

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

Member Function Documentation

◆ cacheAssets()

core_h5p\file_storage::cacheAssets ( & $files,
$key )

Will concatenate all JavaScrips and Stylesheets into two files in order to improve page performance.

Parameters
array$filesA set of all the assets required for content to display
string$keyHashed key for cached asset

Implements Moodle\H5PFileStorage.

◆ cloneContent()

core_h5p\file_storage::cloneContent ( $id,
$newid )

Creates a stored copy of the content folder.

Parameters
string$idIdentifier of content to clone.
int$newidThe cloned content's identifier

Implements Moodle\H5PFileStorage.

◆ cloneContentFile()

core_h5p\file_storage::cloneContentFile ( $file,
$fromid,
$tocontent )

Copy a file from another content or editor tmp dir.

Used when copy pasting content in H5P.

Parameters
string$filepath + name
string | int$fromidContent ID or 'editor' string
stdClass$tocontentTarget Content
Return values
void

Implements Moodle\H5PFileStorage.

◆ delete_library()

core_h5p\file_storage::delete_library ( array $library)

Deletes a library from the file system.

Parameters
array$libraryLibrary details

◆ deleteCachedAssets()

core_h5p\file_storage::deleteCachedAssets ( $keys)

Remove the aggregated cache files.

Parameters
array$keysThe hash keys of removed files

Implements Moodle\H5PFileStorage.

◆ deleteContent()

core_h5p\file_storage::deleteContent ( $content)

Remove content folder.

Parameters
array$contentContent properties

Implements Moodle\H5PFileStorage.

◆ deleteExport()

core_h5p\file_storage::deleteExport ( $filename)

Removes given export file.

Parameters
string$filenamefilename of the export to delete.

Implements Moodle\H5PFileStorage.

◆ deleteLibrary()

core_h5p\file_storage::deleteLibrary ( $library)

Delete library folder.

Parameters
array$library

Implements Moodle\H5PFileStorage.

◆ exportContent()

core_h5p\file_storage::exportContent ( $id,
$target )

Fetch content folder and save in target directory.

Parameters
int$idContent identifier
string$targetWhere the content folder will be saved

Implements Moodle\H5PFileStorage.

◆ exportLibrary()

core_h5p\file_storage::exportLibrary ( $library,
$target )

Fetch library folder and save in target directory.

Parameters
array$libraryLibrary properties
string$targetWhere the library folder will be saved

Implements Moodle\H5PFileStorage.

◆ get_custom_styles()

static core_h5p\file_storage::get_custom_styles ( )
static

Get H5P custom styles if any.

Exceptions
moodle_exceptionIf the CSS setting is empty but there is a file to serve or there is no file but the CSS setting is not empty.
Return values
array|nullIf there is CSS then an array with the keys 'cssurl' and 'cssversion' is returned otherwise null. 'cssurl' is a link to the generated 'custom_h5p.css' file and 'cssversion' the md5 hash of its contents.

◆ get_export_file()

core_h5p\file_storage::get_export_file ( string $filename)

Get files ready for export.

Parameters
string$filenameFile name to retrieve.
Return values
bool|stored_fileStored file instance if exists, false if not

◆ get_icon_url()

core_h5p\file_storage::get_icon_url ( int $itemid,
string $machinename,
int $majorversion,
int $minorversion )

Get the file URL or given library and then return it.

Parameters
int$itemid
string$machinename
int$majorversion
int$minorversion
Return values
stringurl or false if the file doesn't exist

◆ getCachedAssets()

core_h5p\file_storage::getCachedAssets ( $key)

Will check if there are cache assets available for content.

Parameters
string$keyHashed key for cached asset
Return values
array

Implements Moodle\H5PFileStorage.

◆ getContent()

core_h5p\file_storage::getContent ( $filepath)

Read file content of given file and then return it.

Parameters
string$filepath
Return values
stringcontents

Implements Moodle\H5PFileStorage.

◆ getContentFile()

core_h5p\file_storage::getContentFile ( $file,
$content )

Checks to see if an H5P content has the given file.

Parameters
string$fileFile path and name.
int$contentContent id.
Return values
int|nullFile ID or NULL if not found

Implements Moodle\H5PFileStorage.

◆ getTmpPath()

core_h5p\file_storage::getTmpPath ( )

Get path to a new unique tmp folder.

Please note this needs to not be a directory.

Return values
stringPath

Implements Moodle\H5PFileStorage.

◆ getUpgradeScript()

core_h5p\file_storage::getUpgradeScript ( $machinename,
$majorversion,
$minorversion )

Check if upgrades script exist for library.

Parameters
string$machinename
int$majorversion
int$minorversion
Return values
stringRelative path

Implements Moodle\H5PFileStorage.

◆ hasExport()

core_h5p\file_storage::hasExport ( $filename)

Check if the given export file exists.

Parameters
string$filenameThe export file to check.
Return values
booleanTrue if the export file exists.

Implements Moodle\H5PFileStorage.

◆ hasPresave()

core_h5p\file_storage::hasPresave ( $libraryname,
$developmentpath = null )

Check if the library has a presave.js in the root folder.

Parameters
string$libraryname
string$developmentpath
Return values
bool

Implements Moodle\H5PFileStorage.

◆ hasWriteAccess()

core_h5p\file_storage::hasWriteAccess ( )

Check if server setup has write permission to the required folders.

Return values
boolTrue if server has the proper write access

Implements Moodle\H5PFileStorage.

◆ moveContentDirectory()

core_h5p\file_storage::moveContentDirectory ( $source,
$contentid = null )

Copy content from one directory to another.

Defaults to cloning content from the current temporary upload folder to the editor path.

Parameters
string$sourcepath to source directory
string$contentidId of content

Implements Moodle\H5PFileStorage.

◆ removeContentFile()

core_h5p\file_storage::removeContentFile ( $file,
$contentid )

Remove content files that are no longer used.

Used when saving content.

Parameters
string$fileFile path and name.
int$contentidContent id.
Return values
void

Implements Moodle\H5PFileStorage.

◆ saveContent()

core_h5p\file_storage::saveContent ( $source,
$content )

Store the content folder.

Parameters
string$sourcePath on file system to content directory.
array$contentContent properties

Implements Moodle\H5PFileStorage.

◆ saveExport()

core_h5p\file_storage::saveExport ( $source,
$filename )

Save export in file system.

Parameters
string$sourcePath on file system to temporary export file.
string$filenameName of export file.

Implements Moodle\H5PFileStorage.

◆ saveFile()

core_h5p\file_storage::saveFile ( $file,
$contentid )

Save files uploaded through the editor.

Parameters
H5peditorFile$file
int$contentid
Return values
intThe id of the saved file.

Implements Moodle\H5PFileStorage.

◆ saveFileFromZip()

core_h5p\file_storage::saveFileFromZip ( $path,
$file,
$stream )

Store the given stream into the given file.

Parameters
string$path
string$file
resource$stream
Return values
bool|int

Implements Moodle\H5PFileStorage.

◆ saveLibrary()

core_h5p\file_storage::saveLibrary ( $library)

Stores a H5P library in the Moodle filesystem.

Parameters
array$libraryLibrary properties.

Implements Moodle\H5PFileStorage.

Member Data Documentation

◆ $context

context core_h5p\file_storage::$context
protected

$context Currently we use the system context everywhere.

Don't feel forced to keep it this way in the future.

◆ EDITOR_FILEAREA

const core_h5p\file_storage::EDITOR_FILEAREA = 'editor'

The editor file area.

Deprecated
since Moodle 3.10 MDL-68909. Please do not use this constant any more.
Todo
MDL-69530 This will be deleted in Moodle 4.2.

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