PHP 클래스 FOF30\Model\TreeModel

상속: extends DataModel
파일 보기 프로젝트 열기: akeeba/fof 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$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