TreeBehavior::rootIds PHP Method

rootIds() public method

returns the object ids that are at the top of trees.
public rootIds ( )
    public function rootIds()
    {
        $owner = $this->getOwner();
        $db = $owner->getDbConnection();
        $query = 'SELECT leaf.id FROM (SELECT leaf.' . $this->idAttribute . ' AS id, (COUNT(parent. ' . $this->idAttribute . ') -1) AS DEPTH ' . 'FROM ' . $owner->treeTable() . ' AS leaf, ' . $owner->treeTable() . ' AS parent ' . 'WHERE leaf.' . $this->leftAttribute . ' BETWEEN parent.' . $this->leftAttribute . ' AND parent.' . $this->rightAttribute . ' GROUP BY leaf.id) as leaf WHERE depth = 0';
        echo $query;
        $res = $db->createCommand($query)->query();
        $ids = array();
        foreach ($res as $r) {
            $ids[] = $r['id'];
        }
        return $ids;
    }