Stud.IP  4.2 Revision
FileManager Class Reference
Collaboration diagram for FileManager:
Collaboration graph

Static Public Member Functions

static cleanFileName ($file_name=null, $shorten_name=false)
 
static getIconNameForMimeType ($mime_type=null)
 
static getIconForMimeType ( $mime_type=null, $role=Icon::ROLE_CLICKABLE, $attributes=[])
 
static getIconForFileRef (FileRef $ref, $role=Icon::ROLE_CLICKABLE, array $attributes=[])
 
static getDownloadURLForArchivedCourse (ArchivedCourse $archived_course, $protected_archive=false)
 
static getDownloadLinkForArchivedCourse (ArchivedCourse $archived_course, $protected_archive=false)
 
static getDownloadLinkForTemporaryFile ( $temporary_file_name=null, $download_file_name=null)
 
static getDownloadURLForTemporaryFile ( $temporary_file_name=null, $download_file_name=null)
 
static checkUploadedFileStatus ($uploaded_file)
 
static handleFileUpload (Array $uploaded_files, FolderType $folder, $user_id)
 
static updateFileRef (FileRef $source, User $user, $uploaded_file_data=[], $update_filename=false, $update_other_references=false)
 
static editFileRef (FileRef $file_ref, User $user, $name=null, $description=null, $content_terms_of_use_id=null)
 
static copyFileRef (FileRef $source, FolderType $destination_folder, User $user)
 
static moveFileRef (FileRef $source, FolderType $destination_folder, User $user)
 
static deleteFileRef (FileRef $file_ref, User $user)
 
static createSubFolder (FolderType $destination_folder, User $user, $folder_type_class_name=null, $name=null, $description=null)
 
static copyFolder (FolderType $source_folder, FolderType $destination_folder, User $user)
 
static moveFolder (FolderType $source_folder, FolderType $destination_folder, User $user)
 
static deleteFolder (FolderType $folder, User $user)
 
static getFolderTypes ()
 
static getAvailableFolderTypes ($range_id_or_object, $user_id)
 
static copyFolderContentIntoPath (FolderType $folder, $path=null, $user_id='nobody', $min_perms='nobody', $ignore_perms=false)
 
static countFilesInFolder (FolderType $folder, $count_subfolders=true, $owner_id=null, $user_id=null)
 
static getFolderFilesRecursive (FolderType $top_folder, $user_id, $check_file_permissions=false)
 
static getReadableFolders (FolderType $top_folder, $user_id)
 
static getUnreadableFolders (FolderType $top_folder, $user_id)
 
static getTypedFolder ($id, $pluginclass=null)
 
static fetchURLMetadata ($url, $level=0)
 
static getInboxFolder (User $user)
 
static getOutboxFolder (User $user)
 
static getUploadTypeConfig ($range_id, $user_id=null)
 
static getFullPath (FolderType $folder, $include_root=true)
 
static getFolderURL ($folder)
 
static getFolderLink ($folder)
 

Detailed Description

The FileManager class contains methods that faciliate the management of files and folders. Furthermore its methods perform necessary additional checks so that files and folders are managed in a correct manner.

It is recommended to use the methods of this class for file and folder management instead of writing own methods.

Member Function Documentation

◆ checkUploadedFileStatus()

static checkUploadedFileStatus (   $uploaded_file)
static

This is a helper method that checks an uploaded file for errors which appeared during upload.

◆ cleanFileName()

static cleanFileName (   $file_name = null,
  $shorten_name = false 
)
static

Removes special characters from the file name (and by that cleaning the file name) so that the file name which is returned by this method works on every operating system.

Parameters
string$file_nameThe file name that shall be "cleaned".
bool$shorten_nameTrue, if the file name shall be shortened to 31 characters. False, if the full length shall be kept (default).
Returns
string The "cleaned" file name.
Here is the caller graph for this function:

◆ copyFileRef()

static copyFileRef ( FileRef  $source,
FolderType  $destination_folder,
User  $user 
)
static

This method handles copying a file to a new folder.

If the user (given by $user) is the owner of the file (by looking at the user_id in the file reference) we can just make a new reference to that file. Else, we must copy the file and its content.

The file name is altered when a file with the identical name exists in the destination folder. In that case, only the name in the FileRef object of the file is altered and the File object's name is unchanged.

