Blesta Source Documentation

DownloadManagerFiles extends DownloadManagerModel

Download Manager Files

Manages file downloads

Table of Contents

Properties

$allowed_paths

Methods

__construct() Initialize
add() Create a new file
delete() Deletes a file
edit() Updates a file
get() Fetches the file
getAll() Fetches all files within a specific category
getAllAvailable() Retrieves a list of files available to a client, filtered by category
getFileExtension() Retrieves the file extension (after the last .) of a given filename
getFileGroups() Fetches all of the client groups that this file belongs to
getFileModifiedDate() Retrieves the modified date from a file extension
getFilePackages() Fetches all of the client groups that this file belongs to
getTotal() Count all files for the given company and category
hasAccessToFile() Checks whether the given client has access to the given file
makeFileName() Converts the given file name into an appropriate file name to store to disk
validateFile() Validates that the file or file name provided is valid
validateFileAssignment() Validates that at least one of the given availability options is set, but not all
validateGroups() Validates that the given client groups may be added for this file
validatePackages() Validates that the given packages may be added for this file
addFileGroups() Attaches a list of client groups to a file
addFilePackages() Attaches a list of packages to a file
deleteFileGroups() Deletes all client groups attached to this file
deleteFilePackages() Deletes all packages attached to this file
getFilesAvailable() Partially constructs a Record object for fetching files available to a client
getRules() Retrieves a list of rules to validate add/editing files
Properties

$allowed_paths

private array<string|int, mixed> $allowed_paths = [\CACHEDIR]

A list of directories that are allowed for reading

Methods

add()

Create a new file

public add(array<string|int, mixed> $vars, array<string|int, mixed> $files) : stdClass
Parameters
$vars : array<string|int, mixed>

A list of file input vars, including:

  • category_id The ID of the category to which this file belongs (optional)
  • name The name of the file
  • file_name The absolute path to the file on the server, or null if the file is being uploaded in $files
  • public Whether or not this file is publically-available (0 or 1, default 0)
  • permit_client_groups Whether or not this file is available to permitted client groups (0 or 1, default 0)
  • file_groups A list of client group IDs (optional)
  • permit_packages Whether or not this file is available to permitted packgaes (0 or 1, default 0)
  • file_packages A list of package IDs (optional)
$files : array<string|int, mixed>

A list of files in the format of post data $_FILES

Return values
stdClass

An stdClass object representing this file, or void on error

delete()

Deletes a file

public delete(int $file_id) : mixed
Parameters
$file_id : int

The ID of the file to delete

edit()

Updates a file

public edit(int $file_id, array<string|int, mixed> $vars, array<string|int, mixed> $files) : stdClass
Parameters
$file_id : int

The ID of the file to update

$vars : array<string|int, mixed>

A list of file input vars, including:

  • category_id The ID of the category to which this file belongs
  • name The name of the file
  • file_name The absolute path to the file on the server, or null if the file is being uploaded in $files
  • public Whether or not this file is publically-available (0 or 1, default 0)
  • permit_client_groups Whether or not this file is available to permitted client groups (0 or 1, default 0)
  • file_groups A list of client group IDs (optional)
  • permit_packages Whether or not this file is available to permitted packgaes (0 or 1, default 0)
  • file_packages A list of package IDs (optional)
$files : array<string|int, mixed>

A list of files in the format of post data $_FILES

Return values
stdClass

An stdClass object representing this file

get()

Fetches the file

public get(int $file_id) : mixed
Parameters
$file_id : int

The ID of the file to fetch

Return values
mixed

An stdClass object representing the file, or false if none exist

getAll()

Fetches all files within a specific category

public getAll(int $company_id[, int $category_id = null ]) : array<string|int, mixed>
Parameters
$company_id : int

The ID of the company from which to fetch files

$category_id : int = null

The ID of the category whose files to fetch (optional, default null for uncategorized)

Return values
array<string|int, mixed>

A list of stdClass objects representing files

getAllAvailable()

Retrieves a list of files available to a client, filtered by category

public getAllAvailable(int $company_id[, int $client_id = null ][, int $category_id = null ]) : array<string|int, mixed>
Parameters
$company_id : int

The ID of the company this client belongs to

$client_id : int = null

The ID of the client

$category_id : int = null

The ID of the download category whose files to fetch

Return values
array<string|int, mixed>

A list of files available to the client in the given category

getFileExtension()

Retrieves the file extension (after the last .) of a given filename

public getFileExtension(string $filename) : string
Parameters
$filename : string

The name of the file

Return values
string

The extension, including preceeding . (e.g. ".txt")

getFileGroups()

Fetches all of the client groups that this file belongs to

public getFileGroups(int $file_id) : array<string|int, mixed>
Parameters
$file_id : int

The ID of the file whose client groups to fetch

Return values
array<string|int, mixed>

A list of client group IDs that are assigned to the given file

getFileModifiedDate()

Retrieves the modified date from a file extension

public getFileModifiedDate(string $filename) : int
Parameters
$filename : string

The name of the file

