public function tree() { $_tree = Set::model()->findAll(array('order' => $this->leftAttribute)); $left = $this->leftAttribute; $right = $this->rightAttribute; $root = $this->rootAttribute; $level = array(); $ancestors = array(); foreach (self::$_tree as $item) { $root = $item->root; if (!isset($ancestors[$root])) { $ancestors[$root] = array(); } if (!isset($level[$root])) { $level[$root] = 1; } $item->_ancestors = array(); $ancestors[$root][$item->level] = $item; foreach ($ancestors[$root] as $l => $node) { if ($level < $node->level) { break; } if ($node->$left < $item->$left && $node->$right > $item->$right) { $item->_ancestors[] = $node; } } $level = $item->level; } return self::$_tree; }