Parameters
FileRef$sourceThe file reference for the file that shall be copied.
FolderType$destination_folderThe destination folder for the file.
User$userThe user who wishes to copy the file.
Returns
FileRef|string[] The copied FileRef object on success or an array with error messages on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ copyFolder()

static copyFolder ( FolderType  $source_folder,
FolderType  $destination_folder,
User  $user 
)
static

This method handles copying folders, including copying the subfolders and files recursively.

Parameters
FolderType$source_folderThe folder that shall be copied.
FolderType$destination_folderThe destination folder.
User$userThe user who wishes to copy the folder.
Returns
FolderType|string[] The copy of the source_folder FolderType object on success or an array with error messages on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ copyFolderContentIntoPath()

static copyFolderContentIntoPath ( FolderType  $folder,
  $path = null,
  $user_id = 'nobody',
  $min_perms = 'nobody',
  $ignore_perms = false 
)
static

Copies the content of a folder (files and subfolders) into a given path in the operating system's file system.

Parameters
FolderTypefolder The folder whose content shall be copied.
stringpath The path in the operating system's file system where the content shall be copied into.
stringuser_id The user who wishes to copy the content.
stringmin_perms If set, the selection of subfolders and files is limited to those which are visible for users having the minimum permissions.
boolignore_perms If set to true, files are copied without checking the minimum permissions or the permissions of the user given by user_id.
Returns
bool True on success, false on error.
Here is the call graph for this function:

◆ countFilesInFolder()

static countFilesInFolder ( FolderType  $folder,
  $count_subfolders = true,
  $owner_id = null,
  $user_id = null 
)
static

Counts the number of files inside a folder and its subfolders. The search result can be limited to the files belonging to one user and/or to the files which are readable for one user.

Parameters
FolderType$folderThe folder whose files shall be counted.
bool$count_subfoldersTrue, if files subfolders shall also be counted, too (default). False otherwise.
string$owner_idOptional user-ID to count only files of one user specified by the ID.
string$user_idOptional user-ID to count only files the user (specified by this user-ID) can read.
Returns
int The amount of files inside the folder (and its subfolders).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ createSubFolder()

static createSubFolder ( FolderType  $destination_folder,
User  $user,
  $folder_type_class_name = null,
  $name = null,
  $description = null 
)
static

Handles the sub folder creation routine.

Parameters
FolderType$destination_folderThe folder where the subfolder shall be linked.
User$userThe user who wishes to create the subfolder.
string$folder_type_class_nameThe FolderType class name for the new folder
string$nameThe name for the new folder
string$descriptionThe description of the new folder
Returns
FolderType|string[] Either the FolderType object of the new folder or an Array with error messages.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ deleteFileRef()

static deleteFileRef ( FileRef  $file_ref,
User  $user 
)
static

This method handles deletign a file reference.

Parameters
FileReffile_ref The file reference that shall be deleted
Useruser The user who wishes to delete the file reference.
Returns
FileRef|string[] The FileRef object that was deleted from the database on success or an array with error messages on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ deleteFolder()

static deleteFolder ( FolderType  $folder,
User  $user 
)
static

This method helps with deleting a folder.

Parameters
FolderType$folderThe folder that shall be deleted.
User$userThe user who wishes to delete the folder.
Returns
FolderType|string[] The deleted folder's FolderType object on success or an array with error messages on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ editFileRef()

static editFileRef ( FileRef  $file_ref,
User  $user,
  $name = null,
  $description = null,
  $content_terms_of_use_id = null 
)
static

This method handles editing file reference attributes.

Checks that have to be made during the editing of a file reference are placed in this method so that a controller can simply call this method to change attributes of a file reference.

At least one of the three parameters name, description and license must be set. Otherwise this method will do nothing.

Parameters
FileReffile_ref The file reference that shall be edited.
Useruser The user who wishes to edit the file reference.
string|nullname The new name for the file reference
string|nulldescription The new description for the file reference.
string|nullcontent_terms_of_use_id The ID of the new ContentTermsOfUse object.
string|nulllicense The new license description for the file reference.
Returns
FileRef|string[] The edited FileRef object on success, string array with error messages on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fetchURLMetadata()

static fetchURLMetadata (   $url,
  $level = 0 
)
static

Retrieves additional data for an URL by looking at the HTTP header.

