Stud.IP  5.4
FileArchiveManager Class Reference

Static Public Member Functions

static addFileTypeToArchive (ZipArchive $archive, FileType $file_type, $user_id=null, $archive_fs_path='', $do_user_permission_checks=true, $ignore_user=false, &$file_list=null)
 
static addFileRefToArchive (ZipArchive $archive, FileRef $file_ref, $user_id=null, $archive_fs_path='', $do_user_permission_checks=true, $ignore_user=false, &$file_list=null)
 
static addFolderToArchive (ZipArchive $archive, FolderType $folder, $user_id=null, $archive_fs_path='', $do_user_permission_checks=true, $keep_hierarchy=true, $ignore_user=false, &$file_list=null)
 
static createArchive ( $file_area_objects=[], $user_id=null, $archive_file_path='', $do_user_permission_checks=true, $keep_hierarchy=true, $ignore_user=false, $zip_encoding='UTF-8', $add_filelist_to_archive=false)
 
static createArchiveFromFileRefs ( $file_refs, User $user, $archive_file_path='', $do_user_permission_checks=true)
 
static createArchiveFromFolder (FolderType $folder, $user_id=null, $archive_file_path='', $do_user_permission_checks=true, $keep_hierarchy=true)
 
static createArchiveFromCourse ( $course_id, $user_id=null, $archive_file_path='', $do_user_permission_checks=true, $keep_hierarchy=true)
 
static createArchiveFromInstitute ( $institute_id, $user_id=null, $archive_file_path='', $do_user_permission_checks=true, $keep_hierarchy=true)
 
static createArchiveFromUser ( $user_id, $archive_file_path='', $do_user_permission_checks=true, $keep_hierarchy=true)
 
static createArchiveFromPhysicalFolder ($folder_path, $archive_file_path)
 
static createFolderPath (FolderType $folder, User $user, $path='')
 
static extractFileFromArchive (Studip\ZipArchive $archive, $archive_path, FolderType $target_folder, User $user)
 
static extractArchiveFileToFolder (FileType $archive_file, FolderType $folder, $user_id=null)
 

Detailed Description

The FileArchiveManager class gives programmers a simple way to handle file archives by providing different methods for packing and unpacking file archives in a simple manner.

Member Function Documentation

◆ addFileRefToArchive()

static addFileRefToArchive ( ZipArchive  $archive,
FileRef  $file_ref,
  $user_id = null,
  $archive_fs_path = '',
  $do_user_permission_checks = true,
  $ignore_user = false,
$file_list = null 
)
static

Adds a FileRef to a Zip archive. This is only a wrapper to addFileTypeToArchive that exists only for compatibility reasons.

See also
addFileTypeToArchive

◆ addFileTypeToArchive()

static addFileTypeToArchive ( ZipArchive  $archive,
FileType  $file_type,
  $user_id = null,
  $archive_fs_path = '',
  $do_user_permission_checks = true,
  $ignore_user = false,
$file_list = null 
)
static

Adds a file to an archive using its FileType object.

Parameters
ZipArchive$archiveThe Zip archive where the FileRef shall be added to.
FileType$file_typeThe FileType which shall be added to the zip archive.
string$user_idThe user who wishes to add the FileRef to the archive.
string$archive_fs_pathThe path of the file inside the archive's file system.
bool$do_user_permission_checksSet to true if reading/downloading permissions shall be checked. False otherwise. Default is true.
bool$ignore_userSet to true, if a file which has no download restrictions shall be included and the user-specific download condition check shall be ignored. If this parameter is set to true, the user_id parameter is irrelevant. The default for this parameter is false.
Returns
bool True on success, false on failure.
Exceptions
Exception|FileArchiveManagerExceptionIf an error occurs a general exception or a more special exception is thrown.

◆ addFolderToArchive()

static addFolderToArchive ( ZipArchive  $archive,
FolderType  $folder,
  $user_id = null,
  $archive_fs_path = '',
  $do_user_permission_checks = true,
  $keep_hierarchy = true,
  $ignore_user = false,
$file_list = null 
)
static

Adds a FolderType instance to a Zip archive.

