[ Index ] |
|
Code source de SPIP Agora 1.4 |
1 <?php 2 // 3 // +----------------------------------------------------------------------+ 4 // | PEAR :: DB_NestedSet_Output | 5 // +----------------------------------------------------------------------+ 6 // | Copyright (c) 1997-2003 The PHP Group | 7 // +----------------------------------------------------------------------+ 8 // | This source file is subject to version 2.0 of the PHP license, | 9 // | that is bundled with this package in the file LICENSE, and is | 10 // | available at through the world-wide-web at | 11 // | http://www.php.net/license/2_02.txt. | 12 // | If you did not receive a copy of the PHP license and are unable to | 13 // | obtain it through the world-wide-web, please send a note to | 14 // | license@php.net so we can mail you a copy immediately. | 15 // +----------------------------------------------------------------------+ 16 // | Authors: Daniel Khan <dk@webcluster.at> | 17 // | Jason Rust <jason@rustyparts.com> | 18 // +----------------------------------------------------------------------+ 19 // $Id: Output.php,v 1.14 2004/07/25 11:55:22 datenpunk Exp $ 20 // 21 22 require_once 'PEAR.php'; 23 24 // {{{ constants 25 26 define('NESEO_ERROR_NO_METHOD', 'E1000'); 27 define('NESEO_DRIVER_NOT_FOUND', 'E1100'); 28 define('NESEO_ERROR_NO_OPTIONS', 'E2100'); 29 30 // }}} 31 // {{{ DB_NestedSet_Output:: class 32 33 /** 34 * DB_NestedSet_Output is a unified API for other output drivers 35 * Status is beta 36 * 37 * At the moment PEAR::HTML_TreeMenu written by Jason Rust is supported 38 * A driver for treemenu.org will follow soon. 39 * 40 * Usage example: 41 * 42 * require_once('DB_NestedSet/NestedSet/Output.php'); 43 * $icon = 'folder.gif'; 44 * $expandedIcon = 'folder-expanded.gif'; 45 * // get data (important to fetch it as an array, using the true flag) 46 * $data = $NeSe->getAllNodes(true); 47 * // change the events for one of the elements 48 * $data[35]['events'] = array('onexpand' => 'alert("we expanded!");'); 49 * // add links to each item 50 * foreach ($data as $a_data) { 51 * $a_data['link'] = 'http://foo.com/foo.php?' . $a_data['id']; 52 * } 53 * $params = array( 54 * 'structure' => $data, 55 * 'options' => array( 56 * 'icon' => $icon, 57 * 'expandedIcon' => $expandedIcon, 58 * ), 59 * 'textField' => 'name', 60 * 'linkField' => 'link', 61 * ); 62 * $menu =& DB_NestedSet_Output::factory('TreeMenu', $params); 63 * $menu->printListbox(); 64 * 65 * @author Daniel Khan <dk@webcluster.at> 66 * @package DB_NestedSet 67 * @version $Revision: 1.14 $ 68 * @access public 69 * 70 */ 71 72 // }}} 73 class DB_NestedSet_Output { 74 // {{{ properties 75 76 /** 77 * @var object The tree menu structure 78 * @access private 79 */ 80 var $_structTreeMenu = false; 81 82 /** 83 * @var array Array of options to be passed to the ouput methods 84 * @access public 85 */ 86 var $options = array(); 87 88 // }}} 89 // {{{ factory() 90 91 /** 92 * Returns a output driver object 93 * 94 * @param array $params A DB_NestedSet nodeset 95 * @param string $driver (optional) The driver, such as TreeMenu (default) 96 * 97 * @access public 98 * @return object The DB_NestedSet_Ouput object 99 */ 100 function &factory ($params, $driver = 'TreeMenu') { 101 102 $path = dirname(__FILE__).'/'.$driver.'.php'; 103 if(is_dir($path) || !file_exists($path)) { 104 PEAR::raiseError("The output driver '$driver' wasn't found", NESEO_DRIVER_NOT_FOUND, PEAR_ERROR_TRIGGER, E_USER_ERROR); 105 } 106 107 require_once($path); 108 $driverClass = 'DB_NestedSet_'.$driver; 109 return new $driverClass($params); 110 } 111 112 // }}} 113 // {{{ setOptions() 114 115 /** 116 * Set's options for a specific output group (printTree, printListbox) 117 * This enables you to set specific options for each output method 118 * 119 * @param string $group Output group ATM 'printTree' or 'printListbox' 120 * @param array $options Hash with options 121 * 122 * @access public 123 * @return bool 124 */ 125 function setOptions($group, $options) { 126 $this->options[$group] = $options; 127 return true; 128 } 129 130 // }}} 131 // {{{ _getOptions() 132 133 /** 134 * Get's all option for a specific output group (printTree, printListbox) 135 * 136 * @param string $group Output group ATM 'printTree' or 'printListbox' 137 * 138 * @access private 139 * @return array Options 140 */ 141 function _getOptions($group) { 142 143 if (!isset($this->options[$group])) { 144 return array(); 145 } 146 return $this->options[$group]; 147 } 148 149 // }}} 150 // {{{ printTree() 151 152 /** 153 * Print's the current tree using the output driver 154 * Overriden by the driver class 155 * 156 * @access public 157 */ 158 function printTree() { 159 PEAR::raiseError("Method not available for this driver", NESEO_ERROR_NO_METHOD, PEAR_ERROR_TRIGGER, E_USER_ERROR); 160 } 161 162 // }}} 163 // {{{ printListbox() 164 165 /** 166 * Print's a listbox representing the current tree 167 * Overriden by the driver class 168 * 169 * @access public 170 */ 171 function printListbox() { 172 PEAR::raiseError("Method not available for this driver", NESEO_ERROR_NO_METHOD, PEAR_ERROR_TRIGGER, E_USER_ERROR); 173 } 174 175 // }}} 176 177 // {{{ toHTML() 178 179 /** 180 * Returns the HTML for the DHTML-menu. This method can be 181 * used instead of printMenu() to use the menu system 182 * with a template system. 183 * 184 * @access public 185 * @return string The HTML for the menu 186 * @author Emanuel Zueger 187 */ 188 function tree_toHTML() { 189 PEAR::raiseError("Method not available for this driver", NESEO_ERROR_NO_METHOD, PEAR_ERROR_TRIGGER, E_USER_ERROR); 190 } 191 192 // }}} 193 // {{{ listbox_toHTML() 194 195 /** 196 * Returns the HTML for the listbox. This method can be 197 * used instead of printListbox() to use the menu system 198 * with a template system. 199 * 200 * @access public 201 * @return string The HTML for the listbox 202 * @author Emanuel Zueger 203 */ 204 function listbox_toHTML() { 205 PEAR::raiseError("Method not available for this driver", NESEO_ERROR_NO_METHOD, PEAR_ERROR_TRIGGER, E_USER_ERROR); 206 } 207 // }}} 208 // {{{ getStructure() 209 210 /** 211 * 212 * @access public 213 * @return mixed 214 */ 215 function returnStructure() { 216 PEAR::raiseError("Method not available for this driver", NESEO_ERROR_NO_METHOD, PEAR_ERROR_TRIGGER, E_USER_ERROR); 217 } 218 // }}} 219 } 220 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 14:40:03 2007 | par Balluche grâce à PHPXref 0.7 |