Parameters
string$urlThe URL from which additional data shall be fetched.
int$levelThe amount of redirects that have already been walked through. The $level parameter is only useful when this method calls itself recursively.
Returns
array An array with additional data retrieved from the HTTP header.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAvailableFolderTypes()

static getAvailableFolderTypes (   $range_id_or_object,
  $user_id 
)
static

returns the available folder types, for given context and user

Parameters
string | SimpleORMap$range_id_or_object
string$user_id
Returns
array with strings representing the class names of available folder types.
Here is the caller graph for this function:

◆ getDownloadLinkForArchivedCourse()

static getDownloadLinkForArchivedCourse ( ArchivedCourse  $archived_course,
  $protected_archive = false 
)
static

Builds a download link for the file archive of an archived course.

Parameters
ArchivedCourse$archived_courseAn archived course whose file archive is requested.
bool$protected_archiveTrue, if the protected file archive is requested. False, if the "readable for everyone" file archive is requested (default).
Returns
string The download link for the file or an empty string on failure.
Here is the call graph for this function:

◆ getDownloadLinkForTemporaryFile()

static getDownloadLinkForTemporaryFile (   $temporary_file_name = null,
  $download_file_name = null 
)
static

Builds a download link for temporary files.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getDownloadURLForArchivedCourse()

static getDownloadURLForArchivedCourse ( ArchivedCourse  $archived_course,
  $protected_archive = false 
)
static

Builds a download URL for the file archive of an archived course.

Parameters
ArchivedCourse$archived_courseAn archived course whose file archive is requested.
bool$protected_archiveTrue, if the protected file archive is requested. False, if the "readable for everyone" file archive is requested (default).
Returns
string The download link for the file or an empty string on failure.
Here is the call graph for this function:

◆ getDownloadURLForTemporaryFile()

static getDownloadURLForTemporaryFile (   $temporary_file_name = null,
  $download_file_name = null 
)
static

Builds a download URL for temporary files.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFolderFilesRecursive()

static getFolderFilesRecursive ( FolderType  $top_folder,
  $user_id,
  $check_file_permissions = false 
)
static

Creates a list of files and subfolders of a folder.

Parameters
FolderType$top_folderThe folder whose content shall be retrieved.
string$user_idThe ID of the user who wishes to get all files and subfolders of a folder.
bool$check_file_permissionsSet to true, if file permissions shall be checked. Defaults to false.
Returns
mixed[] A mixed array with FolderType and FileRef objects.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFolderLink()

static getFolderLink (   $folder)
static

Create link to a folder

Parameters
FolderType | Folder$folderthe folder
Returns
string link to the folder's range
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFolderTypes()

static getFolderTypes ( )
static

returns the available folder types, There are several types of folders in Stud.IP. This method returns all available folder types.

Returns
array with strings representing the class names of available folder types.

◆ getFolderURL()

static getFolderURL (   $folder)
static

Create URL to a folder

Parameters
FolderType | Folder$folderthe folder
Returns
string URL to the folder's range
Here is the call graph for this function:

◆ getFullPath()

static getFullPath ( FolderType  $folder,
  $include_root = true 
)
static

Create URL to a folder

Parameters
FolderType$folderthe folder
bool$include_root
Returns
array array of FolderType
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getIconForFileRef()

static getIconForFileRef ( FileRef  $ref,
  $role = Icon::ROLE_CLICKABLE,
array  $attributes = [] 
)
static

Returns the icon for a given file ref.

Parameters
FileRef$refThe file ref whose icon is requested.
string$roleThe requested role
array$attributesOptional additional attributes
Returns
Icon The icon for the file ref.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getIconForMimeType()

static getIconForMimeType (   $mime_type = null,
  $role = Icon::ROLE_CLICKABLE,
  $attributes = [] 
)
static

Returns the icon for a given mime type.

Parameters
string$mime_typeThe mime type whose icon is requested.
string$roleThe requested role
array$attributesOptional additional attributes
Returns
Icon The icon for the mime type.
Here is the call graph for this function:

◆ getIconNameForMimeType()

static getIconNameForMimeType (   $mime_type = null)
static

Returns the icon name for a given mime type.

Parameters
string$mime_typeThe mime type whose icon is requested.
Returns
string The icon name for the mime type.
Here is the caller graph for this function:

◆ getInboxFolder()

