1 |
<? |
2 |
/* |
3 |
## ----------------------------------------------------------------------------- |
4 |
## $Id: AbstractExplorer.php,v 1.7 2003/03/29 07:49:55 joko Exp $ |
5 |
## ----------------------------------------------------------------------------- |
6 |
## $Log: AbstractExplorer.php,v $ |
7 |
## Revision 1.7 2003/03/29 07:49:55 joko |
8 |
## show boxes in DEBUG-mode only! |
9 |
## |
10 |
## Revision 1.6 2003/03/28 06:42:37 joko |
11 |
## fix: propagating rpc-debugging-options to constants here |
12 |
## |
13 |
## Revision 1.5 2003/03/27 01:24:29 jonen |
14 |
## + enabled navigation ecom (only list yet) |
15 |
## |
16 |
## Revision 1.4 2003/03/20 08:02:11 jonen |
17 |
## + purged code |
18 |
## |
19 |
## Revision 1.3 2003/03/20 07:54:52 jonen |
20 |
## + added docu |
21 |
## |
22 |
## Revision 1.2 2003/03/20 07:44:31 jonen |
23 |
## + removed dumper |
24 |
## |
25 |
## Revision 1.1 2003/03/20 03:48:46 jonen |
26 |
## + initial commit |
27 |
## |
28 |
## Revision 1.1 2003/03/08 02:36:17 cvsmax |
29 |
## + moved from *.inc |
30 |
## + mungled namespace with WebExplorer |
31 |
## |
32 |
## Revision 1.3 2003/03/03 22:25:21 joko |
33 |
## fixed minor typos |
34 |
## namespace mungling |
35 |
## |
36 |
## Revision 1.2 2003/03/02 00:48:49 cvsmax |
37 |
## + set up gui module registry |
38 |
## - purged old/sample code |
39 |
## |
40 |
## Revision 1.1 2003/03/01 22:57:32 cvsmax |
41 |
## + inital commit |
42 |
## |
43 |
## |
44 |
## ----------------------------------------------------------------------------- |
45 |
*/ |
46 |
|
47 |
/** |
48 |
* WebExplorer::AbstractExplorer - this can be simple compared to a container, |
49 |
* which modular GUI classes can be register, manipulated and rendered... |
50 |
* |
51 |
* @author Sebastian Utz <seut@tunemedia.de> |
52 |
* @package org.netfrag.app |
53 |
* @name WebExplorer::AbstractExplorer |
54 |
*/ |
55 |
|
56 |
|
57 |
class WebExplorer_AbstractExplorer { |
58 |
|
59 |
/** |
60 |
* container holds meta information of data locators |
61 |
*/ |
62 |
var $_data_locators = array(); |
63 |
|
64 |
/** |
65 |
* container for registered modules |
66 |
*/ |
67 |
var $_module = array(); |
68 |
|
69 |
/** |
70 |
* container holds references to each ecom |
71 |
*/ |
72 |
var $_ecom = array(); |
73 |
|
74 |
/** |
75 |
* holds the whole page state |
76 |
*/ |
77 |
var $_state = array(); |
78 |
|
79 |
/** |
80 |
* holds state variables only needed for explorer |
81 |
*/ |
82 |
var $_e_state = array(); |
83 |
|
84 |
|
85 |
function WebExplorer_AbstractExplorer($data_locators=array()) { |
86 |
$this->_data_locators = $data_locators; |
87 |
$this->init_default_gui_modules(); |
88 |
|
89 |
$this->set_e_state(); |
90 |
//print "State: " . Dumper($this->_state) ."<br>"; |
91 |
$div = html_div(); |
92 |
$div->add( html_b(get_class($this)), html_hr(), "Explorer_State: " . Dumper($this->_e_state)); |
93 |
$div->set_style('background: #adadad; border: 2px black groove; width:640px; padding:10px; margin:40px;'); |
94 |
if (constants::get('DEBUG')) { |
95 |
print $div->render(); |
96 |
} |
97 |
//$this->init_state(); |
98 |
} |
99 |
|
100 |
|
101 |
function add_data_locator($label, $args) { |
102 |
$this->_data_locators[$label] = $args; |
103 |
} |
104 |
|
105 |
function set_data_locator($label, $new_args=array() ) { |
106 |
global $app; |
107 |
//print Dumper($app) . "<br>"; |
108 |
if($label == "rpc") { |
109 |
$rpcinfo = $app->getConfig("rpcinfo"); |
110 |
define('RPC_HOSTNAME', $rpcinfo[Host]); |
111 |
define('RPC_PORT', $rpcinfo[Port]); |
112 |
define('RPC_DEBUG', $rpcinfo[DEBUG]); |
113 |
define('RPC_TRACE', $rpcinfo[TRACE]); |
114 |
define('RPC_DISCONNECT_ON_ERROR', $rpcinfo[DISCONNECT_ON_ERROR]); |
115 |
} else { |
116 |
user_error("AbstractExplorer::set_data_locator - data_locator_key label $label not found!"); |
117 |
} |
118 |
} |
119 |
|
120 |
function get_data_locator($label) { |
121 |
} |
122 |
|
123 |
function get_page_state() { |
124 |
$requestTracker = mkObject("Application::Request::Tracker"); |
125 |
$this->_state = $requestTracker->getPointer(); |
126 |
} |
127 |
|
128 |
function set_e_state() { |
129 |
$this->get_page_state(); |
130 |
$this->_e_state = $this->_state[options][options]; |
131 |
} |
132 |
|
133 |
|
134 |
function set_page_state() { |
135 |
user_error("AbstractExplorer::set_page_state - please implement me...."); |
136 |
} |
137 |
|
138 |
|
139 |
function init_default_gui_modules() { |
140 |
//$this->register_gui_module("n_tree", "nav", array( 'name' => "NavigationTree", 'type' => "tree") ); |
141 |
$this->register_gui_module("list", "nav", array( 'name' => "WebExplorer::Module::NavigationList", 'type' => "list") ); |
142 |
$this->register_gui_module("list", "data", array( 'name' => "WebExplorer::Module::DataList", 'type' => "list") ); |
143 |
$this->register_gui_module("item", "data", array( 'name' => "WebExplorer::Module::DataItem", 'type' => "item") ); |
144 |
} |
145 |
|
146 |
function register_source_module($label, $args) { |
147 |
$this->_module['source'][$label] = $args; |
148 |
} |
149 |
|
150 |
function register_gui_module($abstract_type, $ecom_type, $args) { |
151 |
$this->_module['gui'][$ecom_type][$abstract_type] = $args; |
152 |
} |
153 |
|
154 |
function &get_ecom($label) { |
155 |
//return "Hello World"; |
156 |
$this->_load_ecom($label); |
157 |
return $this->_ecom[$label]; |
158 |
} |
159 |
|
160 |
function _load_ecoms() { |
161 |
foreach($this->_e_state[ecoms] as $label => $val) { |
162 |
$this->_load_ecom($label); |
163 |
} |
164 |
} |
165 |
|
166 |
function _load_ecom($label) { |
167 |
$val = $this->_e_state['ecoms'][$label]; |
168 |
// find right gui module |
169 |
$com_type = $val['ecom_type']; |
170 |
$abstract_type = $val['ecom_abstract_type']; |
171 |
$gui_module = $this->_module['gui'][$com_type][$abstract_type]['name']; |
172 |
if(!$gui_module) { |
173 |
user_error("AbstractExplorer::_load_component - No GUI module found for abstract type $val[ecom_abstract_type] ecom type $val[ecom_type] !"); |
174 |
return; |
175 |
} |
176 |
// get arguments needed for gui module |
177 |
$args = $this->_prepare_component_args($label); |
178 |
//print Dumper($args); |
179 |
|
180 |
// get GUI module |
181 |
$ecom = php::mkComponent($gui_module, $args); |
182 |
//print Dumper($ecom); |
183 |
|
184 |
// get phphtmllib GUI object |
185 |
$gui_ecom = &$ecom->get(); |
186 |
|
187 |
// add hidden vars, needed for explorer control |
188 |
$hidden_items = $this->_get_hidden_items($label); |
189 |
if(is_array($hidden_items) ) { |
190 |
$ecom->add_hidden_items($hidden_items); |
191 |
//print "Hidden: " . Dumper($hidden_items); |
192 |
} |
193 |
|
194 |
$this->_ecom[$label] = &$gui_ecom; |
195 |
} |
196 |
|
197 |
function _get_hidden_items($label) { |
198 |
$ecom_state = $this->_e_state['ecoms'][$label]; |
199 |
if($ecom_state['ecom_type'] == "data") { |
200 |
if($ecom_state['ecom_abstract_type'] == "list") { |
201 |
$hidden_items = array( |
202 |
'ecl' => $label, |
203 |
'ecat' => "item", |
204 |
'ecmod' => "view", |
205 |
); |
206 |
} |
207 |
elseif($ecom_state['ecom_abstract_type'] == "item") { |
208 |
$hidden_items = array( |
209 |
'ecl' => $label, |
210 |
'ecat' => "item", |
211 |
'ecmod' => "view", |
212 |
); |
213 |
/* |
214 |
if($ecom_state['ecom_mode'] == "view") { |
215 |
$hidden_items['ecmod'] = "edit"; |
216 |
} |
217 |
elseif($ecom_state['ecom_mode'] == "edit") { |
218 |
$hidden_items['ecmod'] = "edit"; |
219 |
} |
220 |
*/ |
221 |
} |
222 |
$hidden_items['ap'] = "explorer"; |
223 |
} |
224 |
return $hidden_items; |
225 |
} |
226 |
|
227 |
function _prepare_component_args($label) { |
228 |
$val = $this->_e_state['ecoms'][$label]; |
229 |
$this->set_data_locator($val['ecom_data_locator_key']); |
230 |
// switch component type |
231 |
if($val['ecom_type'] == "data") { |
232 |
// switch abstract type |
233 |
if($val['ecom_abstract_type'] == "list") { |
234 |
if($val['ecom_data_locator_key'] == "rpc") { |
235 |
//$data_locator_meta = array( datasource => 'rpc', metatype => 'data', vartype => 'objects', classname => $val['ecom_data_ident']); |
236 |
$data_locator_meta = array( datasource => 'rpc', metatype => 'data', abstract_type => 'list', classname => $val['ecom_data_ident']); |
237 |
} else { |
238 |
user_error("AbstractExplorer::_prepare_component_args - Cannot build query for data_locator_key $val[ecom_data_locator_key] !"); |
239 |
} |
240 |
$args = array( |
241 |
'caption' => "Liste", |
242 |
'orderby' => "Guid", |
243 |
'options' => array( |
244 |
'data_locator_meta' => $data_locator_meta, |
245 |
'decode' => 1, |
246 |
'decode_args' => array( |
247 |
'seperator' => "_", |
248 |
'form' => 1, |
249 |
), |
250 |
), |
251 |
); |
252 |
// switch abstract type |
253 |
} elseif ($val['ecom_abstract_type'] == "item") { |
254 |
if($val['ecom_data_locator_key'] == "rpc") { |
255 |
//$data_locator_meta = array( datasource => 'rpc', metatype => 'data', vartype => 'objects', classname => $val['ecom_data_ident']); |
256 |
$data_locator_meta = array( datasource => 'rpc', metatype => 'data', abstract_type => 'item', ident => $val['ecom_data_ident'], classname => $val['ecom_data_meta']); |
257 |
} else { |
258 |
user_error("AbstractExplorer::_prepare_component_args - Cannot build query for data_locator_key $val[ecom_data_locator_key] !"); |
259 |
} |
260 |
if(!$val['ecom_mode']) { $val['ecom_mode'] = "view"; } |
261 |
print "Mode: $val[ecom_mode]<br>"; |
262 |
$args = array( |
263 |
'caption' => "Item", |
264 |
'mode' => $val['ecom_mode'], |
265 |
'options' => array( |
266 |
'data_locator_meta' => $data_locator_meta, |
267 |
'decode' => 1, |
268 |
'decode_args' => array( |
269 |
'seperator' => "_", |
270 |
), |
271 |
), |
272 |
); |
273 |
if($val['ecom_mode'] == "edit") { $args['adapter'] = 'FormProcessor'; } |
274 |
} |
275 |
// switch component type |
276 |
} elseif ($val['ecom_type'] == "nav") { |
277 |
// switch abstract type |
278 |
if($val['ecom_abstract_type'] == "list") { |
279 |
if($val['ecom_data_locator_key'] == "rpc") { |
280 |
$data_locator_meta = array( datasource => 'rpc', metatype => 'schema' ); |
281 |
} else { |
282 |
user_error("AbstractExplorer::_prepare_component_args - Cannot build query for data_locator_key $val[ecom_data_locator_key] !"); |
283 |
} |
284 |
$args = array( |
285 |
'caption' => "Objekt Typen", |
286 |
'options' => array( |
287 |
'data_locator_meta' => $data_locator_meta, |
288 |
), |
289 |
); |
290 |
} elseif ($val['ecom_abstract_type'] == "tree") { |
291 |
$args = array(); |
292 |
} |
293 |
} |
294 |
return $args; |
295 |
} |
296 |
|
297 |
function get_msg($label) { |
298 |
if($label == "welcome") { |
299 |
$msg = "Welcome to the Explorer."; |
300 |
} |
301 |
return $msg; |
302 |
} |
303 |
|
304 |
function render() { |
305 |
user_error("AbstractExplorer::render - please implement me...."); |
306 |
} |
307 |
|
308 |
} |
309 |
|
310 |
|
311 |
?> |