cvs: pear /DB_NestedSet/NestedSet TreeMenu.php /DB_NestedSet/docs TreeMenu_example.php

From: Date: Tue, 30 Dec 2003 17:07:37 +0000
Subject: cvs: pear /DB_NestedSet/NestedSet TreeMenu.php /DB_NestedSet/docs TreeMenu_example.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-15229@lists.php.net to get a copy of this message
jrust Tue Dec 30 12:07:37 2003 EDT Modified files: /pear/DB_NestedSet/NestedSet TreeMenu.php /pear/DB_NestedSet/docs TreeMenu_example.php Log: * Updated example for TreeMenu to show how to add an icon to the node. * Cleaned up code and docs for TreeMenu renderer Index: pear/DB_NestedSet/NestedSet/TreeMenu.php diff -u pear/DB_NestedSet/NestedSet/TreeMenu.php:1.13 pear/DB_NestedSet/NestedSet/TreeMenu.php:1.14 --- pear/DB_NestedSet/NestedSet/TreeMenu.php:1.13 Mon Oct 6 20:11:27 2003 +++ pear/DB_NestedSet/NestedSet/TreeMenu.php Tue Dec 30 12:07:36 2003 @@ -16,7 +16,7 @@ // | Authors: Jason Rust <jrust@rustyparts.com> | // +----------------------------------------------------------------------+ // -// $Id: TreeMenu.php,v 1.13 2003/10/07 00:11:27 datenpunk Exp $ +// $Id: TreeMenu.php,v 1.14 2003/12/30 17:07:36 jrust Exp $ // require_once 'HTML/TreeMenu.php'; @@ -30,7 +30,7 @@ * @see docs/TreeMenu_example.php * @author Jason Rust <jrust@rustyparts.com> * @package DB_NestedSet -* @version $Revision: 1.13 $ +* @version $Revision: 1.14 $ * @access public */ // }}} @@ -46,7 +46,18 @@ // }}} // {{{ DB_NestedSet_TreeMenu - function &DB_NestedSet_TreeMenu($params) { + /** + * The constructor + * + * @param array $params The config parameters used for building the + * tree. + * + * @see _createFromStructure() + * @access public + * @return void + */ + function &DB_NestedSet_TreeMenu($params) + { $this->_structTreeMenu =& $this->_createFromStructure($params); } @@ -54,19 +65,27 @@ // {{{ _createFromStructure() /** - * <pre>Creates a HTML_TreeMenu structure based off of the results from getAllNodes() method - * of the DB_NestedSet class. The needed parameters are: - * o 'structure' => the result from $nestedSet->getAllNodes(true) - * o 'textField' => the field in the table that has the text for node - * o 'linkField' => the field in the table that has the link for the node - * o 'options' => (optional) an array of any additional options to pass to the node when - * Additionally these parameters may be added to the individual nodes to control their - * behavior: - * o 'ensureVisible' => (optional) whether or not the field should be forced as visible - * creating it such as 'icon' or 'expandedIcon' - * o 'events' => (optional) an array of any events to pass to the node when creating it - * such as 'onclick' or 'onexpand'</pre> + * <pre>Creates a HTML_TreeMenu structure based off of the results + * from getAllNodes() method of the DB_NestedSet class. + * Note that these parameters may be added to the individual nodes + * to control their behavior: + * o 'ensureVisible' => (optional) Whether or not the field should be + * forced as visible creating it such as 'icon' + * or 'expandedIcon' + * o 'events' => (optional) An array of any events to pass to the + * node when creating it such as 'onclick' or + * 'onexpand' + * + * @param array $params The configuration parameters. Available + * params are: + * o 'structure' => The result from $nestedSet->getAllNodes(true) + * o 'textField' => The field in the table that has the text for node + * o 'linkField' => The field in the table that has the link for the node + * o 'options' => (optional) An array of any additional options to + * pass to the node when it is created (i.e. icon, + * class). See HTML_TreeNode for the options) * </pre> + * * @access public * @return object A HTML_TreeMenu object */ @@ -100,11 +119,9 @@ // mark that we've hit this node $params['structure'][$key]['hit'] = $node['hit'] = true; - $tag = array( - 'text' => $node[$params['textField']], - 'link' => $node[$params['linkField']], - 'ensureVisible' => isset($node['ensureVisible']) ? $node['ensureVisible'] : false, - ); + $tag = array('text' => $node[$params['textField']], + 'link' => $node[$params['linkField']], + 'ensureVisible' => isset($node['ensureVisible']) ? $node['ensureVisible'] : false); $options = isset($params['options']) ? array_merge($params['options'], $tag) : $tag; $events = isset($node['events']) ? $node['events'] : array(); $parentNode =& $treeMenu->addItem(new HTML_TreeNode($options, $events)); @@ -143,7 +160,8 @@ * * @access public */ - function printTree() { + function printTree() + { $options = $this->_getOptions('printTree'); $tree =& new HTML_TreeMenu_DHTML($this->_structTreeMenu, $options); $tree->printMenu(); @@ -157,12 +175,12 @@ * * @access public */ - function printListbox() { + function printListbox() + { $options = $this->_getOptions('printListbox'); $listBox =& new HTML_TreeMenu_Listbox($this->_structTreeMenu, $options); $listBox->printMenu(); } - // }}} // }}} // {{{ tree_toHTML() @@ -176,7 +194,8 @@ * @return string The HTML for the menu * @Author Emanuel Zueger */ - function tree_toHTML() { + function tree_toHTML() + { $options = $this->_getOptions('toHTML'); $tree =& new HTML_TreeMenu_DHTML($this->_structTreeMenu, $options); return $tree->toHTML(); @@ -194,7 +213,8 @@ * @return string The HTML for the listbox * @author Emanuel Zueger */ - function listbox_toHTML() { + function listbox_toHTML() + { $options = $this->_getOptions('toHTML'); $listBox =& new HTML_TreeMenu_Listbox($this->_structTreeMenu, $options); return $listBox->toHTML(); Index: pear/DB_NestedSet/docs/TreeMenu_example.php diff -u pear/DB_NestedSet/docs/TreeMenu_example.php:1.4 pear/DB_NestedSet/docs/TreeMenu_example.php:1.5 --- pear/DB_NestedSet/docs/TreeMenu_example.php:1.4 Fri Jul 18 14:52:10 2003 +++ pear/DB_NestedSet/docs/TreeMenu_example.php Tue Dec 30 12:07:37 2003 @@ -1,4 +1,4 @@ -<?php /** $Id: TreeMenu_example.php,v 1.4 2003/07/18 18:52:10 jrust Exp $ */ ?> +<?php /** $Id: TreeMenu_example.php,v 1.5 2003/12/30 17:07:37 jrust Exp $ */ ?> <html> <title>DB_NestedSet using TreeMenu Output class</title> <body> @@ -67,7 +67,7 @@ require_once('DB/NestedSet.php'); require_once('DB/NestedSet/Output.php'); -$dsn = 'mysql://user:pass@localhost/test'; +$dsn = 'mysql://root:3ugr4ts@localhost/test'; $params = array( 'id' => 'id', 'parent_id' => 'rootid', @@ -104,6 +104,7 @@ 'structure' => $data, 'textField' => 'name', 'linkField' => 'link', + 'options' => array('icon' => 'folder.gif', 'expandedIcon' => 'folder-expanded.gif'), ); $output =& DB_NestedSet_Output::factory($params, 'TreeMenu');

« previous php.pear.cvs (#15229) next »