components/AuthBehavior.php
public function getAncestor($itemName, $depth = 0)
    {
        $ancestors = array();
        $parents = $this->getParents($itemName);
        if (empty($parents)) {
            $parents = $this->owner->db->createCommand()
                ->select('parent')
                ->from($this->owner->itemChildTable)
                ->where('child=:child', array(':child' => $itemName))
                ->queryColumn();
            $this->setItemParents($itemName, $parents);
        }

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

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