Re: DB_Nested 1.3 createRootNode problem

From: Date: Mon, 27 Oct 2003 16:07:39 +0000
Subject: Re: DB_Nested 1.3 createRootNode problem
References: 1 2  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-23037@lists.php.net to get a copy of this message
Hi, I would suggest breaking createRootNode() into two methods, createFirstRootNode() and addRootNode(). The API would be function createFirstRootNode($values) function addRootNode($values, $id, $_pos = 'AF') <--- also, shouldn't 'AF' be the constant NESE_MOVE_AFTER? You needn't remove createRootNode(), but you should deprecate it in favor of these two new methods in the documentation, and make them a wrapper of createRootNode(). Optional parameters was a bad choice since they really aren't optional for the creation of a new tree, or for adding a root node to a tree. I would also strongly encourage you to drop the explicit specification of a mode in _raiseError(). You needn't change any of the calls to _raiseError() immediately, but simply pass in null instead of $mode to PEAR::raiseError(). I don't like seeing packages controlling error handling, that is an application realm. This is a great package, I look forward to getting to know it intimately and pushing it around until it does what I need :) Greg Daniel Khan wrote:
Arnaud Limbourg wrote:
the createRootNode method fails with 1.3 of DB_NestedSet. function prototype is as follows function createRootNode($values, $id = false, $first = false, $_pos = 'AF') { $id and $first are optional. If a call to createRootNode is made as such $nestedSet->createRootNode($values); The creation fails because both $id and $first are false the test is always true. test is done as follows
createRootNode() needs either $values and $id or $values and $first. Reason: $first is only a flag to indicate that you really know what you are doing. If $first is set, a new tree is built which means that the old get's _deleted_. The method doesn't look that nice atm - but I have to keep it for BC reasons. Normally you only need createRootNode() to create the first node of the tree. All other rootnodes can be created by calling createRightNode()/createLeftNode() on a rootnode. greetings Daniel Khan


« previous php.pear.dev (#23037) next »