[ Index ] |
|
Code source de Horde 3.1.3 |
1 <?php 2 /** 3 * The Horde_Tree_select:: class extends the Horde_Tree class to provide 4 * <option> tag rendering. 5 * 6 * Copyright 2005-2006 Ben Chavet <ben@horde.org> 7 * 8 * See the enclosed file COPYING for license information (LGPL). If you did 9 * not receive this file, see http://www.fsf.org/copyleft/lgpl.html. 10 * 11 * $Horde: framework/Tree/Tree/select.php,v 1.2.2.7 2006/01/01 21:28:40 jan Exp $ 12 * 13 * @author Ben Chavet <ben@horde.org> 14 * @package Horde_Tree 15 * @since Horde 3.1 16 */ 17 class Horde_Tree_select extends Horde_Tree { 18 19 /** 20 * TODO 21 * 22 * @var array 23 */ 24 var $_nodes = array(); 25 26 /** 27 * Constructor. 28 */ 29 function Horde_Tree_select($tree_name, $params) 30 { 31 parent::Horde_Tree($tree_name, $params); 32 $this->_static = true; 33 } 34 35 /** 36 * Returns the tree. 37 * 38 * @return string The HTML code of the rendered tree. 39 */ 40 function getTree() 41 { 42 $this->_buildIndents($this->_root_nodes); 43 44 $tree = ''; 45 foreach ($this->_root_nodes as $node_id) { 46 $tree .= $this->_buildTree($node_id); 47 } 48 return $tree; 49 } 50 51 /** 52 * Checks the current environment to see if we can render the HTML tree. 53 * HTML is always renderable, at least until we add a php-gtk tree 54 * backend, in which case this implementation will actually need a body. 55 * 56 * @static 57 * 58 * @return boolean Whether or not this Tree:: backend will function. 59 */ 60 function isSupported() 61 { 62 return true; 63 } 64 65 /** 66 * Returns just the JS node definitions as a string. This is a no-op for 67 * the select renderer. 68 */ 69 function renderNodeDefinitions() 70 { 71 } 72 73 /** 74 * Adds additional parameters to a node. 75 * 76 * @param string $id The unique node id. 77 * @param array $params Any other parameters to set. 78 * <pre> 79 * selected -- Whether this node is selected 80 * </pre> 81 */ 82 function addNodeParams($id, $params = array()) 83 { 84 if (!is_array($params)) { 85 $params = array($params); 86 } 87 88 $allowed = array('selected'); 89 90 foreach ($params as $param_id => $param_val) { 91 /* Set only allowed and non-null params. */ 92 if (in_array($param_id, $allowed) && !is_null($param_val)) { 93 $this->_nodes[$id][$param_id] = $param_val; 94 } 95 } 96 } 97 98 /** 99 * Recursive function to walk through the tree array and build the output. 100 * 101 * @access private 102 * 103 * @param string $node_id The Node ID. 104 * 105 * @return string The tree rendering. 106 */ 107 function _buildTree($node_id) 108 { 109 $selected = $this->_nodes[$node_id]['selected'] ? ' selected="selected"' : ''; 110 111 $output = '<option value="' . htmlspecialchars($node_id) . '"' . $selected . '>' . 112 str_repeat(' ', (int)$this->_nodes[$node_id]['indent']) . htmlspecialchars($this->_nodes[$node_id]['label']) . 113 '</option>'; 114 115 if (isset($this->_nodes[$node_id]['children']) && 116 $this->_nodes[$node_id]['expanded']) { 117 $num_subnodes = count($this->_nodes[$node_id]['children']); 118 for ($c = 0; $c < $num_subnodes; $c++) { 119 $child_node_id = $this->_nodes[$node_id]['children'][$c]; 120 $output .= $this->_buildTree($child_node_id); 121 } 122 } 123 124 return $output; 125 } 126 127 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 18:01:28 2007 | par Balluche grâce à PHPXref 0.7 |