Subversion Repositories Applications.gtt

Rev

Rev 94 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
94 jpm 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.11 2003/10/07 00:11:27 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.11 $
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
 
104
        if(is_dir($path) || !file_exists($path)) {
105
            PEAR::raiseError("The output driver '$driver' wasn't found", NESEO_DRIVER_NOT_FOUND, PEAR_ERROR_TRIGGER, E_USER_ERROR);
106
        }
107
 
108
        require_once($path);
109
        $driverClass = 'DB_NestedSet_'.$driver;
110
        return new $driverClass($params);
111
    }
112
 
113
    // }}}
114
    // {{{ setOptions()
115
 
116
    /**
117
    * Set's options for a specific output group (printTree, printListbox)
118
    * This enables you to set specific options for each output method
119
    *
120
    * @param string $group Output group ATM 'printTree' or 'printListbox'
121
    * @param array $options Hash with options
122
    *
123
    * @access public
124
    * @return bool
125
    */
126
    function setOptions($group, $options) {
127
        $this->options[$group] = $options;
128
        return true;
129
    }
130
 
131
    // }}}
132
    // {{{ _getOptions()
133
 
134
    /**
135
    * Get's all option for a specific output group (printTree, printListbox)
136
    *
137
    * @param string $group Output group ATM 'printTree' or 'printListbox'
138
    *
139
    * @access private
140
    * @return array Options
141
    */
142
    function _getOptions($group) {
143
 
144
        if (!isset($this->options[$group])) {
145
            return array();
146
        }
147
        return $this->options[$group];
148
    }
149
 
150
    // }}}
151
    // {{{ printTree()
152
 
153
    /**
154
    * Print's the current tree using the output driver
155
    * Overriden by the driver class
156
    *
157
    * @access public
158
    */
159
    function printTree() {
160
        PEAR::raiseError("Method not available for this driver", NESEO_ERROR_NO_METHOD, PEAR_ERROR_TRIGGER, E_USER_ERROR);
161
    }
162
 
163
    // }}}
164
    // {{{ printListbox()
165
 
166
    /**
167
    * Print's a listbox representing the current tree
168
    * Overriden by the driver class
169
    *
170
    * @access public
171
    */
172
    function printListbox() {
173
        PEAR::raiseError("Method not available for this driver", NESEO_ERROR_NO_METHOD, PEAR_ERROR_TRIGGER, E_USER_ERROR);
174
    }
175
 
176
    // }}}
177
 
178
    // {{{ toHTML()
179
 
180
    /**
181
     * Returns the HTML for the DHTML-menu. This method can be
182
     * used instead of printMenu() to use the menu system
183
     * with a template system.
184
     *
185
     * @access public
186
     * @return string The HTML for the menu
187
     * @author Emanuel Zueger
188
     */
189
    function tree_toHTML() {
190
        PEAR::raiseError("Method not available for this driver", NESEO_ERROR_NO_METHOD, PEAR_ERROR_TRIGGER, E_USER_ERROR);
191
    }
192
 
193
    // }}}
194
    // {{{ listbox_toHTML()
195
 
196
    /**
197
     * Returns the HTML for the listbox. This method can be
198
     * used instead of printListbox() to use the menu system
199
     * with a template system.
200
     *
201
     * @access public
202
     * @return string The HTML for the listbox
203
     * @author Emanuel Zueger
204
     */
205
    function listbox_toHTML() {
206
        PEAR::raiseError("Method not available for this driver", NESEO_ERROR_NO_METHOD, PEAR_ERROR_TRIGGER, E_USER_ERROR);
207
    }
208
 
209
    // }}}
210
}
211
?>