Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.4.1

Bug #6390 options not used
Submitted: 2006-01-02 12:00 UTC
From: bate Assigned: bate
Status: Closed Package: DB_NestedSet
PHP Version: 5.0.5 OS: FreeBSD
Roadmaps: (Not assigned)    
Subscription  


 [2006-01-02 12:00 UTC] bate
Description: ------------ The example in TreeMenu doesnt work. Options are not used. The provided diff patches this problem. Index: TreeMenu.php =================================================================== RCS file: /repository/pear/DB_NestedSet/NestedSet/TreeMenu.php,v retrieving revision 1.19 diff -u -p -d -r1.19 TreeMenu.php --- TreeMenu.php 2 Apr 2004 00:15:06 -0000 1.19 +++ TreeMenu.php 2 Jan 2006 11:54:12 -0000 @@ -152,6 +152,13 @@ class DB_NestedSet_TreeMenu extends DB_N 'ensureVisible' => isset($node[$params['ensureVisibleField']]) ? $node[$params['ensureVisibleField']] : false); $options = isset($params['options']) ? array_merge($params['options'], $tag) : $tag; + + foreach ($params['options'] as $key => $value) { + if ($options[$key] === false) { + $options[$key] = $value; + } + } + $events = isset($node['events']) ? $node['events'] : array(); $parentNode = & $treeMenu->addItem(new HTML_TreeNode($options, $events)); // see if it has children Test script: --------------- DB_NestedSet using TreeMenu Output class
DB_NestedSet using the TreeMenu Output class
<div> <?php require_once('HTML/Menu.php'); require_once('DB/NestedSet.php'); require_once('DB/NestedSet/Output.php'); $dsn = 'mysql://root:3ugr4ts@localhost/test'; $params = array( 'id' => 'id', 'root_id' => 'rootid', 'left_id' => 'l', 'right_id' => 'r', 'order_num' => 'norder', 'level' => 'level', 'name' => 'name', ); $nestedSet =& DB_NestedSet::factory('DB', $dsn, $params); // we want the nodes to be displayed ordered by name, so we add the secondarySort attribute $nestedSet->setAttr(array( 'node_table' => 'ns_tree', 'lock_table' => 'ns_locks', 'secondarySort' => 'name', ) ); $data = $nestedSet->getAllNodes(true); foreach ($data as $id => $node) { $data[$id]['link'] = '?id=' . $node['id']; $data[$id]['events'] = array( 'onexpand' => 'alert("we expanded!");', 'onclick' => 'alert("we clicked!");', ); } $params = array( 'structure' => $data, 'textField' => 'name', 'linkField' => 'link', 'ensureVisible' => true, 'options' => array( 'icon' => 'folder.gif', 'expandedIcon' => 'folder-expanded.gif' ), ); $output =& DB_NestedSet_Output::factory($params, 'TreeMenu'); echo '<script src="admin/TreeMenu.js" language="JavaScript" type="text/javascript"></script>'; $output->setOptions('printTree', array('images' => 'http://php/sandbox_mk/cdmm_catalog/admin/images/tree/')); $output->printTree(); ?> </body> </html> Expected result: ---------------- Tree with expanded folder images. This works not because its doesnt checks the globals params for options settings. This works just if you the the icon and icon-expanded array elements for every node. The provided patch apply node options and just if a node entry is false (=== false) it applies the global option value. Its possible to set (string)'false' for some nodes to hide the image.

Comments

 [2006-01-06 15:00 UTC] bate
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.