Re: re: Tree navigation via links

From: Date: Wed, 30 Apr 2003 08:46:48 +0000
Subject: Re: re: Tree navigation via links
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-5134@lists.php.net to get a copy of this message
i dont know if that is really what you need, but you could try hasChildren($id) this tells you if the element has children, if not you know you are at the end of the tree (so to say at a 'leaf') regards wolfram Joseph Blythe wrote:
Hey all, Just got a bit further with this thanks to Wolfram :) it was just me not using the class properly as usual! At the moment there are only two levels of categories have to test more depth later, but my next problem is trying to find out when to list the products as I will never know how many levels of catergories there may be, so it needs to query the product database at the point when it hits the last level of children for a given node. What I got so far pretty much acts as I would like, I know there is probaly a better way of doing this suggestions anyone? Please see link below to see what I got so far: http://demo.optcom.net.au/categories_test.php Regards, Joseph -----Original Message----- From: Wolfram Kriesing [mailto:wolfram@visionp.de] Sent: Tuesday, 29 April 2003 6:49 PM To: Joseph Blythe Cc: Pear-General (E-mail) Subject: Re: [PEAR] re: Tree navigation via links could you please send me the code and the DB-dump off-list, i will try to figure out what the problem is. thanks wolfram Joseph Blythe wrote:
Hi Wolfram, Thankyou for you feedback, just what I needed to get my brain into gear :) I had a good look at the mentioned tutorial on the excellant phpkitchen website, and tried to get a working example running but soon ran into problems, I dont think I not passing the options correctly or something ?
I
have tried to trace this through the classes but soon lost the plot :) I have tried passing options quite a number of ways also using the 'columnNameMaps' index containg an array but still get undefined index
error
messages from Common.php The _myTree database table looks like so: id int(11) unsigned NOT NULL auto_increment, name varchar(50) NOT NULL default '', l int(11) unsigned NOT NULL default '0', r int(11) unsigned NOT NULL default '0', parent int(11) unsigned NOT NULL default '0', comment varchar(255) NOT NULL default '', user_id int(11) NOT NULL default '0', PRIMARY KEY (id) I have tried to keep it really simple so I can work out whats happening
have
a look at: http://demo.optcom.net.au/categories.php The root of the above site is the catalogue demo I am working on very unfinished :) products.php would list all of the root nodes on left menu then when one is clicked display the children in center of page, when one
of
these is clicked it would just keep going through categories until it hit
a
product, then display the actual product. I have allows viewing of source as I have nothing worth hiding :) Hope this helps explain things better think am very close. Regards, Joseph -----Original Message----- From: Wolfram Kriesing [mailto:wolfram@visionp.de] Sent: Monday, 28 April 2003 6:14 PM To: Joseph Blythe Cc: Pear-General (E-mail) Subject: Re: [PEAR] re: Tree navigation via links Hi Joseph, I think you need to use the Dynamic_DB* interface for your tree, this way you can read out the data you really need. Please see http://www.phpkitchen.com/article.php?story=20030427152620585 for a introductory tutorial Your problem, you might attack it like this: $root = $tree->getRoot(); $rootId = $root['id']; // get the first level, that means all the children of the root $firstLevel = $tree->getChildren($rootId); // get the entire path to your current element // where the $_REQUEST['id'] is simply the element the user had // clicked on $path = $tree->getPath($_REQUEST['id']); // and to show the user the children of the current item // you might want to do this $children = $tree->getChildren($_REQUEST['id']); now you only have to render the data :-) properly therefore you might want to build an array like this which you simply have to loop through later ... // the very first item is always the root, i guess // if you dont need the root, simply leave out this line $items = array($root); foreach ($firstLevel as $aNode) {
    $items[] = $aNode;
    // add the $path at the appropriate place
    if ($aNode['id'] == $path[1]['id']) {
        array_shift($path); // remove the root
        array_shift($path); // remove the node which is equal $aNode
        array_merge($items,$path); // add all the other items
    }
} i havent tried the code, but i hope i could transport the idea. i know it should be easier. if any of you has an idea how to make it easier, may be adding a method in Tree, which does that ... your input is welcome regards Wolfram Joseph Blythe wrote:
Hey all, I was wondering how one would go about navigating a PEAR Tree structure by using links, what I would like to be able to do is list all the top level nodes as links and as the user clicks through each one it would pass it's
id
and list all of its children (using the same page). I do not want to
display
the whole tree at one time, only the top level nodes then each child. The reason I am thinking of this is I have a bunch of product categories
in
a DB and need a easy way to allow a user to navigate them, because the categories are content managed and infinite I have to have to find a way
to
navigate them to the product level easily no matter how many categories it takes to reach them. I have a working Tree_Menu, using the same data but this is far from what
I
want on the display/navigation side, I hope this makes some sense if
anyone
has any suggestions/examples or just want to tell me how stupid I am then feel free ) I guess I was thinking of maybe trying to extend Tree_Menu to allow this kind of navigation but I must admit is probally beyond me at the moment. Any help appreciated, Regards, 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 -- 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 (#5134) next »