PHP 클래스 Tree\NestedTree\NestedTree

파일 보기 프로젝트 열기: nilsteampassnet/TeamPass

공개 메소드들

메소드 설명
__construct ( string $table, string $idField, string $parentField, string $sortField ) Constructor. Set the database table name and necessary field names
generateTreeData ( &$arr, integer $id, integer $level, &$n ) Generate the tree data. A single call to this generates the n-values for 1 node in the tree. This function assigns the passed in n value as the node's nleft value. It then processes all the node's children (which in turn recursively processes that node's children and so on), and when it is finally done, it takes the update n-value and assigns it as its nright value. Because it is passed as a reference, the subsequent changes in subrequests are held over to when control is returned so the nright can be assigned.
getChildren ( integer $id, boolean $includeSelf = false ) : array Fetch the children of a node, or if no node is specified, fetch the top level items.
getDescendants ( integer $id, boolean $includeSelf = false, boolean $childrenOnly = false, $unique_id_list = false ) : array Fetch the descendants of a node, or if no node is specified, fetch the entire tree. Optionally, only return child data instead of all descendant data.
getFields ( ) : array A utility function to return an array of the fields that need to be selected in SQL select queries
getImmediateFamily ( integer $id ) : array Fetch the immediately family of a node. More specifically, fetch a node's parent, siblings and children. If the node isn't valid, fetch the first level of nodes from the tree.
getNode ( integer $id ) : object Fetch the node data for the node identified by $id
getPath ( integer $id, boolean $includeSelf = false ) : array Fetch the path to a node. If an invalid node is passed, an empty array is returned.
getTreeWithChildren ( ) : array Fetch the tree data, nesting within each node references to the node's children
isChildOf ( integer $child_id, integer $parent_id ) : boolean Check if one node is a child of another node. If either node is not found, then false is returned.
isDescendantOf ( integer $descendant_id, integer $ancestor_id ) : boolean Check if one node descends from another node. If either node is not found, then false is returned.
numChildren ( integer $id ) : integer Find the number of children a node has
numDescendants ( integer $id ) : integer Find the number of descendants a node has
rebuild ( ) Rebuilds the tree data and saves it to the database

메소드 상세

__construct() 공개 메소드

Constructor. Set the database table name and necessary field names
public __construct ( string $table, string $idField, string $parentField, string $sortField )
$table string Name of the tree database table
$idField string Name of the primary key ID field
$parentField string Name of the parent ID field
$sortField string Name of the field to sort data.

generateTreeData() 공개 메소드

Generate the tree data. A single call to this generates the n-values for 1 node in the tree. This function assigns the passed in n value as the node's nleft value. It then processes all the node's children (which in turn recursively processes that node's children and so on), and when it is finally done, it takes the update n-value and assigns it as its nright value. Because it is passed as a reference, the subsequent changes in subrequests are held over to when control is returned so the nright can be assigned.
public generateTreeData ( &$arr, integer $id, integer $level, &$n )
$id integer The ID of the current node to process
$level integer The nlevel to assign to the current node

getChildren() 공개 메소드

Fetch the children of a node, or if no node is specified, fetch the top level items.
public getChildren ( integer $id, boolean $includeSelf = false ) : array
$id integer The ID of the node to fetch child data for.
$includeSelf boolean Whether or not to include the passed node in the the results.
리턴 array The children of the passed node

getDescendants() 공개 메소드

Fetch the descendants of a node, or if no node is specified, fetch the entire tree. Optionally, only return child data instead of all descendant data.
public getDescendants ( integer $id, boolean $includeSelf = false, boolean $childrenOnly = false, $unique_id_list = false ) : array
$id integer The ID of the node to fetch descendant data for. Specify an invalid ID (e.g. 0) to retrieve all data.
$includeSelf boolean Whether or not to include the passed node in the the results. This has no meaning if fetching entire tree.
$childrenOnly boolean True if only returning children data. False if returning all descendant data
리턴 array The descendants of the passed now

getFields() 공개 메소드

A utility function to return an array of the fields that need to be selected in SQL select queries
public getFields ( ) : array
리턴 array An indexed array of fields to select

getImmediateFamily() 공개 메소드

Fetch the immediately family of a node. More specifically, fetch a node's parent, siblings and children. If the node isn't valid, fetch the first level of nodes from the tree.
public getImmediateFamily ( integer $id ) : array
$id integer The ID of the node to fetch child data for.
리턴 array An array of each node in the family

getNode() 공개 메소드

Fetch the node data for the node identified by $id
public getNode ( integer $id ) : object
$id integer The ID of the node to fetch
리턴 object An object containing the node's data, or null if node not found

getPath() 공개 메소드

If a top level node is passed, an array containing on that node is included (if 'includeSelf' is set to true, otherwise an empty array)
public getPath ( integer $id, boolean $includeSelf = false ) : array
$id integer The ID of the node to fetch child data for.
$includeSelf boolean Whether or not to include the passed node in the the results.
리턴 array An array of each node to passed node

getTreeWithChildren() 공개 메소드

Fetch the tree data, nesting within each node references to the node's children
public getTreeWithChildren ( ) : array
리턴 array The tree with the node's child data

isChildOf() 공개 메소드

Check if one node is a child of another node. If either node is not found, then false is returned.
public isChildOf ( integer $child_id, integer $parent_id ) : boolean
$child_id integer The node that is possibly a child
$parent_id integer The node that is possibly a parent
리턴 boolean True if $child_id is a child of $parent_id, false otherwise

isDescendantOf() 공개 메소드

Check if one node descends from another node. If either node is not found, then false is returned.
public isDescendantOf ( integer $descendant_id, integer $ancestor_id ) : boolean
$descendant_id integer The node that potentially descends
$ancestor_id integer The node that is potentially descended from
리턴 boolean True if $descendant_id descends from $ancestor_id, false otherwise

numChildren() 공개 메소드

Find the number of children a node has
public numChildren ( integer $id ) : integer
$id integer The ID of the node to search for. Pass 0 to count the first level items
리턴 integer The number of descendants the node has, or -1 if the node isn't found.

numDescendants() 공개 메소드

Find the number of descendants a node has
public numDescendants ( integer $id ) : integer
$id integer The ID of the node to search for. Pass 0 to count all nodes in the tree.
리턴 integer The number of descendants the node has, or -1 if the node isn't found.

rebuild() 공개 메소드

Rebuilds the tree data and saves it to the database
public rebuild ( )