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

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

Inheritance diagram for core_h5p\file_storage:

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

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

◆ 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

◆ 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

◆ 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

◆ deleteContent()

core_h5p\file_storage::deleteContent (   $content)

Remove content folder.

Parameters
array$contentContent properties

◆ deleteExport()

core_h5p\file_storage::deleteExport (   $filename)

Removes given export file.

Parameters
string$filenamefilename of the export to delete.

◆ 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

◆ 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

◆ 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

◆ getContent()

core_h5p\file_storage::getContent (   $filepath)

Read file content of given file and then return it.

Parameters
string$filepath
Return values
stringcontents

◆ 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

◆ 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

◆ 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

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

◆ 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

◆ 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

◆ 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

◆ 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

◆ saveContent()

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

Store the content folder.

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

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

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

◆ 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

◆ saveLibrary()

core_h5p\file_storage::saveLibrary (   $library)

Stores a H5P library in the Moodle filesystem.

Parameters
array$libraryLibrary properties.

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.


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