PHP Class FOF30\Model\TreeModel

Inheritance: extends DataModel
Afficher le fichier Open project: akeeba/fof Class Usage Examples

Protected Properties

Свойство Type Description
$treeDepth The level (depth) of this node in the tree
$treeNestedGet Should I perform a nested get (used to query ascendants/descendants)
$treeParent The parent node of ourselves
$treeRoot The root node in the tree

Méthodes publiques

Méthode Description
__construct ( Container $container = null, array $config = [] ) Public constructor. Overrides the parent constructor, making sure there are lft/rgt columns which make it compatible with nested sets.
buildQuery ( boolean $overrideLimits = false ) : JDatabaseQuery Overrides the DataModel's buildQuery to allow nested set searches using the provided scopes
check ( ) Overrides the automated table checks to handle the 'hash' column for faster searching
copy ( $data = null ) : static Makes a copy of the record, inserting it as the last child of the current node's parent.
create ( array $data ) : static Create a new record with the provided data. It is inserted as the last child of the current node's parent
equals ( TreeModel &$node ) : boolean Is $node this very node?
findByPath ( string $path ) : TreeModel | null Locate a node from a given path, e.g. "/some/other/leaf"
forceDelete ( mixed $id = null ) Delete a node, either the currently loaded one or the one specified in $id. If an $id is specified that node is loaded before trying to delete it. In the end the data model is reset. If the node has any children nodes they will be removed before the node itself is deleted.
getAncestors ( ) : Collection Get all ancestors to this node but not the node itself. In other words it gets the path to the node, without the node itself.
getAncestorsAndSelf ( ) : Collection Get all ancestors to this node and the node itself. In other words it gets the full path to the node and the node itself.
getAncestorsAndSelfWithoutRoot ( ) : Collection Get all ancestors to this node and the node itself, but not the root node. If you want to
getAncestorsWithoutRoot ( ) : Collection Get all ancestors to this node but not the node itself and its root.
getDescendants ( ) : Collection Get only our descendant (children) nodes, not ourselves.
getDescendantsAndSelf ( ) : Collection Get all descendant (children) nodes and ourselves.
getImmediateDescendants ( ) : Collection Get the immediate descendants (children). Unlike getDescendants it only goes one level deep into the tree structure. Descendants of descendant nodes will not be returned.
getLeaves ( ) : Collection Get all leaf nodes in the tree. You may want to use the scopes to narrow down the search in a specific subtree or path.
getLevel ( ) : integer | mixed Gets the level (depth) of this node in the tree. The result is cached in $this->treeDepth for faster retrieval.
getNestedList ( string $column = 'title', null $key = null, string $seperator = ' ' ) : array Returns a hashed array where each element's key is the value of the $key column (default: the ID column of the table) and its value is the value of the $column column (default: title). Each nesting level will have the value of the $column column prefixed by a number of $separator strings, as many as its nesting level (depth).
getParent ( ) : static Returns the immediate parent of the current node
getRoot ( ) : static Returns the root node of the tree this node belongs to
getSiblings ( ) : Collection Get all sibling nodes, except ourselves
getSiblingsAndSelf ( ) : Collection Get all sibling nodes, including ourselves
inSameScope ( TreeModel $otherNode ) : boolean Returns true if both this node and $otherNode are root, leaf or child (same tree scope)
insertAsChildOf ( TreeModel &$parentNode ) Alias for insertAsLastchildOf
insertAsFirstChildOf ( TreeModel &$parentNode ) Insert the current node as the first (leftmost) child of a parent node.
insertAsLastChildOf ( TreeModel &$parentNode ) Insert the current node as the last (rightmost) child of a parent node.
insertAsRoot ( ) : static Insert the current node as a tree root. It is a good idea to never use this method, instead providing a root node in your schema installation and then sticking to only one root.
insertAsSiblingOf ( TreeModel &$siblingNode ) Alias for insertRightOf
insertLeftOf ( TreeModel &$siblingNode ) Insert the current node to the left of (before) a sibling node
insertRightOf ( TreeModel &$siblingNode ) Insert the current node to the right of (after) a sibling node
insideSubtree ( TreeModel $otherNode ) : boolean Checks if our node is inside the subtree of $otherNode. This is a fast check as only lft and rgt values have to be compared.
isAncestorOf ( TreeModel $otherNode ) : boolean Returns true if we are an ancestor of $otherNode
isChild ( ) : boolean Is this a child node (not root)?
isDescendantOf ( TreeModel $otherNode ) : boolean Returns true if we are a descendant of $otherNode
isLeaf ( ) : boolean Is this a leaf node (a node without children)?
isRoot ( ) : boolean Is this a top-level root node?
isSelfOrAncestorOf ( TreeModel $otherNode ) : boolean Returns true if $otherNode is ourselves or we are an ancestor of $otherNode
isSelfOrDescendantOf ( TreeModel $otherNode ) : boolean Returns true if $otherNode is ourselves or if we are a descendant of $otherNode
makeChildOf ( TreeModel $parentNode ) Alias for makeLastChildOf
makeFirstChildOf ( TreeModel $parentNode ) Moves a node and its subtree as a the first (leftmost) child of $parentNode
makeLastChildOf ( TreeModel $parentNode ) Moves a node and its subtree as a the last (rightmost) child of $parentNode
makeNextSiblingOf ( TreeModel $siblingNode ) Alias for moveToRightOf
makePreviousSiblingOf ( TreeModel $siblingNode ) Alias for moveToLeftOf
makeRoot ( ) Makes the current node a root (and moving its entire subtree along the way). This is achieved by moving the node to the right of its root node
makeSiblingOf ( TreeModel $siblingNode ) Alias for makeNextSiblingOf
move ( integer $delta, string $where = '' ) : static Not supported in nested sets
moveLeft ( ) Move the current node (and its subtree) one position to the left in the tree, i.e. before its left-hand sibling
moveRight ( ) Move the current node (and its subtree) one position to the right in the tree, i.e. after its right-hand sibling
moveToLeftOf ( TreeModel $siblingNode ) Moves the current node (and its subtree) to the left of another node. The other node can be in a different position in the tree or even under a different root.
moveToRightOf ( TreeModel $siblingNode ) Moves the current node (and its subtree) to the right of another node. The other node can be in a different position in the tree or even under a different root.
reorder ( string $where = '' ) : static Not supported in nested sets
reset ( boolean $useDefaults = true, boolean $resetRelations = false ) : static Reset the record data and the tree cache
withoutNode ( TreeModel $node ) : void get() will not return the selected node if it's part of the query results

