function test_convertModel() { $rnc = 3; $depth = 1; $npl = 2; $this->_createSubNode($rnc, $depth, $npl); DB_NestedSet::convertTreeModel($this->_NeSe, $this->_NeSe2); $this->_NeSe->setSortMode(NESE_SORT_LEVEL); $this->_NeSe2->setSortMode(NESE_SORT_LEVEL); $this->assertEquals($this->_NeSe->getAllNodes(true), $this->_NeSe2->getAllNodes(true), 'Converted tree should match original'); }
/** * Convert a <1.3 tree into a 1.3 tree format * * This will convert the tree into a format needed for some new features in * 1.3. Your <1.3 tree will still work without converting but some new features * like preorder sorting won't work as expected. * * <pre> * Usage: * - Create a new node table (tb_nodes2) from the current node table (tb_nodes1) (only copy the structure). * - Create a nested set instance of the 'old' set (NeSe1) and one of the new set (NeSe2) * - Now you have 2 identical objects where only node_table differs * - Call DB_NestedSet::convertTreeModel(&$orig, &$copy); * - After that you have a cleaned up copy of tb_nodes1 inside tb_nodes2 * </pre> * * @param object DB_NestedSet $orig Nested set we want to copy * @param object DB_NestedSet $copy Object where the new tree is copied to * @param integer $_parent ID of the parent node (private) * * @static * @access public * @return bool True uns success */ function convertTreeModel(&$orig, &$copy, $_parent = false) { static $firstSet; $isRoot = false; if (!$_parent) { if (!is_object($orig) || !is_object($copy)) { return false; } if ($orig->node_table == $copy->node_table) { return false; } $copy->_dumbmode = true; $orig->sortMode = NESE_SORT_LEVEL; $copy->sortMode = NESE_SORT_LEVEL; $sibl = $orig->getRootNodes(true); $isRoot = true; } else { $sibl = $orig->getChildren($_parent, true); } if (empty($sibl)) { return false; } foreach ($sibl as $sid => $sibling) { unset($sibling['l']); unset($sibling['r']); unset($sibling['norder']); $values = array(); foreach ($sibling as $key => $val) { if (!isset($copy->_flparams[$key])) { continue; } $values[$copy->_flparams[$key]] = $val; } if (!$firstSet) { $psid = $copy->createRootNode($values, false, true); $firstSet = true; } elseif ($isRoot) { $psid = $copy->createRightNode($psid, $values); } else { $copy->createSubNode($_parent, $values); } DB_NestedSet::convertTreeModel($orig, $copy, $sid); } return true; }