Sortable
extends Creatable
in package
implements
IOverrideSortable
uses
Sortable
Handles the sortable content in the folder. The methods of this class contains always the keyword "content".
Table of Contents
Interfaces
Properties
- $absolutePath : mixed
- $children : mixed
- $cnt : mixed
- $contentCustomOrder : mixed
- $id : mixed
- $name : mixed
- $order : mixed
- $owner : mixed
- $parent : mixed
- $restrictions : mixed
- $restrictionsCount : mixed
- $row : mixed
- $slug : mixed
- $systemReservedFolders : mixed
- $visible : mixed
- $cachedContentOrders : mixed
Methods
- __construct() : mixed
- C'tor with the main properties.
- anyChildrenHas() : array<string|int, mixed>
- Get all children which meets a given column value or column value is not empty.
- anyChildrenHasMetadata() : array<string|int, mixed>
- Get all chilren which meets a given meta key value or meta key value is not empty.
- anyParentHas() : array<string|int, mixed>
- Get all parents which meets a given column value or column value is not empty.
- anyParentHasMetadata() : array<string|int, mixed>
- Get all parents which meets a given meta key value or meta key value is not empty.
- contentDeleteOrder() : mixed
- contentEnableOrder() : mixed
- contentIndex() : mixed
- contentOrder() : mixed
- contentOrderBy() : mixed
- contentReindex() : mixed
- contentRestoreOldCustomNr() : mixed
- delete_all_order() : mixed
- Deletes the complete order. Use it with CAUTION!
- deleted_realmedialibrary_meta() : mixed
- Delete the subOrderAutomatically metadata when deleting the subfolder order and also reset the subfolder order. It also handles the content order.
- forceContentCustomOrder() : bool
- Override this functionality to force the content custom order in the posts_clauses.
- getAbsolutePath() : string
- Creates a absolute path. If the absolute path is empty or forced to, it will be updated in the database, too.
- getAllParents() : array<string|int, int>
- Get all parents of this folder.
- getAttachmentNextTo() : mixed
- getAvailableContentOrders() : array<string|int, mixed>
- Get all available order methods.
- getAvailableSubfolderOrders() : array<string|int, mixed>
- Get all available order methods for subfolders.
- getChildren() : IFolder
- Get children of this folder.
- getCnt() : int
- Gets the count of the files in this folder.
- getContentAggregationNr() : mixed
- getContentCustomOrder() : int
- The content custom order defines the state of the content order functionality:
- getContentNrOf() : mixed
- getContentOldCustomNrCount() : mixed
- getId() : int
- Get the folder id.
- getMaxOrder() : int
- Get the maximal order number of the children.
- getName() : string
- Get the folder name.
- getOrder() : int
- Get the order number.
- getOwner() : int
- Get the creator/owner of the folder.
- getParent() : int
- Get the parent folder id.
- getPath() : string
- Creates a absolute path without slugging' the names.
- getPlain() : array<string|int, mixed>
- Gets a plain array with folder properties.
- getPluginConstantPrefix() : string
- Get the prefix of this plugin so composer packages can dynamically build other constant values on it.
- getRestrictions() : array<string|int, string>
- Get the restrictions of this folder.
- getRestrictionsCount() : int
- Get the count of the restrictions.
- getRowData() : mixed
- Get the full row of the SQL query.
- getSlug() : string
- Returns a sanitized title for the folder. If the slug is empty or forced to, it will be updated in the database, too.
- getTypeDescription() : string
- Get the type description for this folder.
- getTypeName() : string
- Get the type name for this folder. For example: Folder, Collection, Gallery, Unorganized.
- hasChildren() : bool
- Checks if this folder has a children with a given name.
- insert() : true
- Insert an amount of post ID's (attachments) to this folder.
- is() : bool
- Check if the folder object is a given type.
- isContentCustomOrderAllowed() : bool
- Checks if the folder is allowed to use custom content order.
- isRestrictFor() : bool
- Checks if this folder has a special restriction.
- isValidChildrenType() : mixed
- isValidName() : bool
- Checks, if a given folder name is valid. The name is also sanitized so there can be no problem for physical moves for example.
- isVisible() : bool
- Check if the folder object is visible to the user.
- item_move_finished() : mixed
- When moving to a folder with content custom order, reindex the folder content.
- mla_media_modal_query_final_terms() : WP_Query
- Media Library Assistant extension.
- orderSubfolders() : mixed
- persist() : int
- Persist the given creatable with the database. Think about it, that this only works, when the ID === -1 (that means, it will be a new folder).
- persistCheckParent() : mixed
- posts_clauses() : array<string|int, string>
- JOIN the order table and orderby the nr.
- postsClauses() : bool
- Override the default posts_clauses join and orderby instead of the RML standard.
- read() : array<string|int, int>
- Fetch all attachment ids currently in this folder. It uses the default WP_Query to fetch the ids. You can also use the WP_Query like: ```php $query = new \WP_Query([ 'post_status' => 'inherit', 'post_type' => 'attachment', 'rml_folder' => 4, // Can also be an array of integers 'rml_include_children' => false // (optional) Include files of subfolder, you have to use wp_rml_all_children_sql_supported(false, 'function') for checking support ]); ```
- reindexChildrens() : mixed
- relocate() : mixed
- resetSubfolderOrder() : mixed
- setName() : bool
- Renames a folder and then checks, if there is no duplicate folder in the parent folder.
- setParent() : mixed
- setRestrictions() : bool
- Set restrictions for this folder. Allowed restrictions for folders:
- setVisible() : mixed
- Sets the folders visibility to the user.
- updateThisAndChildrensAbsolutePath() : mixed
- Iterate all children of this folder recursively and update the absolute path. Use this function with caution because it can be time intensive.
- xread() : array<string|int, mixed>
- Read ids for a given folder id.
- applySubfolderOrderBy() : bool
- Check if the current folders parent is automatically ordered by a criteria so the order can be applied. This should be called when the hierarchy of the folder is changed or when a new folder is added to that parent.
- singleCheckInsert() : mixed
- Simply check, if an id can be inserted in this folder. If something is wrong with the id, please throw an exception!
- singleCheckInsertPermissions() : mixed
- Simply check, if an id can be inserted in this folder. If something is wrong with the id, please throw an exception!
Properties
$absolutePath
protected
mixed
$absolutePath
$children
protected
mixed
$children
$cnt
protected
mixed
$cnt
$contentCustomOrder
protected
mixed
$contentCustomOrder
$id
protected
mixed
$id
$name
protected
mixed
$name
$order
protected
mixed
$order
$owner
protected
mixed
$owner
$parent
protected
mixed
$parent
$restrictions
protected
mixed
$restrictions
= []
$restrictionsCount
protected
mixed
$restrictionsCount
= 0
$row
protected
mixed
$row
$slug
protected
mixed
$slug
$systemReservedFolders
protected
mixed
$systemReservedFolders
= ['/', '..', '.']
$visible
protected
mixed
$visible
= true
$cachedContentOrders
private
static mixed
$cachedContentOrders
= null
Methods
__construct()
C'tor with the main properties.
public
__construct(mixed $id[, mixed $parent = -1 ][, mixed $name = '' ][, mixed $slug = '' ][, mixed $absolute = '' ][, mixed $order = -1 ][, mixed $cnt = 0 ][, mixed $row = [] ]) : mixed
The constructor does not throw any errors because when it is fully filled with parameters it expects the right properties from the database.
Only ::instance and ::create should create instances from this class!
Synced with order\Sortable::__construct
Parameters
- $id : mixed
- $parent : mixed = -1
- $name : mixed = ''
- $slug : mixed = ''
- $absolute : mixed = ''
- $order : mixed = -1
- $cnt : mixed = 0
- $row : mixed = []
anyChildrenHas()
Get all children which meets a given column value or column value is not empty.
public
anyChildrenHas(mixed $column[, mixed $value = null ][, mixed $valueFormat = '%s' ][, mixed $includeSelf = false ]) : array<string|int, mixed>
Parameters
- $column : mixed
-
The column name for the wp_realmedialibrary SQL table. "slug", "name", "absolutePath", ... This string is not escaped when you pass it through this function
- $value : mixed = null
-
The value the column should have
- $valueFormat : mixed = '%s'
-
The value format for $value ($wpdb->prepare) This string is not escaped when you pass it through this function
- $includeSelf : mixed = false
-
Set true to add self to list
Return values
array<string|int, mixed> —folderId => columnValue, first id is the first found child
anyChildrenHasMetadata()
Get all chilren which meets a given meta key value or meta key value is not empty.
public
anyChildrenHasMetadata(mixed $meta_key[, mixed $meta_value = null ][, mixed $valueFormat = '%s' ][, mixed $includeSelf = false ]) : array<string|int, mixed>
Parameters
- $meta_key : mixed
-
The meta key name for the wp_realmedialibrary_meta SQL table. This string is not escaped when you pass it through this function
- $meta_value : mixed = null
-
The value the meta key should have
- $valueFormat : mixed = '%s'
-
The value format for $value ($wpdb->prepare) This string is not escaped when you pass it through this function
- $includeSelf : mixed = false
-
Set true to add self to list
Return values
array<string|int, mixed> —Array with keys: id (meta_id), folderId, value (meta_value), first id is the first found child
anyParentHas()
Get all parents which meets a given column value or column value is not empty.
public
anyParentHas(mixed $column[, mixed $value = null ][, mixed $valueFormat = '%s' ][, mixed $includeSelf = false ][, mixed $until = null ]) : array<string|int, mixed>
Parameters
- $column : mixed
-
The column name for the wp_realmedialibrary SQL table. "slug", "name", "absolutePath", ... This string is not escaped when you pass it through this function
- $value : mixed = null
-
The value the column should have
- $valueFormat : mixed = '%s'
-
The value format for $value ($wpdb->prepare) This string is not escaped when you pass it through this function
- $includeSelf : mixed = false
-
Set true to add self to list
- $until : mixed = null
-
The highest allowed folder id. If null _wp_rml_root() is used
Return values
array<string|int, mixed> —folderId => columnValue, first id is the first found parent
anyParentHasMetadata()
Get all parents which meets a given meta key value or meta key value is not empty.
public
anyParentHasMetadata(mixed $meta_key[, mixed $meta_value = null ][, mixed $valueFormat = '%s' ][, mixed $includeSelf = false ][, mixed $until = null ]) : array<string|int, mixed>
Parameters
- $meta_key : mixed
-
The meta key name for the wp_realmedialibrary_meta SQL table. This string is not escaped when you pass it through this function
- $meta_value : mixed = null
-
The value the meta key should have
- $valueFormat : mixed = '%s'
-
The value format for $value ($wpdb->prepare) This string is not escaped when you pass it through this function
- $includeSelf : mixed = false
-
Set true to add self to list
- $until : mixed = null
-
The highest allowed folder id. If null _wp_rml_root() is used
Return values
array<string|int, mixed> —Array with keys: id (meta_id), folderId, value (meta_value), first id is the first found parent
contentDeleteOrder()
public
contentDeleteOrder() : mixed
contentEnableOrder()
public
contentEnableOrder() : mixed
contentIndex()
public
contentIndex([mixed $delete = true ]) : mixed
Parameters
- $delete : mixed = true
contentOrder()
public
contentOrder(mixed $attachmentId, mixed $nextId[, mixed $lastIdInView = false ]) : mixed
Parameters
- $attachmentId : mixed
- $nextId : mixed
- $lastIdInView : mixed = false
contentOrderBy()
public
contentOrderBy(mixed $orderby[, mixed $writeMetadata = true ]) : mixed
Parameters
- $orderby : mixed
- $writeMetadata : mixed = true
contentReindex()
public
contentReindex() : mixed
contentRestoreOldCustomNr()
public
contentRestoreOldCustomNr() : mixed
delete_all_order()
Deletes the complete order. Use it with CAUTION!
public
static delete_all_order() : mixed
deleted_realmedialibrary_meta()
Delete the subOrderAutomatically metadata when deleting the subfolder order and also reset the subfolder order. It also handles the content order.
public
static deleted_realmedialibrary_meta(array<string|int, int> $meta_ids, int $object_id, string $meta_key) : mixed
Parameters
- $meta_ids : array<string|int, int>
- $object_id : int
- $meta_key : string
forceContentCustomOrder()
Override this functionality to force the content custom order in the posts_clauses.
public
forceContentCustomOrder() : bool
Return values
boolgetAbsolutePath()
Creates a absolute path. If the absolute path is empty or forced to, it will be updated in the database, too.
public
getAbsolutePath([mixed $force = false ][, mixed $fromSetName = false ]) : string
Parameters
- $force : mixed = false
-
Forces to regenerate the absolute path
- $fromSetName : mixed = false
-
For internal usage only
Return values
stringgetAllParents()
Get all parents of this folder.
public
getAllParents([mixed $until = null ][, mixed $colIdx = 0 ]) : array<string|int, int>
Parameters
- $until : mixed = null
-
The highest allowed folder id. If null _wp_rml_root() is used
- $colIdx : mixed = 0
-
The index returning for the wp_rml_create_all_parents_sql() query
Return values
array<string|int, int> —Folder ids, first id is the first parent
getAttachmentNextTo()
public
getAttachmentNextTo(mixed $attachmentId) : mixed
Parameters
- $attachmentId : mixed
getAvailableContentOrders()
Get all available order methods.
public
static getAvailableContentOrders([bool $asMap = false ]) : array<string|int, mixed>
Parameters
- $asMap : bool = false
Return values
array<string|int, mixed>getAvailableSubfolderOrders()
Get all available order methods for subfolders.
public
static getAvailableSubfolderOrders([bool $asMap = false ]) : array<string|int, mixed>
Parameters
- $asMap : bool = false
Return values
array<string|int, mixed>getChildren()
Get children of this folder.
public
getChildren() : IFolder
Return values
IFoldergetCnt()
Gets the count of the files in this folder.
public
getCnt([mixed $forceReload = false ]) : int
Parameters
- $forceReload : mixed = false
-
If true the count cache gets reloaded
Return values
intgetContentAggregationNr()
public
getContentAggregationNr([mixed $function = 'MAX' ]) : mixed
Parameters
- $function : mixed = 'MAX'
getContentCustomOrder()
The content custom order defines the state of the content order functionality:
public
getContentCustomOrder() : int
0 = No content order defined 1 = Content order is enabled 2 = Custom content order is not allowed
Return values
int —The content custom order value
getContentNrOf()
public
getContentNrOf(mixed $attachmentId) : mixed
Parameters
- $attachmentId : mixed
getContentOldCustomNrCount()
public
getContentOldCustomNrCount() : mixed
getId()
Get the folder id.
public
getId() : int
Return values
intgetMaxOrder()
Get the maximal order number of the children.
public
getMaxOrder() : int
Return values
int —Max order number
getName()
Get the folder name.
public
getName([mixed $htmlentities = false ]) : string
Parameters
- $htmlentities : mixed = false
-
If true the name is returned htmlentitied for output
Return values
stringgetOrder()
Get the order number.
public
getOrder() : int
Return values
intgetOwner()
Get the creator/owner of the folder.
public
getOwner() : int
Return values
int —ID of the user
getParent()
Get the parent folder id.
public
getParent() : int
Return values
intgetPath()
Creates a absolute path without slugging' the names.
public
getPath([mixed $implode = '/' ][, mixed $map = 'htmlentities' ][, mixed $filter = null ]) : string
// Get valid physical folder name
$folder->getPath("/", "_wp_rml_sanitize_filename");
Parameters
- $implode : mixed = '/'
-
Delimiter for the folder names
- $map : mixed = 'htmlentities'
-
Map the names with this function. Pass null to skip this map function
- $filter : mixed = null
-
Filter folders
Return values
string —htmlentitied path
getPlain()
Gets a plain array with folder properties.
public
getPlain([mixed $deep = false ]) : array<string|int, mixed>
Parameters
- $deep : mixed = false
-
Return the children as plain object array
Return values
array<string|int, mixed> —or null when not visible
getPluginConstantPrefix()
Get the prefix of this plugin so composer packages can dynamically build other constant values on it.
public
getPluginConstantPrefix() : string
Tags
Return values
stringgetRestrictions()
Get the restrictions of this folder.
public
getRestrictions() : array<string|int, string>
Return values
array<string|int, string>getRestrictionsCount()
Get the count of the restrictions.
public
getRestrictionsCount() : int
Return values
intgetRowData()
Get the full row of the SQL query.
public
getRowData([mixed $field = null ]) : mixed
Parameters
- $field : mixed = null
-
The field name
Return values
mixed —Any object or false
getSlug()
Returns a sanitized title for the folder. If the slug is empty or forced to, it will be updated in the database, too.
public
getSlug([mixed $force = false ][, mixed $fromSetName = false ]) : string
Parameters
- $force : mixed = false
-
Forces to regenerate the slug
- $fromSetName : mixed = false
-
For internal usage only
Return values
stringgetTypeDescription()
Get the type description for this folder.
public
getTypeDescription([mixed $default = null ]) : string
Parameters
- $default : mixed = null
-
The default (if null folder description is used as default)
Return values
stringgetTypeName()
Get the type name for this folder. For example: Folder, Collection, Gallery, Unorganized.
public
getTypeName([mixed $default = null ]) : string
Parameters
- $default : mixed = null
-
The default (if null "Folder" is used as default)
Return values
stringhasChildren()
Checks if this folder has a children with a given name.
public
hasChildren(mixed $name[, mixed $returnObject = false ]) : bool
Parameters
- $name : mixed
-
Name of folder
- $returnObject : mixed = false
-
If set to true and a children with this name is found, then return the object for this folder
Return values
boolinsert()
Insert an amount of post ID's (attachments) to this folder.
public
insert(mixed $ids[, mixed $supress_validation = false ][, mixed $isShortcut = false ]) : true
Parameters
- $ids : mixed
-
Array of post ids
- $supress_validation : mixed = false
-
Suppress the permission validation
- $isShortcut : mixed = false
-
Determines, if the post's should be "copied" to the folder (no physical copy)
Return values
trueis()
Check if the folder object is a given type.
public
is(mixed $folder_type) : bool
Parameters
- $folder_type : mixed
-
The folder type
Return values
boolisContentCustomOrderAllowed()
Checks if the folder is allowed to use custom content order.
public
isContentCustomOrderAllowed() : bool
Return values
boolisRestrictFor()
Checks if this folder has a special restriction.
public
isRestrictFor(mixed $restriction) : bool
Parameters
- $restriction : mixed
-
The restriction to check
Return values
boolisValidChildrenType()
public
isValidChildrenType(mixed $type) : mixed
Parameters
- $type : mixed
isValidName()
Checks, if a given folder name is valid. The name is also sanitized so there can be no problem for physical moves for example.
public
isValidName(string $name) : bool
Parameters
- $name : string
-
The folder name
Return values
boolisVisible()
Check if the folder object is visible to the user.
public
isVisible() : bool
Return values
boolitem_move_finished()
When moving to a folder with content custom order, reindex the folder content.
public
static item_move_finished(int $folderId, array<string|int, int> $ids, IFolder $folder, bool $isShortcut) : mixed
Parameters
- $folderId : int
- $ids : array<string|int, int>
- $folder : IFolder
- $isShortcut : bool
Tags
mla_media_modal_query_final_terms()
Media Library Assistant extension.
public
static mla_media_modal_query_final_terms(WP_Query $query) : WP_Query
Parameters
- $query : WP_Query
Return values
WP_QueryorderSubfolders()
public
orderSubfolders(mixed $orderby[, mixed $writeMetadata = true ]) : mixed
Parameters
- $orderby : mixed
- $writeMetadata : mixed = true
persist()
Persist the given creatable with the database. Think about it, that this only works, when the ID === -1 (that means, it will be a new folder).
public
persist() : int
After the folder is created, this instance is useless, you must get the folder with the API wp_rml_get_by_id
Tags
Return values
int —ID of the newly created folder
persistCheckParent()
public
persistCheckParent() : mixed
posts_clauses()
JOIN the order table and orderby the nr.
public
static posts_clauses(array<string|int, string> $pieces, WP_Query $query) : array<string|int, string>
It is only affected when $query = new \WP_Query([ 'post_status' => 'inherit', 'post_type' => 'attachment', 'rml_folder' => 4, 'orderby' => 'rml' ));
Parameters
- $pieces : array<string|int, string>
- $query : WP_Query
Return values
array<string|int, string>postsClauses()
Override the default posts_clauses join and orderby instead of the RML standard.
public
postsClauses(mixed $pieces) : bool
This can be useful if you want to take the order from another relationship. You have to return true if you have overwritten it.
Parameters
- $pieces : mixed
-
The posts_clauses $pieces parameter
Return values
boolread()
Fetch all attachment ids currently in this folder. It uses the default WP_Query to fetch the ids. You can also use the WP_Query like: ```php $query = new \WP_Query([ 'post_status' => 'inherit', 'post_type' => 'attachment', 'rml_folder' => 4, // Can also be an array of integers 'rml_include_children' => false // (optional) Include files of subfolder, you have to use wp_rml_all_children_sql_supported(false, 'function') for checking support ]); ```
public
read([mixed $order = null ][, mixed $orderby = null ]) : array<string|int, int>
Parameters
- $order : mixed = null
-
The order "ASC" or "DESC"
- $orderby : mixed = null
-
Use "rml" to get ids ordered by custom order
Return values
array<string|int, int> —Post ids
reindexChildrens()
public
reindexChildrens([mixed $resetData = false ]) : mixed
Parameters
- $resetData : mixed = false
relocate()
public
relocate(mixed $parentId[, mixed $nextFolderId = false ]) : mixed
Parameters
- $parentId : mixed
- $nextFolderId : mixed = false
resetSubfolderOrder()
public
resetSubfolderOrder() : mixed
setName()
Renames a folder and then checks, if there is no duplicate folder in the parent folder.
public
setName(mixed $name[, mixed $supress_validation = false ]) : bool
Parameters
- $name : mixed
-
String New name of the folder
- $supress_validation : mixed = false
-
Suppress the permission validation
Return values
boolsetParent()
public
setParent(mixed $id[, mixed $ord = -1 ][, mixed $force = false ]) : mixed
Parameters
- $id : mixed
- $ord : mixed = -1
- $force : mixed = false
setRestrictions()
Set restrictions for this folder. Allowed restrictions for folders:
public
setRestrictions([mixed $restrictions = [] ]) : bool
- par Restrict to change the parent id
- rea Restrict to rearrange the hierarchical levels of all subfolders (it is downwards all subfolders!) and cannot be inherited
- cre Restrict to create new subfolders
- ins Restrict to insert/upload new attachments, automatically moved to root if upload
- ren Restrict to rename the folder
- del Restrict to delete the folder
- mov Restrict to move files outside the folder
You can append a ">" after each permission so it is inherited in each created subfolder: "cre>", "ins>", ...
Parameters
- $restrictions : mixed = []
-
Array with restrictions
Return values
boolsetVisible()
Sets the folders visibility to the user.
public
setVisible(mixed $visible) : mixed
Parameters
- $visible : mixed
updateThisAndChildrensAbsolutePath()
Iterate all children of this folder recursively and update the absolute path. Use this function with caution because it can be time intensive.
public
updateThisAndChildrensAbsolutePath() : mixed
xread()
Read ids for a given folder id.
public
static xread(int $id[, string $order = null ][, string $orderby = null ]) : array<string|int, mixed>
Parameters
- $id : int
-
The folder id (-1 for root)
- $order : string = null
-
The order
- $orderby : string = null
-
The order by
Return values
array<string|int, mixed> —with ids
applySubfolderOrderBy()
Check if the current folders parent is automatically ordered by a criteria so the order can be applied. This should be called when the hierarchy of the folder is changed or when a new folder is added to that parent.
protected
applySubfolderOrderBy() : bool
Return values
boolsingleCheckInsert()
Simply check, if an id can be inserted in this folder. If something is wrong with the id, please throw an exception!
protected
singleCheckInsert(int $id) : mixed
Parameters
- $id : int
-
The id
Tags
singleCheckInsertPermissions()
Simply check, if an id can be inserted in this folder. If something is wrong with the id, please throw an exception!
protected
singleCheckInsertPermissions(int $id) : mixed
Parameters
- $id : int
-
The id