public function add($parentId, Branch $branch) { $this->branches[$branch->getNodeId()] = $branch; if (null === $this->root) { $this->root = $parentId ? $this->branches[$parentId] = new UnknownNodeBranch($branch) : $branch; } else { if (false === isset($this->branches[$parentId])) { // hidden from nav, don’t return the whole section then: return $this; } $this->branches[$parentId]->add($branch); } return $this; }
/** * @param Branch $branch * @param Branch $currentBranch * * @return array * @throws \Exception */ public function getPreviousSibling(Branch $branch, Branch $currentBranch) { $current = null; $previousSibiling = null; foreach ($branch->getChildren() as $node) { if ($node->getNodeId() === $currentBranch->getNodeId()) { $current = $node; } if (!$current) { $previousSibiling = $node; } if ($previousSibiling && $current) { break; } } return $previousSibiling; }