By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,051 Members | 1,221 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,051 IT Pros & Developers. It's quick & easy.

Writing a Category Hierarchy where to research?

P: n/a
I'm looking into writing a Category Hierarchy on a site I've written
and am looking for some information about writing this kind of code.
Maybe some samples or a book. Any information would be helpful.

Thanks,

Troy Lynch
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Troy Lynch wrote:
I'm looking into writing a Category Hierarchy on a site I've written
and am looking for some information about writing this kind of code.
Maybe some samples or a book. Any information would be helpful.

Thanks,

Troy Lynch


Hi Troy,

Mabe you are looking for something like this?

<?php
// Copyright (c) the partners of MetaClass, 2003, 2004
// Licensed under the Academic Free License version 2.0

includeClass('PntDbObject', 'pnt/db');

class TreeItem extends PntDbObject {

var $parentId = 0;

function initPropertyDescriptors() {
parent::initPropertyDescriptors();

$this->addFieldProp('parentId', 'number', false, null, null, 1, '6,0');
$this->addDerivedProp('parent', 'TreeItem', false);
$prop =& $this->addMultiValueProp('children', 'TreeItem');
$prop->setTwinName('parent');

$this->addFieldProp('name', 'string', false, null, null, 0, '40');
}

/** @static
* @return String the name of the database table the instances are
stored in
* @abstract - override for each subclass
*/
function getTableName()
{
return 'ex_tree';
}

/** Returns the directory of the class file
* @static
* @return String
*/
function getClassDir()
{
return 'exampleA1';
}

function getLabel()
{
return $this->name;
}

}
?>

To try it out go:

http://www.phppeanuts.org/examples/e...tType=TreeItem

In the user interface it may not look like a tree, but that is a matter
of web page design. To make objects of some other peanuts class in the
same application classFolder reference to a tree item, all you have to
do is add the following to its initPropertyDescriptors() method:

$this->addFieldProp('categoryId', 'number', false, null, null, 1, '6,0');
$this->addDerivedProp('category', 'TreeItem', false);

and add a categoryId column to its database table. Assuming you did not
override the default edit details page and uiFieldProperties for the
class, this will automaticly enable the selection of a category from a
list or, if there are many categories, from a search dialog. If you
write your own dialog class and name it TreeItemDialog you can make a
nice visual representation of the category tree to select from and it
will be used automaticly by the default edit details page.

Greetings,

Henk Verhoeven,
www.phpPeanuts.org.

BTW, the example is not in the download. It requires a few more files,
very similar to example 1. Anyone interested please send me an email if
you want to receive the complete exampleA1 by email.

Jul 17 '05 #2

P: n/a
Troy Lynch wrote:
I'm looking into writing a Category Hierarchy on a site I've written
and am looking for some information about writing this kind of code.
Maybe some samples or a book. Any information would be helpful.

Thanks,

Troy Lynch


I just added a simple graphical representation, see
http://www.phppeanuts.org/examples/exampleA1/

its code:

printBranches( getRoots() );

function printBranches(&$treeItems, $depth=0)
{
while (list($key) = each($treeItems) ) {
for ($i=0; $i<$depth; $i++)
print "&nbsp;&nbsp;&nbsp;";
$item =& $treeItems[$key];
?><A HREF='index.php?pntType=TreeItem&id=<?php print $item->get('id') ?>'
title='edit details'><?php print $item->get('name') ?></A><BR>
<?php
printBranches($item->get('children'), $depth + 1);
}
}

Groeten,

Henk Verhoeven,
www.phpPeanuts.org.

Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.