/** * @param bool $accessChecks * @param bool $load * * @return bool|NodeModel */ public function findRoot($accessChecks = true, $load = true) { $node = new self(); if ($accessChecks === false) { $node->ignoreAccessControl = true; } $lastParent = $this->getPK(); $parent = $this->has('parent') ? $this->getParent(false) : false; while ($parent) { $lastParent = $parent; $node->loadByPK($parent); $parent = $node->has('parent') ? $node->getParent(false) : false; } if ($lastParent === $this->getPK()) { return $this; } else { if ($lastParent) { if ($load) { $root = new self(); if (!$accessChecks) { $root->ignoreAccessControl = true; } $root->loadByPK($lastParent); return $root; } else { return (string) $lastParent; } } } // TODO: we can never reach this? return false; }