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