Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

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