components/AuthBehavior.php
public function getDescendant($itemName, $depth = 0)
    {
        $descendants = array();
        $children = $this->getChildren($itemName);
        if (empty($children)) {
            $children = $this->owner->db->createCommand()
                ->select('child')
                ->from($this->owner->itemChildTable)
                ->where('parent=:parent', array(':parent' => $itemName))
                ->queryColumn();
            $this->setItemChildren($itemName, $children);
        }

        foreach ($children as $child) {
            $descendants[$child] = array(
                'name' => $child,
                'item' => $this->owner->getAuthItem($child),
                'children' => $this->getDescendant($child, $depth + 1),
                'depth' => $depth,
            );
        }
        return $descendants;
    }
public function getDescendant($itemName, $depth = 0)
    {
        $descendants = array();
        $children = $this->getChildren($itemName);
        if (empty($children)) {
            $children = $this->owner->db->createCommand()
                ->select('child')
                ->from($this->owner->itemChildTable)
                ->where('parent=:parent', array(':parent' => $itemName))
                ->queryColumn();
            $this->setItemChildren($itemName, $children);
        }

        foreach ($children as $child) {
            $descendants[$child] = array(
                'name' => $child,
                'item' => $this->owner->getAuthItem($child),
                'children' => $this->getDescendant($child, $depth + 1),
                'depth' => $depth,
            );
        }
        return $descendants;
    }
public function getDescendant ( $ itemName , $ depth = 0 ) { $ descendants = array ( ) ; $ children = $ this -> getChildren ( $ itemName ) ; if ( empty ( $ children ) ) { $ children = $ this -> owner -> db -> createCommand ( ) -> select ( 'child' ) -> from ( $ this -> owner -> itemChildTable ) -> where ( 'parent=:parent' , array ( ':parent' => $ itemName ) ) -> queryColumn ( ) ; $ this -> setItemChildren ( $ itemName , $ children ) ; } foreach ( $ children as $ child ) { $ descendants [ $ child ] = array ( 'name' => $ child , 'item' => $ this -> owner -> getAuthItem ( $ child ) , 'children' => $ this -> getDescendant ( $ child , $ depth + 1 ) , 'depth' => $ depth , ) ; } return $ descendants ; }
Returns all the descendants for the given item recursively.
@param string $itemName name of the item.
@param integer $depth current depth.
@return array the descendants.
Returns all the descendants for the given item recursively .