Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

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