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]

   1  <?php
   2  
   3  namespace Moodle;
   4  
   5  /**
   6   * File info?
   7   */
   8  
   9  /**
  10   * Interface needed to handle storage and export of H5P Content.
  11   */
  12  interface H5PFileStorage {
  13  
  14    /**
  15     * Store the library folder.
  16     *
  17     * @param array $library
  18     *  Library properties
  19     */
  20    public function saveLibrary($library);
  21  
  22    /**
  23     * Delete library folder
  24     *
  25     * @param array $library
  26     */
  27    public function deleteLibrary($library);
  28  
  29    /**
  30     * Store the content folder.
  31     *
  32     * @param string $source
  33     *  Path on file system to content directory.
  34     * @param array $content
  35     *  Content properties
  36     */
  37    public function saveContent($source, $content);
  38  
  39    /**
  40     * Remove content folder.
  41     *
  42     * @param array $content
  43     *  Content properties
  44     */
  45    public function deleteContent($content);
  46  
  47    /**
  48     * Creates a stored copy of the content folder.
  49     *
  50     * @param string $id
  51     *  Identifier of content to clone.
  52     * @param int $newId
  53     *  The cloned content's identifier
  54     */
  55    public function cloneContent($id, $newId);
  56  
  57    /**
  58     * Get path to a new unique tmp folder.
  59     *
  60     * @return string
  61     *  Path
  62     */
  63    public function getTmpPath();
  64  
  65    /**
  66     * Fetch content folder and save in target directory.
  67     *
  68     * @param int $id
  69     *  Content identifier
  70     * @param string $target
  71     *  Where the content folder will be saved
  72     */
  73    public function exportContent($id, $target);
  74  
  75    /**
  76     * Fetch library folder and save in target directory.
  77     *
  78     * @param array $library
  79     *  Library properties
  80     * @param string $target
  81     *  Where the library folder will be saved
  82     */
  83    public function exportLibrary($library, $target);
  84  
  85    /**
  86     * Save export in file system
  87     *
  88     * @param string $source
  89     *  Path on file system to temporary export file.
  90     * @param string $filename
  91     *  Name of export file.
  92     */
  93    public function saveExport($source, $filename);
  94  
  95    /**
  96     * Removes given export file
  97     *
  98     * @param string $filename
  99     */
 100    public function deleteExport($filename);
 101  
 102    /**
 103     * Check if the given export file exists
 104     *
 105     * @param string $filename
 106     * @return boolean
 107     */
 108    public function hasExport($filename);
 109  
 110    /**
 111     * Will concatenate all JavaScrips and Stylesheets into two files in order
 112     * to improve page performance.
 113     *
 114     * @param array $files
 115     *  A set of all the assets required for content to display
 116     * @param string $key
 117     *  Hashed key for cached asset
 118     */
 119    public function cacheAssets(&$files, $key);
 120  
 121    /**
 122     * Will check if there are cache assets available for content.
 123     *
 124     * @param string $key
 125     *  Hashed key for cached asset
 126     * @return array
 127     */
 128    public function getCachedAssets($key);
 129  
 130    /**
 131     * Remove the aggregated cache files.
 132     *
 133     * @param array $keys
 134     *   The hash keys of removed files
 135     */
 136    public function deleteCachedAssets($keys);
 137  
 138    /**
 139     * Read file content of given file and then return it.
 140     *
 141     * @param string $file_path
 142     * @return string contents
 143     */
 144    public function getContent($file_path);
 145  
 146    /**
 147     * Save files uploaded through the editor.
 148     * The files must be marked as temporary until the content form is saved.
 149     *
 150     * @param H5peditorFile $file
 151     * @param int $contentId
 152     */
 153    public function saveFile($file, $contentId);
 154  
 155    /**
 156     * Copy a file from another content or editor tmp dir.
 157     * Used when copy pasting content in H5P.
 158     *
 159     * @param string $file path + name
 160     * @param string|int $fromId Content ID or 'editor' string
 161     * @param int $toId Target Content ID
 162     */
 163    public function cloneContentFile($file, $fromId, $toId);
 164  
 165    /**
 166     * Copy a content from one directory to another. Defaults to cloning
 167     * content from the current temporary upload folder to the editor path.
 168     *
 169     * @param string $source path to source directory
 170     * @param string $contentId Id of content
 171     *
 172     * @return object Object containing h5p json and content json data
 173     */
 174    public function moveContentDirectory($source, $contentId = NULL);
 175  
 176    /**
 177     * Checks to see if content has the given file.
 178     * Used when saving content.
 179     *
 180     * @param string $file path + name
 181     * @param int $contentId
 182     * @return string|int File ID or NULL if not found
 183     */
 184    public function getContentFile($file, $contentId);
 185  
 186    /**
 187     * Remove content files that are no longer used.
 188     * Used when saving content.
 189     *
 190     * @param string $file path + name
 191     * @param int $contentId
 192     */
 193    public function removeContentFile($file, $contentId);
 194  
 195    /**
 196     * Check if server setup has write permission to
 197     * the required folders
 198     *
 199     * @return bool True if server has the proper write access
 200     */
 201    public function hasWriteAccess();
 202  
 203    /**
 204     * Check if the library has a presave.js in the root folder
 205     *
 206     * @param string $libraryName
 207     * @param string $developmentPath
 208     * @return bool
 209     */
 210    public function hasPresave($libraryName, $developmentPath = null);
 211  
 212    /**
 213     * Check if upgrades script exist for library.
 214     *
 215     * @param string $machineName
 216     * @param int $majorVersion
 217     * @param int $minorVersion
 218     * @return string Relative path
 219     */
 220    public function getUpgradeScript($machineName, $majorVersion, $minorVersion);
 221  
 222    /**
 223     * Store the given stream into the given file.
 224     *
 225     * @param string $path
 226     * @param string $file
 227     * @param resource $stream
 228     * @return bool
 229     */
 230    public function saveFileFromZip($path, $file, $stream);
 231  }