Méthodes protégées

Méthode Description
onAfterDelete ( $oid )
resetTreeCache ( ) : static Resets cached values used to speed up querying the tree
scopeAncestors ( ) : void get() will return all ancestor nodes but not ourselves
scopeAncestorsAndSelf ( ) : void get() will return all ancestor nodes and ourselves
scopeDescendants ( ) : void get() will return all descendants (even subtrees of subtrees!) but not ourselves
scopeDescendantsAndSelf ( ) : void get() will return all descendants (even subtrees of subtrees!) and ourselves
scopeImmediateDescendants ( ) : void get() will only return immediate descendants (first level children) of the current node
scopeLeaves ( ) : void get() will return only leaf nodes
scopeSiblings ( ) : void get() will return all sibling nodes but not ourselves
scopeSiblingsAndSelf ( ) : void get() will return all sibling nodes and ourselves
scopeWithoutRoot ( ) : void get() will not return our root if it's part of the query results
scopeWithoutSelf ( ) : void get() will not return ourselves if it's part of the query results

Method Details

__construct() public méthode

Public constructor. Overrides the parent constructor, making sure there are lft/rgt columns which make it compatible with nested sets.
See also: FOF30\Model\DataModel::__construct()
public __construct ( Container $container = null, array $config = [] )
$container FOF30\Container\Container The configuration variables to this model
$config array Configuration values for this model

buildQuery() public méthode

