Tree removing top level nodes (was Tree removing nodes)
| From: | Joseph Blythe | Date: | Wed, 21 May 2003 01:11:31 +0000 |
| Subject: | Tree removing top level nodes (was Tree removing nodes) | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-5492@lists.php.net to get a copy of this message | ||
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 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