Class JTableNested
Table class supporting modified pre-order tree traversal behavior.
-
JObject
-
JTable
implements
JObservableInterface,
JTableInterface
-
JTableNested
Methods summary
public
|
#
debug( integer $level )
Sets the debug level on or off
Sets the debug level on or off
Parameters
- $level
integer - $level 0 = off, 1 = on
Since
11.1
|
public
mixed
|
#
getPath( integer $pk = null, boolean $diagnostic = false )
Method to get an array of nodes from a given node to its root.
Method to get an array of nodes from a given node to its root.
Parameters
- $pk
integer - $pk Primary key of the node for which to get the path.
- $diagnostic
boolean - $diagnostic Only select diagnostic data for the nested sets.
Returns
mixed - An array of node objects including the start node.
Throws
Since
11.1
|
public
mixed
|
#
getTree( integer $pk = null, boolean $diagnostic = false )
Method to get a node and all its child nodes.
Method to get a node and all its child nodes.
Parameters
- $pk
integer - $pk Primary key of the node for which to get the tree.
- $diagnostic
boolean - $diagnostic Only select diagnostic data for the nested sets.
Returns
mixed - Boolean false on failure or array of node objects on success.
Throws
Since
11.1
|
public
boolean
|
#
isLeaf( integer $pk = null )
Method to determine if a node is a leaf node in the tree (has no
children).
Method to determine if a node is a leaf node in the tree (has no
children).
Parameters
- $pk
integer - $pk Primary key of the node to check.
Returns
boolean - True if a leaf node, false if not or null if the node does not exist.
Throws
Since
11.1
Note
Since 12.1 this method returns null if the node does not exist.
|
public
|
#
setLocation( integer $referenceId, string $position = 'after' )
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.
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.
Parameters
- $referenceId
integer - $referenceId The primary key of the node to reference new location by.
- $position
string - $position Location type string.
Throws
Since
11.1
See
JTableNested::$_validLocations
Note
Since 12.1 this method returns void and throws an InvalidArgumentException when
an invalid position is passed.
|
public
mixed
|
#
move( integer $delta, string $where = '' )
Method to move a row in the ordering sequence of a group of rows defined by
an SQL WHERE clause. Negative numbers move the row up in the sequence and
positive numbers move it down.
Method to move a row in the ordering sequence of a group of rows defined by
an SQL WHERE clause. Negative numbers move the row up in the sequence and
positive numbers move it down.
Parameters
- $delta
integer - $delta The direction and magnitude to move the row in the ordering sequence.
- $where
string - $where WHERE clause to use for limiting the selection of rows to compact the
ordering values.
Returns
mixed - Boolean true on success.
Throws
Since
11.1
Overrides
|
public
boolean
|
#
moveByReference( integer $referenceId, string $position = 'after', integer $pk = null, boolean $recursiveUpdate = true )
Method to move a node and its children to a new location in the tree.
Method to move a node and its children to a new location in the tree.
Parameters
- $referenceId
integer - $referenceId The primary key of the node to reference new location by.
- $position
string - $position Location type string. ['before', 'after', 'first-child', 'last-child']
- $pk
integer - $pk The primary key of the node to move.
- $recursiveUpdate
boolean - $recursiveUpdate Flag indicate that method recursiveUpdatePublishedColumn should
be call.
Returns
boolean - True on success.
Throws
Since
11.1
|
public
boolean
|
#
delete( integer $pk = null, boolean $children = true )
Method to delete a node and, optionally, its child nodes from the table.
Method to delete a node and, optionally, its child nodes from the table.
Parameters
- $pk
integer - $pk The primary key of the node to delete.
- $children
boolean - $children True to delete child nodes, false to move them up a level.
Returns
boolean - True on success.
Throws
Since
11.1
Overrides
|
public
boolean
|
#
check( )
Checks that the object is valid and able to be stored.
Checks that the object is valid and able to be stored.
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.
Returns
boolean - True if all checks pass.
Since
11.1
Overrides
|
public
boolean
|
#
store( boolean $updateNulls = false )
Method to store a node in the database table.
Method to store a node in the database table.
Parameters
- $updateNulls
boolean - $updateNulls True to update null values as well.
Returns
boolean - True on success.
Since
11.1
Overrides
|
public
boolean
|
#
publish( mixed $pks = null, integer $state = 1, integer $userId = 0 )
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.
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.
Parameters
- $pks
mixed - $pks An optional array of primary key values to update. If not set the instance
property value is used.
- $state
integer - $state The publishing state. eg. [0 = unpublished, 1 = published]
- $userId
integer - $userId The user id of the user performing the operation.
Returns
boolean - True on success.
Throws
Since
11.1
Overrides
|
public
boolean
|
#
orderUp( integer $pk )
Method to move a node one position to the left in the same level.
Method to move a node one position to the left in the same level.
Parameters
- $pk
integer - $pk Primary key of the node to move.
Returns
boolean - True on success.
Throws
Since
11.1
|
public
boolean
|
#
orderDown( integer $pk )
Method to move a node one position to the right in the same level.
Method to move a node one position to the right in the same level.
Parameters
- $pk
integer - $pk Primary key of the node to move.
Returns
boolean - True on success.
Throws
Since
11.1
|
public
mixed
|
#
getRootId( )
Gets the ID of the root item in the tree
Gets the ID of the root item in the tree
Returns
mixed - The primary id of the root row, or false if not found and the internal error is
set.
Since
11.1
|
public
integer
|
#
rebuild( integer $parentId = null, integer $leftId = 0, integer $level = 0, string $path = '' )
Method to recursively rebuild the whole nested set tree.
Method to recursively rebuild the whole nested set tree.
Parameters
- $parentId
integer - $parentId The root of the tree to rebuild.
- $leftId
integer - $leftId The left id to start with in building the tree.
- $level
integer - $level The level to assign to the current nodes.
- $path
string - $path The path to the current nodes.
Returns
integer - 1 + value of root rgt on success, false on failure
Throws
Since
11.1
|
public
boolean
|
#
rebuildPath( integer $pk = null )
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.
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.
Parameters
- $pk
integer - $pk Primary key of the node for which to get the path.
Returns
boolean - True on success.
Since
11.1
|
public
|
#
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).
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).
Since
3.2.1
Overrides
|
public
integer
|
#
saveorder( array $idArray = null, array $lft_array = null )
Method to update order of table rows
Method to update order of table rows
Parameters
- $idArray
array - $idArray id numbers of rows to be reordered.
- $lft_array
array - $lft_array lft values of rows to be reordered.
Returns
integer - 1 + value of root rgt on success, false on failure.
Throws
Since
11.1
|
protected
boolean
|
#
recursiveUpdatePublishedColumn( integer $pk, integer $newState = null )
Method to recursive update published column for children rows.
Method to recursive update published column for children rows.
Parameters
- $pk
integer - $pk Id number of row which published column was changed.
- $newState
integer - $newState An optional value for published column of row identified by $pk.
Returns
boolean - True on success.
Throws
Since
3.7.0
|
protected
mixed
|
#
_getNode( integer $id, string $key = null )
Method to get nested set properties for a node in the tree.
Method to get nested set properties for a node in the tree.
Parameters
- $id
integer - $id Value to look up the node by.
- $key
string - $key An optional key to look up the node by (parent | left | right). If omitted,
the primary key of the table is used.
Returns
mixed - Boolean false on failure or node object on success.
Throws
Since
11.1
|
protected
mixed
|
#
_getTreeRepositionData( object $referenceNode, integer $nodeWidth, string $position = 'before' )
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.
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.
Parameters
- $referenceNode
object - $referenceNode A node object with at least a 'lft' and 'rgt' with which to make
room in the tree around for a new node.
- $nodeWidth
integer - $nodeWidth The width of the node for which to make room in the tree.
- $position
string - $position The position relative to the reference node where the room should be
made.
Returns
mixed - Boolean false on failure or data object on success.
Since
11.1
|
protected
|
#
_logtable( boolean $showData = true, boolean $showQuery = true )
Method to create a log table in the buffer optionally showing the query
and/or data.
Method to create a log table in the buffer optionally showing the query
and/or data.
Parameters
- $showData
boolean - $showData True to show data
- $showQuery
boolean - $showQuery True to show query
Since
11.1
CodeCoverageIgnore
|
protected
boolean
|
#
_runQuery( mixed $query, string $errorMessage )
Runs a query and unlocks the database on an error.
Runs a query and unlocks the database on an error.
Parameters
- $query
mixed - $query A string or JDatabaseQuery object.
- $errorMessage
string - $errorMessage Unused.
Returns
boolean - void
Throws
Since
11.1
Note
Since 12.1 this method returns void and will rethrow the database exception.
|
Methods inherited from JTable
__construct()
,
_getAssetName()
,
_getAssetParentId()
,
_getAssetTitle()
,
_lock()
,
_unlock()
,
addIncludePath()
,
appendPrimaryKeys()
,
attachObserver()
,
bind()
,
checkIn()
,
checkOut()
,
getColumnAlias()
,
getDbo()
,
getFields()
,
getInstance()
,
getKeyName()
,
getNextOrder()
,
getObserverOfClass()
,
getPrimaryKey()
,
getRules()
,
getTableName()
,
hasPrimaryKey()
,
hit()
,
isCheckedOut()
,
load()
,
reorder()
,
save()
,
setColumnAlias()
,
setDbo()
,
setRules()
Methods inherited from JObject
__toString()
,
def()
,
get()
,
getError()
,
getErrors()
,
getProperties()
,
set()
,
setError()
,
setProperties()
Magic methods summary
Properties summary
public
integer
|
$parent_id
|
#
Object property holding the primary key of the parent node. Provides
adjacency list data for nodes.
Object property holding the primary key of the parent node. Provides
adjacency list data for nodes.
Since
11.1
|
public
integer
|
$level
|
#
Object property holding the depth level of the node in the tree.
Object property holding the depth level of the node in the tree.
Since
11.1
|
public
integer
|
$lft
|
#
Object property holding the left value of the node for managing its placement
in the nested sets tree.
Object property holding the left value of the node for managing its placement
in the nested sets tree.
Since
11.1
|
public
integer
|
$rgt
|
#
Object property holding the right value of the node for managing its
placement in the nested sets tree.
Object property holding the right value of the node for managing its
placement in the nested sets tree.
Since
11.1
|
public
string
|
$alias
|
#
Object property holding the alias of this node used to constuct the full text
path, forward-slash delimited.
Object property holding the alias of this node used to constuct the full text
path, forward-slash delimited.
Since
11.1
|
protected
string
|
$_location
|
#
Object property to hold the location type to use when storing the row.
Object property to hold the location type to use when storing the row.
Since
11.1
See
JTableNested::$_validLocations
|
protected
integer
|
$_location_id
|
#
Object property to hold the primary key of the location reference node to use
when storing the row.
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
11.1
|
protected
array
|
$_cache
|
#
An array to cache values in recursive processes.
An array to cache values in recursive processes.
Since
11.1
|
protected
integer
|
$_debug
|
|
protected static
integer
|
$root_id
|
#
Cache for the root ID
Since
3.3
|
Properties inherited from JTable
$_autoincrement
,
$_columnAlias
,
$_db
,
$_jsonEncode
,
$_locked
,
$_observers
,
$_rules
,
$_tbl
,
$_tbl_key
,
$_tbl_keys
,
$_trackAssets
Properties inherited from JObject
$_errors