Parameters
ZipArchive$archiveThe Zip archive where the FileRef shall be added to.
FileRef$file_refThe FileRef which shall be added to the zip archive.
string$user_idThe user who wishes to add the FileRef to the archive.
string$archive_fs_pathThe path of the folder inside the archive's file system.
bool$do_user_permission_checksSet to true if reading/downloading permissions shall be checked. False otherwise. Default is true.
bool$keep_hierarchyTrue, if the folder hierarchy shall be kept. False, if the folder hierarchy shall be flattened.
bool$ignore_userSet to true, if a folder of type StandardFolder shall be included without checking if the user (identified by user_id) can read it.
Returns
bool True on success, false on failure.
Exceptions
Exception|FileArchiveManagerExceptionIf an error occurs a general exception or a more special exception is thrown.

◆ createArchive()

static createArchive (   $file_area_objects = [],
  $user_id = null,
  $archive_file_path = '',
  $do_user_permission_checks = true,
  $keep_hierarchy = true,
  $ignore_user = false,
  $zip_encoding = 'UTF-8',
  $add_filelist_to_archive = false 
)
static

General method for creating file archives.

This method is a generalisation for all archive creation methods. For easier archive creation you may use the other archive creation methods which work with less arguments.

Parameters
Array$file_area_objectsArray of FileRef, FileURL, Folder or FolderType objects. $file_area_objects may contain a mix between those object types.
string$user_idThe user who wishes to pack files.
string$archive_file_pathThe path for the archive file.
bool$do_user_permission_checksSet to true if individual reading/downloading permissions shall be checked. False otherwise. Default is true.
bool$keep_hierarchyTrue, if the folder hierarchy shall be kept. False, if the folder hierarchy shall be flattened. Default is true.
bool$ignore_userSet to true, if all files which have no download restrictions and all folders which are of type StandardFolder shall be included and the user-specific download condition check shall be ignored. If this parameter is set to true, the user_id parameter is irrelevant. The default for this parameter is false.
string$zip_encodingencoding for filenames in zip
bool$add_filelist_to_archiveIf this is set to true a file list in the CSV format will be added to the archive. Its name is hardcoded to archive_filelist.csv. The default value of $add_filelist_to_archive is false which means no file list is added.
Returns
bool True, if the archive file was created and saved successfully at $archive_file_path, false otherwise.
Exceptions
Exception|FileArchiveManagerExceptionIf an error occurs a general exception or a more special exception is thrown.

◆ createArchiveFromCourse()

static createArchiveFromCourse (   $course_id,
  $user_id = null,
  $archive_file_path = '',
  $do_user_permission_checks = true,
  $keep_hierarchy = true 
)
static

Creates an archive that contains all files of a course the given user is allowed to download.

Parameters
string$course_idThe ID of the course whose files shall be put inside an archive.
string$user_idThe ID of the user who wishes to put the course's files into an archive
string$archive_file_pathThe path for the archive file.
bool$do_user_permission_checksSet to true if reading/downloading permissions shall be checked. False otherwise. Default is true.
bool$keep_hierarchyTrue, if the file hierarchy shall be kept inside the archive. If $keep_hierarchy is set to false you will get an archive that contains only files and no subdirectories.
Returns
bool True, if the archive file was created and saved successfully at $archive_file_path, false otherwise.
Exceptions
Exception|FileArchiveManagerExceptionIf an error occurs a general exception or a more special exception is thrown.

◆ createArchiveFromFileRefs()

static createArchiveFromFileRefs (   $file_refs,
User  $user,
  $archive_file_path = '',
  $do_user_permission_checks = true 
)
static

Puts files (identified by their file refs) into one file archive.

Parameters
FileRef[]$file_refs Array of FileRef objects.
User$userThe user who wishes to pack files.
string$archive_file_pathThe path for the archive file.
bool$do_user_permission_checksSet to true if reading/downloading permissions shall be checked. False otherwise. Default is true.
Returns
bool True, if the archive file was created and saved successfully at $archive_file_path, false otherwise.
Exceptions
Exception|FileArchiveManagerExceptionIf an error occurs a general exception or a more special exception is thrown.

◆ createArchiveFromFolder()

static createArchiveFromFolder ( FolderType  $folder,
  $user_id = null,
  $archive_file_path = '',
  $do_user_permission_checks = true,
  $keep_hierarchy = true 
)
static

Creates an archive that contains all files of a course the given user is allowed to download.

Parameters
FolderType$folderThe folder whose files shall be put inside an archive.
string$user_idThe ID of the user who wishes to put the course's files into an archive
string$archive_file_pathThe path for the archive file.
bool$do_user_permission_checksSet to true if reading/downloading permissions shall be checked. False otherwise. Default is true.
bool$keep_hierarchyTrue, if the file hierarchy shall be kept inside the archive. If $keep_hierarchy is set to false you will get an archive that contains only files and no subdirectories.
Returns
bool True, if the archive file was created and saved successfully at $archive_file_path, false otherwise.
Exceptions
Exception|FileArchiveManagerExceptionIf an error occurs a general exception or a more special exception is thrown.

