PHP Class MetaModels\Helper\ToolboxFile

Mostrar archivo Open project: metamodels/core Class Usage Examples

Protected Properties

Property Type Description
$acceptedExtensions array Allowed file extensions.
$baseLanguage string Base language, used for retrieving meta.txt information.
$blnShowImages boolean Determines if we want to generate images or not.
$fallbackLanguage string The fallback language, used for retrieving meta.txt information.
$foundFiles array The files to process in this instance.
$metaInformation array Meta information for files.
$modifiedTime array Buffered modification timestamps.
$outputBuffer array Buffered file information.
$pendingIds array The pending uuids to collect from DB.
$pendingPaths string[] The pending paths to collect from DB.
$resizeImages array Image resize information.
$strLightboxId string The id to use in lightboxes.
$uuidMap string[] File id mapping for files.

Public Methods

Method Description
__construct ( ) Create a new instance.
addPath ( string $strPath ) : ToolboxFile Add path to file or folder list.
addPathById ( string $strId ) : ToolboxFile Contao 3 DBAFS Support.
convertUuidsOrPathsToMetaModels ( array $values ) : array Convert an uuid or path to a value to be handled by MetaModels.
convertValueToPath ( string $varValue ) : string Translate the file ID to file path.
convertValuesToDatabase ( array $values ) : array Convert an array of values handled by MetaModels to a value to be stored in the database (array of bin uuid).
convertValuesToMetaModels ( array $values ) : array Convert an array of values stored in the database (array of bin uuid) to a value to be handled by MetaModels.
getAcceptedExtensions ( ) : array Retrieve the allowed file extensions.
getBaseLanguage ( ) : string Retrieve the base language.
getFallbackLanguage ( ) : string Retrieve the fallback language.
getFiles ( ) : array Returns the file list.
getLightboxId ( ) : string Retrieve the lightbox id to use.
getResizeImages ( ) : array Retrieve the resize information.
getShowImages ( ) : boolean Retrieve the flag if images shall be rendered as images.
resolveFiles ( ) : ToolboxFile Process all folders and resolve to a valid file list.
setAcceptedExtensions ( string | array $acceptedExtensions ) : void Set the allowed file extensions.
setBaseLanguage ( string $baseLanguage ) : ToolboxFile Set the base language.
setFallbackLanguage ( string $fallbackLanguage ) : ToolboxFile Set the fallback language.
setLightboxId ( string $strLightboxId ) : ToolboxFile Sets the Id to use for the lightbox.
setResizeImages ( array $resizeImages ) : ToolboxFile Set the resize information.
setShowImages ( boolean $blnShowImages ) : ToolboxFile Set to show/prepare images or not.
sortFiles ( string $sortType, array $sortIds = [] ) : array Sorts the internal file list by a given condition.

Protected Methods

Method Description
addClasses ( array &$arrSource ) : void Attach first, last and even/odd classes to the given array.
collectFiles ( ) : void Walks the list of pending folders via ToolboxFile::addPath().
fetchAdditionalData ( ) : void Walk all files and fetch desired additional information like image sizes etc.
getDownloadLink ( string $strFile ) : string Generate an URL for downloading the given file.
remapSorting ( array $arrFiles, array $arrSource ) : array Maps the sorting from the files to the source.
sortByDate ( boolean $blnAscending = true ) : array Sort by modification time.
sortByIdList ( array $sortIds ) : array Sort by passed id list.
sortByName ( boolean $blnAscending = true ) : array Sort by filename.
sortByRandom ( ) : array Shuffle the file list.

Private Methods

Method Description
addFileModels ( FilesModel[] $files, array $skipPaths = [] ) : void Add the passed file model collection to the current buffer if the extension is allowed.
stringToUuid ( string $uuid ) : string Map a string to it's binary uuid representation.
uuidToString ( string $uuid ) : string Map a binary uuid to it's string representation.

Method Details

__construct() public method

Create a new instance.
public __construct ( )

addClasses() protected method

Attach first, last and even/odd classes to the given array.
protected addClasses ( array &$arrSource ) : void
$arrSource array The array reference of the array to which the classes shall be added to.
return void

addPath() public method

Add path to file or folder list.
public addPath ( string $strPath ) : ToolboxFile
$strPath string The path to be added.
return ToolboxFile

addPathById() public method

Contao 3 DBAFS Support.
public addPathById ( string $strId ) : ToolboxFile
$strId string String uuid of the file.
return ToolboxFile

collectFiles() protected method

Walks the list of pending folders via ToolboxFile::addPath().
protected collectFiles ( ) : void
return void

convertUuidsOrPathsToMetaModels() public static method

