/** * Function: getNearestCommonAncestor * * Returns the nearest common ancestor for the specified cells. * * Parameters: * * cell1 - <mxCell> that specifies the first cell in the tree. * cell2 - <mxCell> that specifies the second cell in the tree. */ function getNearestCommonAncestor($cell1, $cell2) { if ($cell1 != null && $cell2 != null) { // Creates the cell path for the second cell $path = mxCellPath::create($cell2); if (isset($path) && strlen($path) > 0) { // Bubbles through the ancestors of the target // cell to find the nearest common ancestor. $cell = $cell1; $current = mxCellPath::create($cell); while ($cell != null) { $parent = $this->getParent($cell); // Checks if the cell path is equal to the beginning // of the given cell path if (strpos($path, $current . mxCellPath::$PATH_SEPARATOR) === 0 && $parent != null) { return $cell; } $current = mxCellPath::getParentPath($current); $cell = $parent; } } } return null; }