static getInboxFolder ( User  $user)
static

Returns an INBOX folder for the given user.

Parameters
Useruser The user whose inbox folder is requested.
Returns
FolderType|null Returns the inbox folder on success, null on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getOutboxFolder()

static getOutboxFolder ( User  $user)
static

Returns a FolderType object for the outbox folder of the given user.

Parameters
Useruser The user whose outbox folder is requested.
Returns
FolderType|null Returns the inbox folder on success, null on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getReadableFolders()

static getReadableFolders ( FolderType  $top_folder,
  $user_id 
)
static

Creates a list of readable subfolders of a folder.

Parameters
FolderType$top_folder
string$user_id
Returns
FolderType[] assoc array ID => FolderType
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getTypedFolder()

static getTypedFolder (   $id,
  $pluginclass = null 
)
static

Returns a FolderType instance for a given folder-ID. This method can also get FolderType instances which are defined in a file system plugin.

Parameters
$idThe ID of a Folder object.
null$pluginclassThe name of a Plugin's main class.
Returns
FolderType|null A FolderType object if it can be retrieved using the Folder-ID (and by option the plugin class name) or null in case no FolderType object can be created.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getUnreadableFolders()

static getUnreadableFolders ( FolderType  $top_folder,
  $user_id 
)
static

Creates a list of unreadable subfolders of a folder.

Deprecated:
use getReadableFolders() instead
Parameters
FolderType$top_folder
string$user_id
Returns
FolderType[] assoc array ID => FolderType
Here is the call graph for this function:

◆ getUploadTypeConfig()

static getUploadTypeConfig (   $range_id,
  $user_id = null 
)
static

returns config array for upload types and sizes

Parameters
$range_idstring id of Course Institute User
null$user_idstring
Returns
array
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handleFileUpload()

static handleFileUpload ( Array  $uploaded_files,
FolderType  $folder,
  $user_id 
)
static

Handles uploading one or more files

Parameters
uploaded_filesA two-dimensional array with file data for all uploaded files. The array has the following structure in the second dimension: [ 'name': The name of the file 'error': An integer telling if there were errors. 0, if no errors occured. 'type': The uploaded file's mime type. 'tmp_name': Name of the temporary file that was created right after the upload. 'size': Size of the uploaded file in bytes. ]
folderthe folder where the files are inserted
user_idthe ID of the user who wants to upload files
Returns
mixed[] Array with the created file objects and error strings
Here is the call graph for this function:
Here is the caller graph for this function:

◆ moveFileRef()

static moveFileRef ( FileRef  $source,
FolderType  $destination_folder,
User  $user 
)
static

This method handles moving a file to a new folder.

Parameters
FileRef$sourceThe file reference for the file that shall be moved.
FolderType$destination_folderThe destination folder.
User$userThe user who wishes to move the file.
Returns
FileRef|string[] $source FileRef object on success, Array with error messages on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ moveFolder()

static moveFolder ( FolderType  $source_folder,
FolderType  $destination_folder,
User  $user 
)
static

This method handles moving folders, including subfolders and files.

Parameters
FolderType$source_folderThe folder that shall be moved.
FolderType$destination_folderThe destination folder.
User$userThe user who wishes to move the folder.
Returns
FolderType|string[] The moved folder's FolderType object on success or an array with error messages on failure.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateFileRef()

static updateFileRef ( FileRef  $source,
User  $user,
  $uploaded_file_data = [],
  $update_filename = false,
  $update_other_references = false 
)
static

This method handles updating the File a FileRef is pointing to.

The parameters $source, $user and $uploaded_file_data are required for this method to work.

Parameters
FileRef$sourceThe file reference pointing to a file that shall be updated.
User$userThe user who wishes to update the file.
Array$uploaded_file_dataThe data of the uploaded new version of the file that is going to be updated.
bool$update_filenameTrue, if the file name of the File and the FileRef shall be set to the name of the uploaded new version of the file. False otherwise.
bool$update_other_referencesIf other FileRefs pointing to the File that is going to be updated shall be updated too, set this to True. In case only the FileRef $source and its file shall be updated, set this to False. In the latter case the File will be copied and the copy gets updated.
Returns
FileRef|string[] On success the updated $source FileRef is returned. On failure an array with error messages is returned.
Here is the call graph for this function:
Here is the caller graph for this function:

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