PHP Класс FOF30\Model\TreeModel

Наследование: extends DataModel
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$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

Открытые методы

Метод Описание
__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

Защищенные методы

Метод Описание
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

Описание методов

__construct() публичный Метод

Public constructor. Overrides the parent constructor, making sure there are lft/rgt columns which make it compatible with nested sets.
См. также: 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() публичный Метод

Overrides the DataModel's buildQuery to allow nested set searches using the provided scopes
public buildQuery ( boolean $overrideLimits = false ) : JDatabaseQuery
$overrideLimits boolean
Результат JDatabaseQuery

check() публичный Метод

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

copy() публичный Метод

Makes a copy of the record, inserting it as the last child of the current node's parent.
public copy ( $data = null ) : static
Результат static

create() публичный Метод

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
Результат static The new node

equals() публичный Метод

Is $node this very node?
public equals ( TreeModel &$node ) : boolean
$node TreeModel
Результат boolean

findByPath() публичный Метод

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
Результат TreeModel | null The found node or null if nothing is found

forceDelete() публичный Метод

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() публичный Метод

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
Результат FOF30\Model\DataModel\Collection

getAncestorsAndSelf() публичный Метод

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
Результат FOF30\Model\DataModel\Collection

getAncestorsAndSelfWithoutRoot() публичный Метод

Get all ancestors to this node and the node itself, but not the root node. If you want to
public getAncestorsAndSelfWithoutRoot ( ) : Collection
Результат FOF30\Model\DataModel\Collection

getAncestorsWithoutRoot() публичный Метод

Get all ancestors to this node but not the node itself and its root.
public getAncestorsWithoutRoot ( ) : Collection
Результат FOF30\Model\DataModel\Collection

getDescendants() публичный Метод

Note: all descendant nodes, even descendants of our immediate descendants, will be returned.
public getDescendants ( ) : Collection
Результат FOF30\Model\DataModel\Collection

getDescendantsAndSelf() публичный Метод

Note: all descendant nodes, even descendants of our immediate descendants, will be returned.
public getDescendantsAndSelf ( ) : Collection
Результат FOF30\Model\DataModel\Collection

getImmediateDescendants() публичный Метод

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
Результат FOF30\Model\DataModel\Collection

getLeaves() публичный Метод

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
Результат FOF30\Model\DataModel\Collection

getLevel() публичный Метод

Gets the level (depth) of this node in the tree. The result is cached in $this->treeDepth for faster retrieval.
public getLevel ( ) : integer | mixed
Результат integer | mixed

getNestedList() публичный Метод

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
Результат array

getParent() публичный Метод

Returns the immediate parent of the current node
public getParent ( ) : static
Результат static

getRoot() публичный Метод

Returns the root node of the tree this node belongs to
public getRoot ( ) : static
Результат static

getSiblings() публичный Метод

Get all sibling nodes, except ourselves
public getSiblings ( ) : Collection
Результат FOF30\Model\DataModel\Collection

getSiblingsAndSelf() публичный Метод

Get all sibling nodes, including ourselves
public getSiblingsAndSelf ( ) : Collection
Результат FOF30\Model\DataModel\Collection

inSameScope() публичный Метод

Returns true if both this node and $otherNode are root, leaf or child (same tree scope)
public inSameScope ( TreeModel $otherNode ) : boolean
$otherNode TreeModel
Результат boolean

insertAsChildOf() публичный Метод

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

insertAsFirstChildOf() публичный Метод

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() публичный Метод

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() публичный Метод

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
Результат static

insertAsSiblingOf() публичный Метод

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

insertLeftOf() публичный Метод

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() публичный Метод

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() публичный Метод

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
Результат boolean

isAncestorOf() публичный Метод

Returns true if we are an ancestor of $otherNode
public isAncestorOf ( TreeModel $otherNode ) : boolean
$otherNode TreeModel
Результат boolean

isChild() публичный Метод