Overrides the DataModel's buildQuery to allow nested set searches using the provided scopes
public buildQuery ( boolean $overrideLimits = false ) : JDatabaseQuery
$overrideLimits boolean
Résultat JDatabaseQuery

check() public méthode

Overrides the automated table checks to handle the 'hash' column for faster searching
public check ( )

copy() public méthode

Makes a copy of the record, inserting it as the last child of the current node's parent.
public copy ( $data = null ) : static
Résultat static

create() public méthode

Create a new record with the provided data. It is inserted as the last child of the current node's parent
public create ( array $data ) : static
$data array The data to use in the new record
Résultat static The new node

equals() public méthode

Is $node this very node?
public equals ( TreeModel &$node ) : boolean
$node TreeModel
Résultat boolean

findByPath() public méthode

Notes: - This will only work when you have a "slug" and a "hash" field in your table. - If the path starts with "/" we will use the root with lft=1. Otherwise the first component of the path is supposed to be the slug of the root node. - If the root node is not found you'll get null as the return value - You will also get null if any component of the path is not found
public findByPath ( string $path ) : TreeModel | null
$path string The path to locate
Résultat TreeModel | null The found node or null if nothing is found

forceDelete() public méthode

Delete a node, either the currently loaded one or the one specified in $id. If an $id is specified that node is loaded before trying to delete it. In the end the data model is reset. If the node has any children nodes they will be removed before the node itself is deleted.
public forceDelete ( mixed $id = null )
$id mixed Primary key (id field) value

getAncestors() public méthode

Get all ancestors to this node but not the node itself. In other words it gets the path to the node, without the node itself.
public getAncestors ( ) : Collection
Résultat FOF30\Model\DataModel\Collection

getAncestorsAndSelf() public méthode

Get all ancestors to this node and the node itself. In other words it gets the full path to the node and the node itself.
public getAncestorsAndSelf ( ) : Collection
Résultat FOF30\Model\DataModel\Collection

getAncestorsAndSelfWithoutRoot() public méthode

Get all ancestors to this node and the node itself, but not the root node. If you want to
public getAncestorsAndSelfWithoutRoot ( ) : Collection
Résultat FOF30\Model\DataModel\Collection

getAncestorsWithoutRoot() public méthode

Get all ancestors to this node but not the node itself and its root.
public getAncestorsWithoutRoot ( ) : Collection
Résultat FOF30\Model\DataModel\Collection

getDescendants() public méthode

Note: all descendant nodes, even descendants of our immediate descendants, will be returned.
public getDescendants ( ) : Collection
Résultat FOF30\Model\DataModel\Collection

getDescendantsAndSelf() public méthode

Note: all descendant nodes, even descendants of our immediate descendants, will be returned.
public getDescendantsAndSelf ( ) : Collection
Résultat FOF30\Model\DataModel\Collection

getImmediateDescendants() public méthode

Get the immediate descendants (children). Unlike getDescendants it only goes one level deep into the tree structure. Descendants of descendant nodes will not be returned.
public getImmediateDescendants ( ) : Collection
Résultat FOF30\Model\DataModel\Collection

getLeaves() public méthode

Get all leaf nodes in the tree. You may want to use the scopes to narrow down the search in a specific subtree or path.
public getLeaves ( ) : Collection
Résultat FOF30\Model\DataModel\Collection

getLevel() public méthode

Gets the level (depth) of this node in the tree. The result is cached in $this->treeDepth for faster retrieval.
public getLevel ( ) : integer | mixed
Résultat integer | mixed

getNestedList() public méthode

This is useful for creating HTML select elements showing the hierarchy in a human readable format.
public getNestedList ( string $column = 'title', null $key = null, string $seperator = ' ' ) : array
$column string
$key null
$seperator string
Résultat array

getParent() public méthode

Returns the immediate parent of the current node
public getParent ( ) : static
Résultat static

getRoot() public méthode

Returns the root node of the tree this node belongs to
public getRoot ( ) : static
Résultat static

getSiblings() public méthode

Get all sibling nodes, except ourselves
public getSiblings ( ) : Collection
Résultat FOF30\Model\DataModel\Collection