Return values
int

The date when the file was modified

getFilePackages()

Fetches all of the client groups that this file belongs to

public getFilePackages(int $file_id) : array<string|int, mixed>
Parameters
$file_id : int

The ID of the file whose client groups to fetch

Return values
array<string|int, mixed>

A list of client group IDs that are assigned to the given file

getTotal()

Count all files for the given company and category

public getTotal(int $company_id[, mixed $category_id = null ]) : Record
Parameters
$company_id : int

The ID of the company this client belongs to

$category_id : mixed = null

The ID of the download category whose files to fetch (optional, null for root directory, or false to not check category, default null)

Return values
Record

A partially-constructed Record object

hasAccessToFile()

Checks whether the given client has access to the given file

public hasAccessToFile(int $file_id, int $company_id[, int $client_id = null ]) : bool
Parameters
$file_id : int

The ID of the file to check

$company_id : int

The ID of the company that the client belongs to

$client_id : int = null

The ID of the client

Return values
bool

True if the client has access to the file, false otherwise

makeFileName()

Converts the given file name into an appropriate file name to store to disk

public makeFileName(string $file_name) : string
Parameters
$file_name : string

The name of the file to rename

Return values
string

The rewritten file name in the format of YmdTHisO_[hash][ext] (e.g. 20121009T154802+0000_1f3870be274f6c49b3e31a0c6728957f.txt)

validateFile()

Validates that the file or file name provided is valid

public validateFile(string $file_name, array<string|int, mixed> $files) : bool
Parameters
$file_name : string

The name of the file

$files : array<string|int, mixed>

A list of files in the format of post data $_FILES

Return values
bool

True if the file exists or has been uploaded, false otherwise

validateFileAssignment()

Validates that at least one of the given availability options is set, but not all

public validateFileAssignment(int $permit_public, int $permit_client_groups, int $permit_packages) : bool
Parameters
$permit_public : int

Whether or not to permit the public to view this file (1 or 0. if 1, all others must be 0)

$permit_client_groups : int

Whether or not to permit client groups to view this file (1 or 0)

$permit_packages : int

Whether or not to permit certain packages to view this file (1 or 0)

Return values
bool

True if the availability options validate, false otherwise

validateGroups()

Validates that the given client groups may be added for this file

public validateGroups(array<string|int, mixed> $client_group_ids, int $permit_client_groups) : bool
Parameters
$client_group_ids : array<string|int, mixed>

A list of client group IDs

$permit_client_groups : int

Whether or not client groups are permitted (0 or 1)

Return values
bool

True if the client groups are valid, false otherwise

validatePackages()

Validates that the given packages may be added for this file

public validatePackages(array<string|int, mixed> $package_ids, int $permit_packages) : bool
Parameters
$package_ids : array<string|int, mixed>

A list of package IDs

$permit_packages : int

Whether or not packages are permitted (0 or 1)

Return values
bool

True if the packages are valid, false otherwise

addFileGroups()

Attaches a list of client groups to a file

private addFileGroups(int $file_id, array<string|int, mixed> $client_group_ids) : mixed
Parameters
$file_id : int

The ID of the file the client groups should be attached to

$client_group_ids : array<string|int, mixed>

An array of client group IDs

addFilePackages()

Attaches a list of packages to a file

private addFilePackages(int $file_id, array<string|int, mixed> $package_ids) : mixed
Parameters
$file_id : int

The ID of the file the packages should be attached to

$package_ids : array<string|int, mixed>

An array of packages IDs

deleteFileGroups()

Deletes all client groups attached to this file

private deleteFileGroups(int $file_id) : mixed
Parameters
$file_id : int

The ID of the file whose client groups to remove

deleteFilePackages()

Deletes all packages attached to this file

private deleteFilePackages(int $file_id) : mixed
Parameters
$file_id : int

The ID of the file whose packages to remove

getFilesAvailable()

Partially constructs a Record object for fetching files available to a client

private getFilesAvailable(int $company_id[, int $client_id = null ][, mixed $category_id = null ]) : Record
Parameters
$company_id : int

The ID of the company this client belongs to

$client_id : int = null

The ID of the client

$category_id : mixed = null

The ID of the download category whose files to fetch (optional, null for root directory, or false to not check category, default null)

Return values
Record

A partially-constructed Record object

getRules()

Retrieves a list of rules to validate add/editing files

private getRules(array<string|int, mixed> $vars, array<string|int, mixed> $files[, bool $edit = false ]) : array<string|int, mixed>
Parameters
$vars : array<string|int, mixed>

A list of input vars to validate

$files : array<string|int, mixed>

A list of files in the format of post data $_FILES

$edit : bool = false

True to fetch the edit rules, false to fetch the add rules (optional, default false)

Return values
array<string|int, mixed>

A list of rules

Tags
subpackage

plugins.downloadmanager.models

copyright

Copyright (c) 2010, Phillips Data, Inc.

license

http://www.blesta.com/license/ The Blesta License Agreement

link

Blesta


        
On this page

Search results