Is this a child node (not root)?
public isChild ( ) : boolean
Результат boolean

isDescendantOf() публичный Метод

Returns true if we are a descendant of $otherNode
public isDescendantOf ( TreeModel $otherNode ) : boolean
$otherNode TreeModel
Результат boolean

isLeaf() публичный Метод

Is this a leaf node (a node without children)?
public isLeaf ( ) : boolean
Результат boolean

isRoot() публичный Метод

Is this a top-level root node?
public isRoot ( ) : boolean
Результат boolean

isSelfOrAncestorOf() публичный Метод

Returns true if $otherNode is ourselves or we are an ancestor of $otherNode
public isSelfOrAncestorOf ( TreeModel $otherNode ) : boolean
$otherNode TreeModel
Результат boolean

isSelfOrDescendantOf() публичный Метод

Returns true if $otherNode is ourselves or if we are a descendant of $otherNode
public isSelfOrDescendantOf ( TreeModel $otherNode ) : boolean
$otherNode TreeModel
Результат boolean

makeChildOf() публичный Метод

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

makeFirstChildOf() публичный Метод

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

makeLastChildOf() публичный Метод

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

makeNextSiblingOf() публичный Метод

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

makePreviousSiblingOf() публичный Метод

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

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
public makeRoot ( )

makeSiblingOf() публичный Метод

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

move() публичный Метод

Not supported in nested sets
public move ( integer $delta, string $where = '' ) : static
$delta integer Ignored
$where string Ignored
Результат static Self, for chaining

moveLeft() публичный Метод

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() публичный Метод

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() публичный Метод

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() публичный Метод

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 onAfterDelete ( $oid )

reorder() публичный Метод

Not supported in nested sets
public reorder ( string $where = '' ) : static
$where string Ignored
Результат static Self, for chaining

reset() публичный Метод

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
Результат static Self, for chaining

resetTreeCache() защищенный Метод

Resets cached values used to speed up querying the tree
protected resetTreeCache ( ) : static
Результат static for chaining

scopeAncestors() защищенный Метод

get() will return all ancestor nodes but not ourselves
protected scopeAncestors ( ) : void
Результат void

scopeAncestorsAndSelf() защищенный Метод

get() will return all ancestor nodes and ourselves
protected scopeAncestorsAndSelf ( ) : void
Результат void

scopeDescendants() защищенный Метод

get() will return all descendants (even subtrees of subtrees!) but not ourselves
protected scopeDescendants ( ) : void
Результат void

scopeDescendantsAndSelf() защищенный Метод

get() will return all descendants (even subtrees of subtrees!) and ourselves
protected scopeDescendantsAndSelf ( ) : void
Результат void

scopeImmediateDescendants() защищенный Метод

get() will only return immediate descendants (first level children) of the current node
protected scopeImmediateDescendants ( ) : void
Результат void

scopeLeaves() защищенный Метод

get() will return only leaf nodes
protected scopeLeaves ( ) : void
Результат void

scopeSiblings() защищенный Метод

get() will return all sibling nodes but not ourselves
protected scopeSiblings ( ) : void
Результат void

scopeSiblingsAndSelf() защищенный Метод

get() will return all sibling nodes and ourselves
protected scopeSiblingsAndSelf ( ) : void
Результат void

scopeWithoutRoot() защищенный Метод

get() will not return our root if it's part of the query results
protected scopeWithoutRoot ( ) : void
Результат void

scopeWithoutSelf() защищенный Метод

get() will not return ourselves if it's part of the query results
protected scopeWithoutSelf ( ) : void
Результат void

withoutNode() публичный Метод

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
Результат void

Описание свойств

$treeDepth защищенное свойство

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

$treeNestedGet защищенное свойство

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

$treeParent защищенное свойство

The parent node of ourselves
protected $treeParent

$treeRoot защищенное свойство

The root node in the tree
protected $treeRoot