The output array will have the following layout: array( 'bin' => array() // the binary id. 'value' => array() // the uuid. 'path' => array() // the path. )
public static convertUuidsOrPathsToMetaModels ( array $values ) : array
$values array The binary uuids or paths to convert.
return array

convertValueToPath() public static method

Translate the file ID to file path.
public static convertValueToPath ( string $varValue ) : string
$varValue string The file id.
return string

convertValuesToDatabase() public static method

The input array must have the following layout: array( 'bin' => array() // list of the binary ids. 'value' => array() // list of the uuids. 'path' => array() // list of the paths. )
public static convertValuesToDatabase ( array $values ) : array
$values array The values to convert.
return array

convertValuesToMetaModels() public static method

The output array will have the following layout: array( 'bin' => array() // list of the binary ids. 'value' => array() // list of the uuids. 'path' => array() // list of the paths. )
public static convertValuesToMetaModels ( array $values ) : array
$values array The binary uuid values to convert.
return array

fetchAdditionalData() protected method

Walk all files and fetch desired additional information like image sizes etc.
protected fetchAdditionalData ( ) : void
return void

getAcceptedExtensions() public method

Retrieve the allowed file extensions.
public getAcceptedExtensions ( ) : array
return array

getBaseLanguage() public method

Retrieve the base language.
public getBaseLanguage ( ) : string
return string

getFallbackLanguage() public method

Retrieve the fallback language.
public getFallbackLanguage ( ) : string
return string

getFiles() public method

NOTE: you must call resolveFiles() beforehand as otherwise folders are not being evaluated.
public getFiles ( ) : array
return array

getLightboxId() public method

Retrieve the lightbox id to use.
public getLightboxId ( ) : string
return string

getResizeImages() public method

Retrieve the resize information.
public getResizeImages ( ) : array
return array

getShowImages() public method

Retrieve the flag if images shall be rendered as images.
public getShowImages ( ) : boolean
return boolean

remapSorting() protected method

All files from $arrFiles are being walked and the corresponding entry from source gets pulled in. Additionally, the css classes are applied to the returned 'source' array. This returns an array like: array('files' => array(), 'source' => array())
protected remapSorting ( array $arrFiles, array $arrSource ) : array
$arrFiles array The files to sort.
$arrSource array The source list.
return array The mapped result.

resolveFiles() public method

Process all folders and resolve to a valid file list.
public resolveFiles ( ) : ToolboxFile
return ToolboxFile

setAcceptedExtensions() public method

Set the allowed file extensions.
public setAcceptedExtensions ( string | array $acceptedExtensions ) : void
$acceptedExtensions string | array The list of accepted file extensions.
return void

setBaseLanguage() public method

Set the base language.
public setBaseLanguage ( string $baseLanguage ) : ToolboxFile
$baseLanguage string The base language to use.
return ToolboxFile

setFallbackLanguage() public method

Set the fallback language.
public setFallbackLanguage ( string $fallbackLanguage ) : ToolboxFile
$fallbackLanguage string The fallback language to use.
return ToolboxFile

setLightboxId() public method

Sets the Id to use for the lightbox.
public setLightboxId ( string $strLightboxId ) : ToolboxFile
$strLightboxId string The lightbox id to use.
return ToolboxFile

setResizeImages() public method

Set the resize information.
public setResizeImages ( array $resizeImages ) : ToolboxFile
$resizeImages array The resize information. Array of 3 elements: 0: Width, 1: Height, 2: Mode.
return ToolboxFile

setShowImages() public method

Set to show/prepare images or not.
public setShowImages ( boolean $blnShowImages ) : ToolboxFile
$blnShowImages boolean True to show images, false otherwise.
return ToolboxFile

sortByDate() protected method

Sort by modification time.
protected sortByDate ( boolean $blnAscending = true ) : array
$blnAscending boolean Flag to determine if sorting shall be applied ascending (default) or descending.
return array

sortByIdList() protected method

Sort by passed id list.
protected sortByIdList ( array $sortIds ) : array
$sortIds array The list of binary ids to sort by.
return array

sortByName() protected method

Sort by filename.
protected sortByName ( boolean $blnAscending = true ) : array
$blnAscending boolean Flag to determine if sorting shall be applied ascending (default) or descending.
return array

sortByRandom() protected method

Shuffle the file list.
protected sortByRandom ( ) : array
return array

sortFiles() public method

Allowed sort types are: name_asc - Sort by filename ascending. name_desc - Sort by filename descending date_asc - Sort by modification time ascending. date_desc - Sort by modification time descending. manual - Sort by passed id array, the array must contain the binary ids of the files. random - Shuffle all the files around.
public sortFiles ( string $sortType, array $sortIds = [] ) : array
$sortType string The sort condition to be applied.
$sortIds array The list of binary ids to sort by (sort type "manual" only).
return array The sorted file list.

Property Details

$acceptedExtensions protected_oe property

Allowed file extensions.
protected array $acceptedExtensions
return array

$baseLanguage protected_oe property

Base language, used for retrieving meta.txt information.
protected string $baseLanguage
return string

$blnShowImages protected_oe property

Determines if we want to generate images or not.
protected bool $blnShowImages
return boolean

$fallbackLanguage protected_oe property

The fallback language, used for retrieving meta.txt information.
protected string $fallbackLanguage
return string

$foundFiles protected_oe property

The files to process in this instance.
protected array $foundFiles
return array

$metaInformation protected_oe property

Meta information for files.
protected array $metaInformation
return array

$modifiedTime protected_oe property

Buffered modification timestamps.
protected array $modifiedTime
return array

$outputBuffer protected_oe property

Buffered file information.
protected array $outputBuffer
return array

$pendingIds protected_oe property

The pending uuids to collect from DB.
protected array $pendingIds
return array

$pendingPaths protected_oe property

The pending paths to collect from DB.
protected string[] $pendingPaths
return string[]

$resizeImages protected_oe property

Image resize information.
protected array $resizeImages
return array

$strLightboxId protected_oe property

The id to use in lightboxes.
protected string $strLightboxId
return string

$uuidMap protected_oe property

File id mapping for files.
protected string[] $uuidMap
return string[]