getSiblingsAndSelf() public méthode

Get all sibling nodes, including ourselves
public getSiblingsAndSelf ( ) : Collection
Résultat FOF30\Model\DataModel\Collection

inSameScope() public méthode

Returns true if both this node and $otherNode are root, leaf or child (same tree scope)
public inSameScope ( TreeModel $otherNode ) : boolean
$otherNode TreeModel
Résultat boolean

insertAsChildOf() public méthode

Alias for insertAsLastchildOf
public insertAsChildOf ( TreeModel &$parentNode )
$parentNode TreeModel

insertAsFirstChildOf() public méthode

WARNING: If it's an existing node it will be COPIED, not moved.
public insertAsFirstChildOf ( TreeModel &$parentNode )
$parentNode TreeModel The node which will become our parent

insertAsLastChildOf() public méthode

WARNING: If it's an existing node it will be COPIED, not moved.
public insertAsLastChildOf ( TreeModel &$parentNode )
$parentNode TreeModel The node which will become our parent

insertAsRoot() public méthode

Insert the current node as a tree root. It is a good idea to never use this method, instead providing a root node in your schema installation and then sticking to only one root.
public insertAsRoot ( ) : static
Résultat static

insertAsSiblingOf() public méthode

Alias for insertRightOf
public insertAsSiblingOf ( TreeModel &$siblingNode )
$siblingNode TreeModel

insertLeftOf() public méthode

WARNING: If it's an existing node it will be COPIED, not moved.
public insertLeftOf ( TreeModel &$siblingNode )
$siblingNode TreeModel We will be inserted before this node

insertRightOf() public méthode

WARNING: If it's an existing node it will be COPIED, not moved.
public insertRightOf ( TreeModel &$siblingNode )
$siblingNode TreeModel We will be inserted after this node

insideSubtree() public méthode

Checks if our node is inside the subtree of $otherNode. This is a fast check as only lft and rgt values have to be compared.
public insideSubtree ( TreeModel $otherNode ) : boolean
$otherNode TreeModel
Résultat boolean

isAncestorOf() public méthode

Returns true if we are an ancestor of $otherNode
public isAncestorOf ( TreeModel $otherNode ) : boolean
$otherNode TreeModel
Résultat boolean

isChild() public méthode

Is this a child node (not root)?
public isChild ( ) : boolean
Résultat boolean

isDescendantOf() public méthode

Returns true if we are a descendant of $otherNode
public isDescendantOf ( TreeModel $otherNode ) : boolean
$otherNode TreeModel
Résultat boolean

isLeaf() public méthode

Is this a leaf node (a node without children)?
public isLeaf ( ) : boolean
Résultat boolean

isRoot() public méthode

Is this a top-level root node?
public isRoot ( ) : boolean
Résultat boolean

isSelfOrAncestorOf() public méthode

Returns true if $otherNode is ourselves or we are an ancestor of $otherNode
public isSelfOrAncestorOf ( TreeModel $otherNode ) : boolean
$otherNode TreeModel
Résultat boolean

isSelfOrDescendantOf() public méthode

Returns true if $otherNode is ourselves or if we are a descendant of $otherNode
public isSelfOrDescendantOf ( TreeModel $otherNode ) : boolean
$otherNode TreeModel
Résultat boolean

makeChildOf() public méthode

Alias for makeLastChildOf
public makeChildOf ( TreeModel $parentNode )
$parentNode TreeModel

makeFirstChildOf() public méthode

Moves a node and its subtree as a the first (leftmost) child of $parentNode
public makeFirstChildOf ( TreeModel $parentNode )
$parentNode TreeModel

makeLastChildOf() public méthode

Moves a node and its subtree as a the last (rightmost) child of $parentNode
public makeLastChildOf ( TreeModel $parentNode )
$parentNode TreeModel

makeNextSiblingOf() public méthode

Alias for moveToRightOf
public makeNextSiblingOf ( TreeModel $siblingNode )
$siblingNode TreeModel

makePreviousSiblingOf() public méthode

