Nested
Extends TableTable class supporting modified pre-order tree traversal behavior.
since |
1.7.0 |
---|---|
package |
Joomla CMS |
Methods
__construct
Object constructor to set table and key fields. In most cases this will be overridden by child classes to explicitly set the table and key fields for a particular database table.
__construct( table, key, \Joomla\Database\DatabaseDriver db, \Joomla\Event\DispatcherInterface dispatcher = null) :
since |
1.7.0 |
---|
Arguments
- table
string
Name of the table to model.- key
mixed
Name of the primary key field in the table or array of field names that compose the primary key.- db
DatabaseDriver
DatabaseDriver object.- dispatcher
DispatcherInterface
Event dispatcher for this table
Response
mixed
__toString
Magic method to convert the object to a string gracefully.
__toString() :
since |
1.7.0 |
---|---|
deprecated |
4.3 will be removed in 6.0 Classes should provide their own __toString() implementation. |
Response
string
The classname.
_getAssetName
Method to compute the default name of the asset.
_getAssetName() :
The default name is in the form table_name.id where id is the value of the primary key of the table.
since |
1.7.0 |
---|
Response
string
_getAssetParentId
Method to get the parent asset under which to register this one.
_getAssetParentId(\Joomla\CMS\Table\Table table = null, id = null) :
By default, all assets are registered to the ROOT node with ID, which will default to 1 if none exists. An extended class can define a table and ID to lookup. If the asset does not exist it will be created.
since |
1.7.0 |
---|
Arguments
- table
Table
A Table object for the asset parent.- id
int
Id to look up
Response
int
_getAssetTitle
Method to return the title to use for the asset table.
_getAssetTitle() :
In tracking the assets a title is kept for each asset so that there is some context available in a unified access manager. Usually this would just return $this->title or $this->name or whatever is being used for the primary name of the row. If this method is not overridden, the asset name is used.
since |
1.7.0 |
---|
Response
string
The string to use as the title in the asset table.
_getNode
Method to get nested set properties for a node in the tree.
_getNode( id, key = null) :
since |
1.7.0 |
---|---|
throws |
|
Arguments
- id
int
Value to look up the node by.- key
string
An optional key to look up the node by (parent | left | right). If omitted, the primary key of the table is used.
Response
mixed
Boolean false on failure or node object on success.
_getTreeRepositionData
Method to get various data necessary to make room in the tree at a location for a node and its children. The returned data object includes conditions for SQL WHERE clauses for updating left and right id values to make room for the node as well as the new left and right ids for the node.
_getTreeRepositionData( referenceNode, nodeWidth, position = 'before') :
since |
1.7.0 |
---|
Arguments
- referenceNode
object
A node object with at least a 'lft' and 'rgt' with which to make room in the tree around for a new node.- nodeWidth
int
The width of the node for which to make room in the tree.- position
string
The position relative to the reference node where the room should be made.
Response
mixed
Boolean false on failure or data object on success.
_lock
Method to lock the database table for writing.
_lock() :
since |
1.7.0 |
---|---|
throws |
|
Response
bool
True on success.
_logtable
Method to create a log table in the buffer optionally showing the query and/or data.
_logtable( showData = true, showQuery = true) :
since |
1.7.0 |
---|
Arguments
- showData
bool
True to show data- showQuery
bool
True to show query
Response
void
_runQuery
Runs a query and unlocks the database on an error.
_runQuery( query, errorMessage) :
note |
Since 3.0.0 this method returns void and will rethrow the database exception. |
---|---|
since |
1.7.0 |
throws |
|
Arguments
- query
mixed
A string or DatabaseQuery object.- errorMessage
string
Unused.
Response
void
_unlock
Method to unlock the database table for writing.
_unlock() :
since |
1.7.0 |
---|
Response
bool
True on success.
addIncludePath
Add a filesystem path where Table should search for table class files.
addIncludePath(array|string path = null) : mixed||string|int
since |
1.7.0 |
---|---|
deprecated |
4.3 will be removed in 6.0 Should not be used anymore as tables are loaded through the MvcFactory |
Arguments
- path
array<string|int, mixed>|string
A filesystem path or array of filesystem paths to add.
Response
array<string|int, mixed>
An array of filesystem paths to find Table classes in.
appendPrimaryKeys
Method to append the primary keys for this table to a query.
appendPrimaryKeys(\Joomla\Database\DatabaseQuery query, pk = null) :
since |
3.1.4 |
---|
Arguments
- query
DatabaseQuery
A query object to append.- pk
mixed
Optional primary key parameter.
Response
void
bind
Method to bind an associative array or object to the Table instance.This method only binds properties that are publicly accessible and optionally takes an array of properties to ignore when binding.
bind(array|object src, array|string ignore = []) :
since |
1.7.0 |
---|---|
throws |
|
Arguments
- src
array<string|int, mixed>|object
An associative array or object to bind to the Table instance.- ignore
array<string|int, mixed>|string
An optional array or space separated list of properties to ignore while binding.
Response
bool
True on success.
check
Checks that the object is valid and able to be stored.
check() :
This method checks that the parent_id is non-zero and exists in the database. Note that the root node (parent_id = 0) cannot be manipulated with this class.
since |
1.7.0 |
---|
Response
bool
True if all checks pass.
checkIn
Method to check a row in if the necessary properties/fields exist.
checkIn( pk = null) :
Checking a row in will allow other users the ability to edit the row.
since |
1.7.0 |
---|---|
throws |
|
Arguments
- pk
mixed
An optional primary key value to check out. If not set the instance property value is used.
Response
bool
True on success.
checkOut
Method to check a row out if the necessary properties/fields exist.
checkOut( userId, pk = null) :
To prevent race conditions while editing rows in a database, a row can be checked out if the fields 'checked_out' and 'checked_out_time' are available. While a row is checked out, any attempt to store the row by a user other than the one who checked the row out should be held until the row is checked in again.
since |
1.7.0 |
---|---|
throws |
|
Arguments
- userId
int
The Id of the user checking out the row.- pk
mixed
An optional primary key value to check out. If not set the instance property value is used.
Response
bool
True on success.
debug
Sets the debug level on or off
debug( level) :
since |
1.7.0 |
---|
Arguments
- level
int
0 = off, 1 = on
Response
void
def
Sets a default value if not already assigned
def( property, default = null) :
since |
1.7.0 |
---|---|
deprecated |
4.3.0 will be removed in 6.0 Defining dynamic properties should not be used anymore |
Arguments
- property
string
The name of the property.- default
mixed
The default value.
Response
mixed
delete
Method to delete a node and, optionally, its child nodes from the table.
delete( pk = null, children = true) :
since |
1.7.0 |
---|
Arguments
- pk
int
The primary key of the node to delete.- children
bool
True to delete child nodes, false to move them up a level.
Response
bool
True on success.
get
Returns a property of the object or the default value if the property is not set.
get( property, default = null) :
since |
1.7.0 |
---|---|
see | CMSObject::getProperties() |
deprecated |
4.3.0 will be removed in 6.0 Create a proper getter function for the property |
Arguments
- property
string
The name of the property.- default
mixed
The default value.
Response
mixed
The value of the property.
getColumnAlias
Method to return the real name of a "special" column such as ordering, hits, published etc etc. In this way you are free to follow your db naming convention and use the built in \Joomla functions.
getColumnAlias( column) :
since |
3.4 |
---|
Arguments
- column
string
Name of the "special" column (ie ordering, hits)
Response
string
The string that identify the special
getDbo
Method to get the DatabaseDriver object.
getDbo() : \Joomla\Database\DatabaseDriver
since |
1.7.0 |
---|
Response
DatabaseDriver
The internal database driver object.
getError
Get the most recent error message.
getError( i = null, toString = true) :
since |
1.7.0 |
---|---|
deprecated |
3.1.4 will be removed in 6.0 Will be removed without replacement Catch thrown Exceptions instead of getError |
Arguments
- i
int
Option error index.- toString
bool
Indicates if Exception objects should return their error message.
Response
string
Error message
getErrors
Return all errors, if any.
getErrors() : mixed||string|int
since |
1.7.0 |
---|---|
deprecated |
3.1.4 will be removed in 6.0 Will be removed without replacement Catch thrown Exceptions instead of getErrors |
Response
array<string|int, mixed>
Array of error messages.
getFields
Get the columns from database table.
getFields( reload = false) :
since |
1.7.0 |
---|---|
throws |
|
Arguments
- reload
bool
flag to reload cache
Response
mixed
An array of the field names, or false if an error occurs.
getId
Returns the identity (primary key) value of this record
getId() :
since |
4.0.0 |
---|
Response
mixed
getInstance
Static method to get an instance of a Table class if it can be found in the table include paths.
getInstance( type, prefix = 'JTable', mixed||string|int config = []) : \Joomla\CMS\Table\Table|bool
To add include paths for searching for Table classes see Table::addIncludePath().
since |
1.7.0 |
---|---|
deprecated |
4.3 will be removed in 6.0 Use the MvcFactory instead Example: Factory::getApplication()->bootComponent('...')->getMVCFactory()->createTable($name, $prefix, $config); |
Arguments
- type
string
The type (name) of the Table class to get an instance of.- prefix
string
An optional prefix for the table class name.- config
array<string|int, mixed>
An optional array of configuration values for the Table object.
Response
Table|bool
A Table object if found or boolean false on failure.
getKeyName
Method to get the primary key field name for the table.
getKeyName( multiple = false) :
since |
1.7.0 |
---|
Arguments
- multiple
bool
True to return all primary keys (as an array) or false to return just the first one (as a string).
Response
mixed
Array of primary key field names or string containing the first primary key field.
getNextOrder
Method to get the next ordering value for a group of rows defined by an SQL WHERE clause.
getNextOrder( where = '') :
This is useful for placing a new item last in a group of items in the table.
since |
1.7.0 |
---|---|
throws |
|
Arguments
- where
string
WHERE clause to use for selecting the MAX(ordering) for the table.
Response
int
The next ordering value.
getPath
Method to get an array of nodes from a given node to its root.
getPath( pk = null, diagnostic = false) :
since |
1.7.0 |
---|---|
throws |
|
Arguments
- pk
int
Primary key of the node for which to get the path.- diagnostic
bool
Only select diagnostic data for the nested sets.
Response
mixed
An array of node objects including the start node.
getPrimaryKey
Get the primary key values for this table using passed in values as a default.
getPrimaryKey(mixed||string|int keys = []) : mixed||string|int
since |
3.1.4 |
---|
Arguments
- keys
array<string|int, mixed>
Optional primary key values to use.
Response
array<string|int, mixed>
An array of primary key names and values.
getProperties
Returns an associative array of object properties.
getProperties( public = true) : mixed||string|int
since |
1.7.0 |
---|---|
see | CMSObject::get() |
deprecated |
4.3.0 will be removed in 6.0 Create a proper getter function for the property |
Arguments
- public
bool
If true, returns only the public properties.
Response
array<string|int, mixed>
getRootId
Gets the ID of the root item in the tree
getRootId() :
since |
1.7.0 |
---|
Response
mixed
The primary id of the root row, or false if not found and the internal error is set.
getRules
Method to get the rules for the record.
getRules() : \Joomla\CMS\Access\Rules
getTableName
Method to get the database table name for the class.
getTableName() :
since |
1.7.0 |
---|
Response
string
The name of the database table being modeled.
getTree
Method to get a node and all its child nodes.
getTree( pk = null, diagnostic = false) :
since |
1.7.0 |
---|---|
throws |
|
Arguments
- pk
int
Primary key of the node for which to get the tree.- diagnostic
bool
Only select diagnostic data for the nested sets.
Response
mixed
Boolean false on failure or array of node objects on success.
hasField
Check if the record has a property (applying a column alias if it exists)
hasField( key) :
since |
3.9.11 |
---|
Arguments
- key
string
key to be checked
Response
bool
hasPrimaryKey
Validate that the primary key has been set.
hasPrimaryKey() :
since |
3.1.4 |
---|
Response
bool
True if the primary key(s) have been set.
hit
Method to increment the hits for a row if the necessary property/field exists.
hit( pk = null) :
since |
1.7.0 |
---|---|
throws |
|
Arguments
- pk
mixed
An optional primary key value to increment. If not set the instance property value is used.
Response
bool
True on success.
isCheckedOut
Method to determine if a row is checked out and therefore uneditable by a user.
isCheckedOut( with, against = null) :
If the row is checked out by the same user, then it is considered not checked out -- as the user can still edit it.
since |
1.7.0 |
---|
Arguments
- with
int
The user ID to perform the match with, if an item is checked out by this user the function will return false.- against
int
The user ID to perform the match against when the function is used as a static function.
Response
bool
True if checked out.
isLeaf
Method to determine if a node is a leaf node in the tree (has no children).
isLeaf( pk = null) :
note |
Since 3.0.0 this method returns null if the node does not exist. |
---|---|
since |
1.7.0 |
throws |
|
Arguments
- pk
int
Primary key of the node to check.
Response
bool
True if a leaf node, false if not or null if the node does not exist.
load
Method to load a row from the database by primary key and bind the fields to the Table instance properties.
load( keys = null, reset = true) :
since |
1.7.0 |
---|---|
throws |
|
Arguments
- keys
mixed
An optional primary key value to load the row by, or an array of fields to match. If not set the instance property value is used.- reset
bool
True to reset the default values before loading the new row.
Response
bool
True if successful. False if row not found.
move
Method to move a row in the ordering sequence of a group of rows defined by an SQL WHERE clause.
move( delta, where = '') :
Negative numbers move the row up in the sequence and positive numbers move it down.
since |
1.7.0 |
---|
Arguments
- delta
int
The direction and magnitude to move the row in the ordering sequence.- where
string
WHERE clause to use for limiting the selection of rows to compact the ordering values.
Response
mixed
Boolean true on success.
moveByReference
Method to move a node and its children to a new location in the tree.
moveByReference( referenceId, position = 'after', pk = null, recursiveUpdate = true) :
since |
1.7.0 |
---|---|
throws |
|
Arguments
- referenceId
int
The primary key of the node to reference new location by.- position
string
Location type string. ['before', 'after', 'first-child', 'last-child']- pk
int
The primary key of the node to move.- recursiveUpdate
bool
Flag indicate that method recursiveUpdatePublishedColumn should be call.
Response
bool
True on success.
orderDown
Method to move a node one position to the right in the same level.
orderDown( pk) :
since |
1.7.0 |
---|---|
throws |
|
Arguments
- pk
int
Primary key of the node to move.
Response
bool
True on success.
orderUp
Method to move a node one position to the left in the same level.
orderUp( pk) :
since |
1.7.0 |
---|---|
throws |
|
Arguments
- pk
int
Primary key of the node to move.
Response
bool
True on success.
publish
Method to set the publishing state for a node or list of nodes in the database table. The method respects rows checked out by other users and will attempt to checkin rows that it can after adjustments are made. The method will not allow you to set a publishing state higher than any ancestor node and will not allow you to set a publishing state on a node with a checked out child.
publish( pks = null, state = 1, userId) :
since |
1.7.0 |
---|---|
throws |
|
Arguments
- pks
mixed
An optional array of primary key values to update. If not set the instance property value is used.- state
int
The publishing state. eg. [0 = unpublished, 1 = published]- userId
int
The user id of the user performing the operation.
Response
bool
True on success.
rebuild
Method to recursively rebuild the whole nested set tree.
rebuild( parentId = null, leftId, level, path = '') :
since |
1.7.0 |
---|---|
throws |
|
Arguments
- parentId
int
The root of the tree to rebuild.- leftId
int
The left id to start with in building the tree.- level
int
The level to assign to the current nodes.- path
string
The path to the current nodes.
Response
int
1 + value of root rgt on success, false on failure
rebuildPath
Method to rebuild the node's path field from the alias values of the nodes from the current node to the root node of the tree.
rebuildPath( pk = null) :
since |
1.7.0 |
---|
Arguments
- pk
int
Primary key of the node for which to get the path.
Response
bool
True on success.
recursiveUpdatePublishedColumn
Method to recursive update published column for children rows.
recursiveUpdatePublishedColumn( pk, newState = null) :
since |
3.7.0 |
---|---|
throws |
|
Arguments
- pk
int
Id number of row which published column was changed.- newState
int
An optional value for published column of row identified by $pk.
Response
bool
True on success.
reorder
Method to compact the ordering values of rows in a group of rows defined by an SQL WHERE clause.
reorder(string|string[] where = '') :
since |
1.7.0 |
---|---|
throws |
|
Arguments
- where
string|array<string|int, string>
WHERE clause to use for limiting the selection of rows to compact the ordering values.
Response
mixed
Boolean True on success.
reset
Method to reset class properties to the defaults set in the class definition. It will ignore the primary key as well as any private class properties (except $_errors).
reset() :
since |
3.2.1 |
---|
Response
void
save
Method to provide a shortcut to binding, checking and storing a Table instance to the database table.
save(array|object src, orderingFilter = '', array|string ignore = '') :
The method will check a row in once the data has been stored and if an ordering filter is present will attempt to reorder the table rows based on the filter. The ordering filter is an instance property name. The rows that will be reordered are those whose value matches the Table instance for the property specified.
since |
1.7.0 |
---|
Arguments
- src
array<string|int, mixed>|object
An associative array or object to bind to the Table instance.- orderingFilter
string
Filter for the order updating- ignore
array<string|int, mixed>|string
An optional array or space separated list of properties to ignore while binding.
Response
bool
True on success.
saveorder
Method to update order of table rows
saveorder(mixed||string|int idArray = null, mixed||string|int lftArray = null) : int|bool
since |
1.7.0 |
---|---|
throws |
|
Arguments
- idArray
array<string|int, mixed>
id numbers of rows to be reordered.- lftArray
array<string|int, mixed>
lft values of rows to be reordered.
Response
int|bool
1 + value of root rgt on success, false on failure.
set
Modifies a property of the object, creating it if it does not already exist.
set( property, value = null) :
since |
1.7.0 |
---|---|
deprecated |
4.3.0 will be removed in 6.0 Create a proper setter function for the property |
Arguments
- property
string
The name of the property.- value
mixed
The value of the property to set.
Response
mixed
Previous value of the property.
setColumnAlias
Method to register a column alias for a "special" column.
setColumnAlias( column, columnAlias) :
since |
3.4 |
---|
Arguments
- column
string
The "special" column (ie ordering)- columnAlias
string
The real column name (ie foo_ordering)
Response
void
setDbo
Method to set the DatabaseDriver object.
setDbo(\Joomla\Database\DatabaseDriver db) :
since |
1.7.0 |
---|
Arguments
- db
DatabaseDriver
A DatabaseDriver object to be used by the table object.
Response
bool
True on success.
setError
Add an error message.
setError( error) :
since |
1.7.0 |
---|---|
deprecated |
3.1.4 will be removed in 6.0 Will be removed without replacement Throw an Exception instead of using setError |
Arguments
- error
string
Error message.
Response
void
setLocation
Method to set the location of a node in the tree object. This method does not save the new location to the database, but will set it in the object so that when the node is stored it will be stored in the new location.
setLocation( referenceId, position = 'after') :
note |
Since 3.0.0 this method returns void and throws an \InvalidArgumentException when an invalid position is passed. |
---|---|
see | Nested::$_validLocations |
since |
1.7.0 |
throws |
|
Arguments
- referenceId
int
The primary key of the node to reference new location by.- position
string
Location type string.
Response
void
setProperties
Set the object properties based on a named array/hash.
setProperties( properties) :
since |
1.7.0 |
---|---|
see | CMSObject::set() |
deprecated |
4.3.0 will be removed in 6.0 Create a proper setter function for the property |
Arguments
- properties
mixed
Either an associative array or another object.
Response
bool
setRules
Method to set rules for the record.
setRules( input) :
since |
1.7.0 |
---|
Arguments
- input
mixed
A Rules object, JSON string, or array.
Response
void
store
Method to store a node in the database table.
store( updateNulls = false) :
since |
1.7.0 |
---|
Arguments
- updateNulls
bool
True to update null values as well.
Response
bool
True on success.
Properties
_errors
An array of error messages or Exception objects.
since |
1.7.0 |
---|---|
deprecated |
3.1.4 JError has been deprecated |
Type(s)
array<string|int, mixed>
_includePaths
Include paths for searching for Table classes.
since |
3.0.0 |
---|
Type(s)
array<string|int, mixed>
tableFields
Table fields cache
since |
3.10.4 |
---|
Type(s)
array<string|int, mixed>
_tbl
Name of the database table to model.
since |
1.7.0 |
---|
Type(s)
string
_tbl_key
Name of the primary key field in the table.
since |
1.7.0 |
---|
Type(s)
string
_tbl_keys
Name of the primary key fields in the table.
since |
3.0.1 |
---|
Type(s)
array<string|int, mixed>
_db
DatabaseDriver object.
since |
1.7.0 |
---|
Type(s)
DatabaseDriver
_trackAssets
Should rows be tracked as ACL assets?
since |
1.7.0 |
---|
Type(s)
bool
_locked
Indicator that the tables have been locked.
since |
1.7.0 |
---|
Type(s)
bool
_autoincrement
Indicates that the primary keys autoincrement.
since |
3.1.4 |
---|
Type(s)
bool
_columnAlias
Array with alias for "special" columns such as ordering, hits etc etc
since |
3.4.0 |
---|
Type(s)
array<string|int, mixed>
_jsonEncode
An array of key names to be json encoded in the bind function
since |
3.3 |
---|
Type(s)
array<string|int, mixed>
_supportNullValue
Indicates that columns fully support the NULL value in the database
since |
3.10.0 |
---|
Type(s)
bool
typeAlias
The UCM type alias. Used for tags, content versioning etc. Leave blank to effectively disable these features.
since |
4.0.0 |
---|
Type(s)
string
parent_id
Object property holding the primary key of the parent node. Provides adjacency list data for nodes.
since |
1.7.0 |
---|
Type(s)
int
level
Object property holding the depth level of the node in the tree.
since |
1.7.0 |
---|
Type(s)
int
lft
Object property holding the left value of the node for managing its placement in the nested sets tree.
since |
1.7.0 |
---|
Type(s)
int
rgt
Object property holding the right value of the node for managing its placement in the nested sets tree.
since |
1.7.0 |
---|
Type(s)
int
alias
Object property holding the alias of this node used to construct the full text path, forward-slash delimited.
since |
1.7.0 |
---|
Type(s)
string
_location
Object property to hold the location type to use when storing the row.
_location_id
Object property to hold the primary key of the location reference node to use when storing the row.
A combination of location type and reference node describes where to store the current node in the tree.
since |
1.7.0 |
---|
Type(s)
int
_cache
An array to cache values in recursive processes.
since |
1.7.0 |
---|
Type(s)
array<string|int, mixed>
_debug
Debug level
since |
1.7.0 |
---|
Type(s)
int
root_id
Cache for the root ID
since |
3.3 |
---|
Type(s)
int
_validLocations
Array declaring the valid location values for moving a node
since |
3.7.0 |
---|
Type(s)
array<string|int, mixed>