/**
+----------------------------------------------------------
* 当前节点下子孙节点总数.
子孙总数=(当前节点的右值 - 当前节点的左值-1)/2
* @access public
* @param $node_id int 节点$this->_id
* @return $amount int
该节点下的子孙总数 *
+----------------------------------------------------------
*/
public
function
getChildCount(
$nodeId
)
{
$currentNode
=
$this
->getNodeById(
$nodeId
);
if
(!
empty
(
$currentNode
))
{
return
(int)(
$currentNode
[
$this
->_right]-
$currentNode
[
$this
->_left] -1)/2;
}
}
/**
+----------------------------------------------------------
*
获取当前节点下所有子节点。当 A 子类的右节点=B 子类左节点-1
则 A、B 属于同一级别
* @access public
* @param $curentId
* @param $type int 0:当前节点下所有子类,1 为当前节点下一级子类
* @return bool
+----------------------------------------------------------
*/
public
function
getChild(
$nodeId
,
$type
=0)
{
$currentNode
=
$this
->getNodeById(
$nodeId
);
if
(
$currentNode
[
$this
->_left]-
$currentNode
[
$this
->_right] ==1)
{
return
false;
//
当 该节点左值 - 右值=1 时,其下没有子节点。
}
else
{
$condition
=
$this
->_left.'>'.
$currentNode
[
$this
->_left].' and '.
$this
->_right .'<'.
$currentNode
[
$this
->_right];
$child
=
$this
->where(
$condition
)->findAll();
if
(
$type
== 0)
//所有子类
{
return
$child
;
}