Alias for moveToLeftOf
public makePreviousSiblingOf ( TreeModel $siblingNode )
$siblingNode TreeModel

makeRoot() public méthode

Makes the current node a root (and moving its entire subtree along the way). This is achieved by moving the node to the right of its root node
public makeRoot ( )

makeSiblingOf() public méthode

Alias for makeNextSiblingOf
public makeSiblingOf ( TreeModel $siblingNode )
$siblingNode TreeModel

move() public méthode

Not supported in nested sets
public move ( integer $delta, string $where = '' ) : static
$delta integer Ignored
$where string Ignored
Résultat static Self, for chaining

moveLeft() public méthode

Move the current node (and its subtree) one position to the left in the tree, i.e. before its left-hand sibling
public moveLeft ( )

moveRight() public méthode

Move the current node (and its subtree) one position to the right in the tree, i.e. after its right-hand sibling
public moveRight ( )

moveToLeftOf() public méthode

Moves the current node (and its subtree) to the left of another node. The other node can be in a different position in the tree or even under a different root.
public moveToLeftOf ( TreeModel $siblingNode )
$siblingNode TreeModel

moveToRightOf() public méthode

Moves the current node (and its subtree) to the right of another node. The other node can be in a different position in the tree or even under a different root.
public moveToRightOf ( TreeModel $siblingNode )
$siblingNode TreeModel

onAfterDelete() protected méthode

protected onAfterDelete ( $oid )

reorder() public méthode

Not supported in nested sets
public reorder ( string $where = '' ) : static
$where string Ignored
Résultat static Self, for chaining

reset() public méthode

Reset the record data and the tree cache
public reset ( boolean $useDefaults = true, boolean $resetRelations = false ) : static
$useDefaults boolean Should I use the default values? Default: yes
$resetRelations boolean Should I reset the relations too? Default: no
Résultat static Self, for chaining

resetTreeCache() protected méthode

Resets cached values used to speed up querying the tree
protected resetTreeCache ( ) : static
Résultat static for chaining

scopeAncestors() protected méthode

get() will return all ancestor nodes but not ourselves
protected scopeAncestors ( ) : void
Résultat void

scopeAncestorsAndSelf() protected méthode

get() will return all ancestor nodes and ourselves
protected scopeAncestorsAndSelf ( ) : void
Résultat void

scopeDescendants() protected méthode

get() will return all descendants (even subtrees of subtrees!) but not ourselves
protected scopeDescendants ( ) : void
Résultat void

scopeDescendantsAndSelf() protected méthode

get() will return all descendants (even subtrees of subtrees!) and ourselves
protected scopeDescendantsAndSelf ( ) : void
Résultat void

scopeImmediateDescendants() protected méthode

get() will only return immediate descendants (first level children) of the current node
protected scopeImmediateDescendants ( ) : void
Résultat void

scopeLeaves() protected méthode

get() will return only leaf nodes
protected scopeLeaves ( ) : void
Résultat void

scopeSiblings() protected méthode

get() will return all sibling nodes but not ourselves
protected scopeSiblings ( ) : void
Résultat void

scopeSiblingsAndSelf() protected méthode

get() will return all sibling nodes and ourselves
protected scopeSiblingsAndSelf ( ) : void
Résultat void

scopeWithoutRoot() protected méthode

get() will not return our root if it's part of the query results
protected scopeWithoutRoot ( ) : void
Résultat void

scopeWithoutSelf() protected méthode

get() will not return ourselves if it's part of the query results
protected scopeWithoutSelf ( ) : void
Résultat void

withoutNode() public méthode

get() will not return the selected node if it's part of the query results
public withoutNode ( TreeModel $node ) : void
$node TreeModel The node to exclude from the results
Résultat void

Property Details

$treeDepth protected_oe property

The level (depth) of this node in the tree
protected $treeDepth

$treeNestedGet protected_oe property

Should I perform a nested get (used to query ascendants/descendants)
protected $treeNestedGet

$treeParent protected_oe property

The parent node of ourselves
protected $treeParent

$treeRoot protected_oe property

The root node in the tree
protected $treeRoot