MediaDbGen
extends MediaDb
in package
MediaDb extension with editing support
Table of Contents
Properties
- $mark : string
- $maxAlt : int
- $maxLength : int
- $path : string
- $previewExt : string
- $sanitize : bool
- $table : string
- $tableSizes : string
- $tableTags : string
- $tableTagsId : string
- $db : SQL
- $dependents : array<int, array<string, mixed>>
- $fetch : array<int, int>
- $fileApi : FileApi
- $list : array<int, mixed>
- $more : int|null
- $sizePreview : array<string, mixed>
- $sizes : array<int, array<string, mixed>>
- $tags : array<int, array<string, string|int>>
Methods
- __construct() : mixed
- addDependent() : void
- Adds dependent records to check for existence on deletion
- canPreview() : bool
- Checks if system possibly can create preview image from mime (for PDF)
- convertToSave() : string
- Converts links from editor to id marks
- convertToView() : string
- Converts ID marks into links with optional additional info for editing
- createByPath() : array<string, mixed>|null
- dbUpdate() : void
- Updates data
- dbUpdateTags() : void
- Save / update item tags
- fetchIds() : void
- Adds items ids to queue, witch will be loaded at first request
- getAltById() : string
- Returns record alt description
- getImgAttr() : array<string, string|int>|null
- Returns record attributes
- getImgSizes() : array<string, int>|null
- NOTE: its return incorrect size, if crop is set and original image width/height is smaller than applied (max)size in settings
- getItem() : array<string, array<string|int, int>|string|int>|null
- Get media item
- getItemTags() : array<string|int, int>|null
- Get item tags
- getList() : array<int, mixed>
- Get list of records for administration purposes
- getMimeById() : string
- Returns record mime
- getSize() : array<string, mixed>
- Size settings
- getSizePreview() : array<string, mixed>|null
- Get preview size settings
- getSizes() : array<int, array<string, mixed>>
- Get all sizes or all exept default one
- getSrcById() : string
- Return record url
- getTags() : array<int, array<string, string|int>>
- Get tag list
- hasPreview() : bool
- Checks if non image record has preview
- isImage() : bool
- Checks if mime is image
- isMore() : bool
- Is there more records to load
- isVector() : bool
- Checks if mime is vector image
- itemCreate() : int
- Upload new item into media database
- itemDelete() : bool
- Remove record
- itemModify() : void
- Update item data in media database
- itemReplace() : int
- Replace item in media database
- loadId() : bool
- Load selected record and pending preloaded
- preview() : void
- Show image preview with custom settings
- checkId() : bool
- Check record existence
- createImage() : Image
- Creates image based on settings
- createName() : string
- Format file name and check if its unique for use
- dbAction() : mixed
- Process database changes
- dbSave() : int
- Creates new record
- delete() : void
- Remove all images or keep default image
- findSize() : int|null
- Finds size identificator based on unique string mark(directory)
- getMime() : string
- Returns files mime type
- getPath() : string
- Returns root path for records
- isUsed() : bool
- Check if items is already used
- loadFoundMedia() : void
- Prefetch records from regexes in texts
- loadSizes() : void
- Load and set image sizes
- loadTags() : void
- Load tag list
- moveBoth() : int|null
- Process uploaded file and tries to create preview image
- moveFile() : int|null
- Process uploaded file
- moveImage() : int|null
- Process uploaded image
- processFile() : int|null
- Process data
Properties
$mark
public
static string
$mark
= 'media-id'
$maxAlt
public
static int
$maxAlt
= 60
Max length for record description
$maxLength
public
static int
$maxLength
= 60
Max length for file name and mime
$path
public
static string
$path
= 'Y/m/'
$previewExt
public
static string
$previewExt
= '.jpg'
$sanitize
public
static bool
$sanitize
= true
$table
public
static string
$table
= 'media'
$tableSizes
public
static string
$tableSizes
= 'media_sizes'
$tableTags
public
static string
$tableTags
= 'media_tags'
$tableTagsId
public
static string
$tableTagsId
= 'media_tags_id'
$db
protected
SQL
$db
Database connection
$dependents
protected
array<int, array<string, mixed>>
$dependents
= []
Depended tables
$fetch
protected
array<int, int>
$fetch
= []
List of waiting ids to load
$fileApi
protected
FileApi
$fileApi
$list
protected
array<int, mixed>
$list
= []
Loaded media files
$more
protected
int|null
$more
= null
Are there more items to load
$sizePreview
private
array<string, mixed>
$sizePreview
Default preview size of images
$sizes
private
array<int, array<string, mixed>>
$sizes
List of size settings for images
$tags
private
array<int, array<string, string|int>>
$tags
Methods
__construct()
public
__construct(SQL $db, FileApi $api) : mixed
Parameters
addDependent()
Adds dependent records to check for existence on deletion
public
addDependent(string $table, array<string, string>|string $mixed[, string $mode = 'column' ]) : void
Parameters
- $table : string
- $mixed : array<string, string>|string
- $mode : string = 'column'
canPreview()
Checks if system possibly can create preview image from mime (for PDF)
public
canPreview(string $mime) : bool
Parameters
- $mime : string
Return values
boolconvertToSave()
Converts links from editor to id marks
public
convertToSave(string $text) : string
Parameters
- $text : string
Return values
stringconvertToView()
Converts ID marks into links with optional additional info for editing
public
convertToView(string $text[, bool $edit = false ]) : string
Parameters
- $text : string
- $edit : bool = false
Return values
stringcreateByPath()
public
createByPath(array<string|int, string> $params) : array<string, mixed>|null
Parameters
- $params : array<string|int, string>
Return values
array<string, mixed>|nulldbUpdate()
Updates data
public
dbUpdate(int $id, int $userId[, string|null $alt = null ][, string|null $name = null ][, string|null $mime = null ][, int|null $size = null ][, int|null $width = null ][, int|null $height = null ]) : void
Parameters
- $id : int
- $userId : int
- $alt : string|null = null
- $name : string|null = null
- $mime : string|null = null
- $size : int|null = null
- $width : int|null = null
- $height : int|null = null
dbUpdateTags()
Save / update item tags
public
dbUpdateTags(int $id, array<string|int, int> $newTags) : void
Parameters
- $id : int
- $newTags : array<string|int, int>
fetchIds()
Adds items ids to queue, witch will be loaded at first request
public
fetchIds(array<string|int, int> $ids) : void
Parameters
- $ids : array<string|int, int>
getAltById()
Returns record alt description
public
getAltById(int $id) : string
Parameters
- $id : int
Return values
stringgetImgAttr()
Returns record attributes
public
getImgAttr(int $id, int $type[, array<string, int> $srcset = null ]) : array<string, string|int>|null
Parameters
- $id : int
- $type : int
- $srcset : array<string, int> = null
Return values
array<string, string|int>|nullgetImgSizes()
NOTE: its return incorrect size, if crop is set and original image width/height is smaller than applied (max)size in settings
public
getImgSizes(int $id, int $type) : array<string, int>|null
Parameters
- $id : int
- $type : int
Return values
array<string, int>|nullgetItem()
Get media item
public
getItem(int $id) : array<string, array<string|int, int>|string|int>|null
Parameters
- $id : int
Return values
array<string, array<string|int, int>|string|int>|nullgetItemTags()
Get item tags
public
getItemTags(int $id) : array<string|int, int>|null
Parameters
- $id : int
Return values
array<string|int, int>|nullgetList()
Get list of records for administration purposes
public
getList(int $perPage[, int $from = 0 ][, array<string, string|int> $order = [] ][, array<string, string|array<string|int, int>|int> $search = [] ]) : array<int, mixed>
Parameters
- $perPage : int
- $from : int = 0
- $order : array<string, string|int> = []
- $search : array<string, string|array<string|int, int>|int> = []
-
NAME, MIME, TAG
Return values
array<int, mixed>getMimeById()
Returns record mime
public
getMimeById(int $id) : string
Parameters
- $id : int
Return values
stringgetSize()
Size settings
public
getSize([int $i = 0 ]) : array<string, mixed>
Parameters
- $i : int = 0
Return values
array<string, mixed>getSizePreview()
Get preview size settings
public
getSizePreview() : array<string, mixed>|null
Return values
array<string, mixed>|nullgetSizes()
Get all sizes or all exept default one
public
getSizes([bool $all = true ]) : array<int, array<string, mixed>>
Parameters
- $all : bool = true
Return values
array<int, array<string, mixed>>getSrcById()
Return record url
public
getSrcById(int $id[, int|null $type = null ][, bool $edit = false ]) : string
Parameters
- $id : int
- $type : int|null = null
- $edit : bool = false
Return values
stringgetTags()
Get tag list
public
getTags() : array<int, array<string, string|int>>
Return values
array<int, array<string, string|int>>hasPreview()
Checks if non image record has preview
public
hasPreview(array<string, mixed> $rec) : bool
Parameters
- $rec : array<string, mixed>
Return values
boolisImage()
Checks if mime is image
public
isImage(string $mime) : bool
Parameters
- $mime : string
Return values
boolisMore()
Is there more records to load
public
isMore() : bool
Return values
boolisVector()
Checks if mime is vector image
public
isVector(string $mime) : bool
Parameters
- $mime : string
Return values
boolitemCreate()
Upload new item into media database
public
itemCreate(UserSession $user, string $tmpFile, string $orgName) : int
Parameters
- $user : UserSession
- $tmpFile : string
- $orgName : string
Tags
Return values
intitemDelete()
Remove record
public
itemDelete(int $id) : bool
Parameters
- $id : int
Return values
boolitemModify()
Update item data in media database
public
itemModify(int $id, int $size, array<string, mixed> $update) : void
Parameters
- $id : int
- $size : int
- $update : array<string, mixed>
Tags
itemReplace()
Replace item in media database
public
itemReplace(int $id, UserSession $user, string $tmpFile, string $orgName) : int
Parameters
- $id : int
- $user : UserSession
- $tmpFile : string
- $orgName : string
Tags
Return values
intloadId()
Load selected record and pending preloaded
public
loadId(int $id) : bool
Parameters
- $id : int
Return values
boolpreview()
Show image preview with custom settings
public
preview(int $id, int $size[, array<string, mixed> $custom = [] ]) : void
Parameters
- $id : int
- $size : int
- $custom : array<string, mixed> = []
Tags
checkId()
Check record existence
protected
checkId(int $id) : bool
Parameters
- $id : int
Return values
boolcreateImage()
Creates image based on settings
protected
createImage(string $tmpFile, string|null $path, string|null $newName[, int $num = 0 ][, array<string, mixed> $custom = [] ]) : Image
Parameters
- $tmpFile : string
- $path : string|null
- $newName : string|null
- $num : int = 0
- $custom : array<string, mixed> = []
Return values
ImagecreateName()
Format file name and check if its unique for use
protected
createName(string $path, string $name) : string
Parameters
- $path : string
- $name : string
Return values
stringdbAction()
Process database changes
protected
dbAction(int $userId, string $dbPath, string $newName, string $orgName, string $mime, int $size, int $width, int $height, int|bool $saveId) : mixed
Parameters
- $userId : int
- $dbPath : string
- $newName : string
- $orgName : string
- $mime : string
- $size : int
- $width : int
- $height : int
- $saveId : int|bool
dbSave()
Creates new record
protected
dbSave(int $userId, string $path, string $name, string $orgName, string $mime, int $size[, string|null $alt = null ][, int $width = 0 ][, int $height = 0 ]) : int
Parameters
- $userId : int
- $path : string
- $name : string
- $orgName : string
- $mime : string
- $size : int
- $alt : string|null = null
- $width : int = 0
- $height : int = 0
Return values
intdelete()
Remove all images or keep default image
protected
delete(string $path, array<string|int, mixed> $rec[, bool $all = true ]) : void
Parameters
- $path : string
- $rec : array<string|int, mixed>
- $all : bool = true
findSize()
Finds size identificator based on unique string mark(directory)
protected
findSize(string $mark) : int|null
Parameters
- $mark : string
Return values
int|nullgetMime()
Returns files mime type
protected
getMime(string $file) : string
Parameters
- $file : string
Return values
stringgetPath()
Returns root path for records
protected
getPath() : string
Return values
stringisUsed()
Check if items is already used
protected
isUsed(int $id) : bool
Parameters
- $id : int
Return values
boolloadFoundMedia()
Prefetch records from regexes in texts
protected
loadFoundMedia(array<int, array<int, mixed>> $matches) : void
Parameters
- $matches : array<int, array<int, mixed>>
loadSizes()
Load and set image sizes
protected
loadSizes() : void
loadTags()
Load tag list
protected
loadTags() : void
moveBoth()
Process uploaded file and tries to create preview image
protected
moveBoth(int $userId, string $tmpFile, string $path, string $dbPath, string $newName, string $orgName, string $mime, int|bool $saveId) : int|null
Parameters
- $userId : int
- $tmpFile : string
- $path : string
- $dbPath : string
- $newName : string
- $orgName : string
- $mime : string
- $saveId : int|bool
Tags
Return values
int|nullmoveFile()
Process uploaded file
protected
moveFile(int $userId, string $tmpFile, string $path, string $dbPath, string $newName, string $orgName, string $mime, int|bool $saveId) : int|null
Parameters
- $userId : int
- $tmpFile : string
- $path : string
- $dbPath : string
- $newName : string
- $orgName : string
- $mime : string
- $saveId : int|bool
Tags
Return values
int|nullmoveImage()
Process uploaded image
protected
moveImage(int $userId, string $tmpFile, string $path, string $dbPath, string $newName, string $orgName, string $mime, int|bool $saveId) : int|null
Parameters
- $userId : int
- $tmpFile : string
- $path : string
- $dbPath : string
- $newName : string
- $orgName : string
- $mime : string
- $saveId : int|bool
Tags
Return values
int|nullprocessFile()
Process data
protected
processFile(int $userId, string $tmpFile, string $orgName, string $path, string $dbPath[, int|bool $saveId = true ]) : int|null
Parameters
- $userId : int
- $tmpFile : string
- $orgName : string
- $path : string
- $dbPath : string
- $saveId : int|bool = true