◆ createArchiveFromInstitute()

static createArchiveFromInstitute (   $institute_id,
  $user_id = null,
  $archive_file_path = '',
  $do_user_permission_checks = true,
  $keep_hierarchy = true 
)
static

Creates an archive that contains all files of an institute the given user is allowed to download.

Parameters
string$institute_idThe ID of the institute whose files shall be put inside an archive.
string$user_idThe ID of the user who wishes to put the institute's files into an archive
string$archive_file_pathThe path for the archive file.
bool$do_user_permission_checksSet to true if reading/downloading permissions shall be checked. False otherwise. Default is true.
bool$keep_hierarchyTrue, if the file hierarchy shall be kept inside the archive. If $keep_hierarchy is set to false you will get an archive that contains only files and no subdirectories.
Returns
bool True, if the archive file was created and saved successfully at $archive_file_path, false otherwise.
Exceptions
Exception|FileArchiveManagerExceptionIf an error occurs a general exception or a more special exception is thrown.

◆ createArchiveFromPhysicalFolder()

static createArchiveFromPhysicalFolder (   $folder_path,
  $archive_file_path 
)
static

This method creates an archive with the content of a physical folder (A folder inside the operating system's file system).

Parameters
string$folder_pathThe path to the physical folder which content shall be added to a file archive.
string$archive_file_pathThe path to the archive file which shall be created.
Returns
True, if all files were added successfully, false otherwise.
Exceptions
Exception|FileArchiveManagerExceptionIf an error occurs a general exception or a more special exception is thrown.

◆ createArchiveFromUser()

static createArchiveFromUser (   $user_id,
  $archive_file_path = '',
  $do_user_permission_checks = true,
  $keep_hierarchy = true 
)
static

Creates an archive that contains all files of a user, if the current user has root permissions to do this.

Parameters
string$user_idThe ID of the user whose files shall be put inside an archive.
string$archive_file_pathThe path for the archive file.
bool$do_user_permission_checksSet to true if reading/downloading permissions shall be checked. False otherwise. Default is true.
bool$keep_hierarchyTrue, if the file hierarchy shall be kept inside the archive. If $keep_hierarchy is set to false you will get an archive that contains only files and no subdirectories.
Returns
bool True, if the archive file was created and saved successfully at $archive_file_path, false otherwise.
Exceptions
Exception|FileArchiveManagerExceptionIf an error occurs a general exception or a more special exception is thrown.

◆ createFolderPath()

static createFolderPath ( FolderType  $folder,
User  $user,
  $path = '' 
)
static

This is a helper method that builds a subfolder hierarchy inside a folder by looking at a string representing a file system path.

The variable $path contains a hierarchy of subfolders that shall be created inside the given folder. If $path contains "folder1/folder2/folder3" then the given folder will get a subfolder named "folder1". The folder "folder1" itself will get a subfolder named "folder2" and so on.

Parameters
FolderType$folderThe folder where a subfolder path shall be created.
User$userThe user who wishes to create the path.
string$pathThe path which shall be created inside $folder.
Returns
FolderType[] An array with FolderType objects representing each element of $path.

◆ extractArchiveFileToFolder()

static extractArchiveFileToFolder ( FileType  $archive_file,
FolderType  $folder,
  $user_id = null 
)
static

Extracts an archive into a folder inside the Stud.IP file area.

Parameters
FileType$archive_fileThe archive file which shall be extracted.
FolderType$folderThe folder where the archive shall be extracted.
string$user_idThe ID of the user who wants to extract the archive.
Returns
FileType[] Array with extracted files, represented as FileRef objects.

◆ extractFileFromArchive()

static extractFileFromArchive ( Studip\ZipArchive  $archive,
  $archive_path,
FolderType  $target_folder,
User  $user 
)
static

Extracts one file from an opened archive and stores it in a folder.

Parameters
ZipArchive$archiveThe archive from which a file shall be extracted.
string$archive_pathThe path of the file in the archive.
FolderType$target_folderThe folder where the file shall be stored.
User$userThe user who wishes to extract the file from the archive.
Returns
FileType|null FileType instance on success, null otherwise.

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