Writing a Category Hierarchy where to research?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Troy Lynch

    Writing a Category Hierarchy where to research?

    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
  • Henk Verhoeven

    #2
    Re: Writing a Category Hierarchy where to research?

    Troy Lynch wrote:[color=blue]
    > 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[/color]

    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:



    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.

    Comment

    • Henk Verhoeven

      #3
      Re: Writing a Category Hierarchy where to research?

      Troy Lynch wrote:[color=blue]
      > 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[/color]

      I just added a simple graphical representation, see


      its code:

      printBranches( getRoots() );

      function printBranches(& $treeItems, $depth=0)
      {
      while (list($key) = each($treeItems ) ) {
      for ($i=0; $i<$depth; $i++)
      print "&nbsp;&nbsp;&n bsp;";
      $item =& $treeItems[$key];
      ?><A HREF='index.php ?pntType=TreeIt em&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.

      Comment

      Working...