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('P ntDbObject', 'pnt/db');
class TreeItem extends PntDbObject {
var $parentId = 0;
function initPropertyDes criptors() {
parent::initPro pertyDescriptor s();
$this->addFieldProp(' parentId', 'number', false, null, null, 1, '6,0');
$this->addDerivedProp ('parent', 'TreeItem', false);
$prop =& $this->addMultiValueP rop('children', 'TreeItem');
$prop->setTwinName('p arent');
$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 initPropertyDes criptors() 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 uiFieldProperti es 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.