RE: [PEAR] Tree removing top level nodes (was Tree removing nodes)

From: Date: Thu, 22 May 2003 05:54:20 +0000
Subject: RE: [PEAR] Tree removing top level nodes (was Tree removing nodes)
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-5534@lists.php.net to get a copy of this message
Hi Wolfram, LOL I am so stupid at times yes you must have a top level node and then it all works properly, although I did build the whole Tree using the class methods but I didn't build it the right way obviously :) Thankyou for all you help is much appreciated, Regards, Joseph -----Original Message----- From: Wolfram Kriesing [mailto:wolfram@visionp.de] Sent: Thursday, 22 May 2003 12:17 AM To: Joseph Blythe Cc: Pear-General (E-mail) Subject: Re: [PEAR] Tree removing top level nodes (was Tree removing nodes) Joseph Blythe wrote: > Hey Wolfram, > > I guess I was trying to say is that I can not seem to successfully delete a > top level (root) node as it will delete all others on the same level as > itself for example: > > +---level 1_1 (1) > | +----level 2_1 (2) > | +----level 2_2 (3) > | +-----level 3_1 (4) > | +-----level 4_1 (5) > +---level 1_2 (6) > +---level 1_3 (7) > > > Level 1_x has ParentId's of 0 > Level 2_x has ParentId's of 1 > Level 3_x has ParentId's of 3 > Level 4_x has ParentId's of 4 > > In the diagram above if I removed level 1_1 with $tree->remove(1); level 1_2 > and level 1_3 would also be removed even if I manually set > $tree->RemoveRecursively = "false" it still will remove all nodes on that > level as they are children of the root node (parentId 0) > > If I delete level 4_1 then it would only delete level 4_1 (as expected) if I > remove level 3_1 with tree->RemoveRecursively = "true"; then both level 3_1 > and 4_1 are removed (as expected) > > So if I wanted to just remove level 1_2 even with tree->RemoveRecursively = > "false"; the result would be that level 1_1, level 1_2 and level 1_3 would > be removed. Does this make better sense I can not seem to find a way around > it but to not allow the top level nodes to be deleted. i hope i understand you right. the way your tree is setup seems a little strange to me, do level 1_1 and level 1_2 have a root element below? because that would be necessary to properly use the Tree-class. A tree always has a single root-node, so that your tree actually should look like this: ---root (1) +---level 1_1 (3) | +----level 2_1 (4) | +----level 2_2 (5) | +-----level 3_1 (6) | +-----level 4_1 (7) +---level 1_2 (8) +---level 1_3 (9) or like this ---root (1) +---level 1_1 (3) | +----level 2_1 (4) | +----level 2_2 (5) | +-----level 3_1 (6) | +-----level 4_1 (7) ---root1 (8) +---level 1_2 (9) +---level 1_3 (10) where the second case would only work if you use the 'whereAddOn' option, which means that you have an additional column in your DB-table, which stores an ID for the tree (i.e. if you have a tree for each user). The tree you showed didnt have a single root, which is necessary to properly work. I dont even know if the tree you showed can be handled at all. the nested set requires to have a single root (as every tree, i guess :-)) btw. the removeRecursively doesnt work in the DBnested. iirc it only works for the DBsimple. sorry should have written that somewhere. hth regards wolfram > I would fix this if I could write a better remove() method but I am afraid > my understanding of the inner workings of Tree classes and PEAR in general > is pretty basic I can barely understand what is happening :) > > Hope this explains my problem better, > > Thankyou for the help, > > Regards, > > Joseph > > -----Original Message----- > From: Wolfram Kriesing [mailto:wolfram@visionp.de] > Sent: Tuesday, 20 May 2003 6:27 PM > To: Joseph Blythe > Cc: Pear-General (E-mail) > Subject: Re: [PEAR] Tree removing nodes > > > i am not sure if i understand what you mean, but why dont you just > write your own remove() method which checks > $tree->hasChildren($nodeIdToRemove) > before removing? > > hth > > Wolfram > > Joseph Blythe wrote: > >>Hey all, >> >>Is there a way to just remove one node at a time ? I don't mind if a node >>and all it children get deleted but this really isnt the best situation > > when > >>its a root node (parentId = 0) >> >>For example consider the situation below id's 1-5 are root nodes 6-8 are >>children of id 1 if I remvoved id one 1 -5 are also removed ? >> >>id Parent name >>1 0 One >>2 0 Two >>3 0 Three >>4 0 Four >>5 0 Five >>6 1 Six >>7 1 Seven >>8 1 Eight >> >>--snip >> >>$options = array( >> 'table' => 'categories', >> 'whereAddOn' => 'user_id=0'); >> >>$tree = Tree::setup('Dynamic_DBnested', $dsn, $options); >> >>$node = $tree->remove($_GET['id']); >> >>if (PEAR::isError($node)) { >> echo "Error deleting node: " . $node->getUserInfo(); >>} >> >>snip-- >> >>Anyone suggest a way to get out of this I tried the _remove() method > > nothing > >>happens ? >> >>Any help appreciated, >> >>Joseph Blythe >> >> > > > > -- > Wolfram > > ... opensource @ vision:produktion ... > http://opensource.visionp.de > > ... translating template engine .... > http://sf.net/projects/simpletpl > > ... authentication system .... > http://sf.net/projects/auth > > > -- > PEAR General Mailing List (http://pear.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >  > > -- Wolfram ... opensource @ vision:produktion ... http://opensource.visionp.de ... translating template engine .... http://sf.net/projects/simpletpl ... authentication system .... http://sf.net/projects/auth

« previous php.pear.general (#5534) next »