1 |
<?php |
2 |
|
3 |
/** |
4 |
* $Id: MVC.php,v 1.17 2003/06/25 23:45:05 joko Exp $ |
5 |
* |
6 |
* $Log: MVC.php,v $ |
7 |
* Revision 1.17 2003/06/25 23:45:05 joko |
8 |
* trying to switch from "ap" completely to "t" |
9 |
* |
10 |
* Revision 1.16 2003/05/13 14:53:56 joko |
11 |
* reset mvc-params "filter" and "meta" in tree mode!? |
12 |
* |
13 |
* Revision 1.15 2003/05/10 18:19:55 jonen |
14 |
* + added stuff relating to 'create/add new' links/buttons |
15 |
* |
16 |
* Revision 1.14 2003/04/19 16:20:47 jonen |
17 |
* + added handle of ecom 'UMnav' according to page 'Benutzverwaltung' |
18 |
* |
19 |
* Revision 1.13 2003/04/18 15:30:24 joko |
20 |
* NEW: parameter 'ecom_data_filter' - used for 'items' |
21 |
* (introduced to filter xml-payload at backend side via xpath queries) |
22 |
* documented global state parameters |
23 |
* some comments |
24 |
* |
25 |
* Revision 1.12 2003/04/18 13:40:54 jonen |
26 |
* + added 'topic' to requested vars which will currently be merged with the 'ap' var |
27 |
* |
28 |
* Revision 1.11 2003/04/11 00:51:10 joko |
29 |
* minor update: just testing stuff... |
30 |
* |
31 |
* Revision 1.10 2003/04/10 06:03:26 joko |
32 |
* ++ renamed keys: 'ecom_data_form_edit', 'ecom_data_form_cancel' through 'ecom_data_action_edit', 'ecom_data_action_cancel' |
33 |
* + new key: 'ecom_data_action_delete' |
34 |
* + Action.Delete: not really, since it's inside component in fact (self-contained ecom) |
35 |
* |
36 |
* Revision 1.9 2003/04/09 00:05:50 jonen |
37 |
* added request values and functions needed for extended form handling |
38 |
* |
39 |
* Revision 1.8 2003/04/08 17:53:08 joko |
40 |
* NEW: Module 'RemoteAction' in 'phase_startup' |
41 |
* |
42 |
* Revision 1.7 2003/04/07 22:32:27 jonen |
43 |
* + minor changes related to new ecom 'chooser' |
44 |
* |
45 |
* Revision 1.6 2003/04/06 01:32:57 jonen |
46 |
* + minor changes |
47 |
* |
48 |
* Revision 1.5 2003/04/05 21:18:29 joko |
49 |
* added Chooser and associated 'ecds'-parameter |
50 |
* new rule (at bottom) to dispatch datasource-keys to each ecom-component |
51 |
* |
52 |
* Revision 1.4 2003/04/04 23:59:19 jonen |
53 |
* + minor changes according to data form submits |
54 |
* |
55 |
* Revision 1.3 2003/04/04 01:28:13 jonen |
56 |
* + added function to purge unwanted merged vars |
57 |
* + handle form submit's now |
58 |
* |
59 |
* Revision 1.2 2003/03/20 07:54:52 jonen |
60 |
* + added docu |
61 |
* |
62 |
* Revision 1.1 2003/03/20 03:48:47 jonen |
63 |
* + initial commit |
64 |
* |
65 |
* Revision 1.2 2003/03/18 00:00:20 cvsmax |
66 |
* + added thoughts and models for preparing control data to Explorer |
67 |
* |
68 |
* Revision 1.1 2003/03/08 02:36:39 cvsmax |
69 |
* + moved from *.inc |
70 |
* + mungled namespace with WebExplorer |
71 |
* |
72 |
* Revision 1.1 2003/03/03 22:26:16 joko |
73 |
* + initial commit, inherits from WebMVC |
74 |
* |
75 |
* Revision 1.1 2003/03/02 00:49:36 joko |
76 |
* + initial commit |
77 |
* |
78 |
* |
79 |
*/ |
80 |
|
81 |
/** |
82 |
* WebExplorer::MVC - this the MVC used by the WebExplorer. |
83 |
* Its derived from the 'Site::WebAppMVC' module. |
84 |
* |
85 |
* @author Sebastian Utz <seut@tunemedia.de> |
86 |
* @package org.netfrag.app |
87 |
* @name WebExplorer::MVC |
88 |
*/ |
89 |
|
90 |
loadModule('Site::WebAppMVC'); |
91 |
|
92 |
class WebExplorer_MVC extends Site_WebAppMVC { |
93 |
|
94 |
//var $_backend = null; |
95 |
var $_raw = array(); |
96 |
var $_registry = array(); |
97 |
|
98 |
function WebExplorer_MVC(&$args) { |
99 |
|
100 |
parent::constructor(); |
101 |
|
102 |
// new!!! a registry for Views!!! |
103 |
//$regdb = $this->getStaticRegistryDatabase(); |
104 |
//$this->_registry = mkObject('Application::ComponentRegistry', &$regdb, 'REGDB_PAYLOAD'); |
105 |
|
106 |
// new!!! storing the raw request here |
107 |
$this->_raw[request] = &$args[request]; |
108 |
|
109 |
// new!!! user_setup, phpHtmlLib-style... |
110 |
$this->user_setup(); |
111 |
|
112 |
} |
113 |
|
114 |
// setup MVC (model-view-controller) metadata information |
115 |
function user_setup() { |
116 |
|
117 |
$this->add_model( array( |
118 |
//args => array( 'classname', 'guid', 'action', 'data_locator_key', 'block' ), |
119 |
request_args => array( |
120 |
// ApplicationTopic |
121 |
'topic', |
122 |
// ApplicationPage |
123 |
'ap', |
124 |
// important/required parameters for valid ecom-components |
125 |
'ecom_label', 'ecom_type', 'ecom_abstract_type', 'ecom_mode', |
126 |
// parameters about data identifiers, locations, sources and associated meta-information |
127 |
'ecom_data_locator_key', |
128 |
'ecom_data_ident', |
129 |
'ecom_data_meta', 'ecom_data_meta_x', |
130 |
'ecom_data_action_edit', 'ecom_data_action_cancel', 'ecom_data_action_delete', 'ecom_data_action_create', |
131 |
'ecom_data_form_checkbox', 'ecom_data_form_action', |
132 |
'ecom_data_source_key', |
133 |
'ecom_data_filter', |
134 |
), |
135 |
request_arg => array( |
136 |
|
137 |
// a key identifying the current topic |
138 |
'topic' => array( query_arg => 't' ), |
139 |
|
140 |
// a key identifying the current page |
141 |
'ap' => array( query_arg => 'ap' ), |
142 |
|
143 |
// ecom, ecom, ecom |
144 |
|
145 |
// component specific arguments (important for the main dispatcher, etc.) |
146 |
// a label identifying a component |
147 |
'ecom_label' => array( query_arg => 'ecl' ), |
148 |
// data or schema |
149 |
'ecom_type' => array( query_arg => 'ect' ), |
150 |
// item, list or tree |
151 |
'ecom_abstract_type' => array( query_arg => 'ecat' ), |
152 |
|
153 |
|
154 |
// data, data, data |
155 |
|
156 |
// e.g. view, edit |
157 |
'ecom_mode' => array( query_arg => 'ecmod' ), |
158 |
// This should be renamed to 'ecom_data_transport_key'. |
159 |
'ecom_data_locator_key' => array( query_arg => 'ecdlk' ), |
160 |
|
161 |
// This should be enough to identify data Xyz. |
162 |
// e.g. an OID, a GUID, a filename or similar stuff |
163 |
'ecom_data_ident' => array( query_arg => 'ecdid' ), |
164 |
// e.g. a classname or a filename |
165 |
'ecom_data_meta' => array( query_arg => 'ecdm' ), |
166 |
// extended meta, e.g. 2nd parent identifier |
167 |
'ecom_data_meta_x' => array( query_arg => 'ecdmx' ), |
168 |
// filter the data: e.g. |
169 |
// - an xpath-query (xpq), |
170 |
// - an abstract/custom filter string or |
171 |
// - a parent node identifier (maybe revamp as 'ecdpnid')? |
172 |
'ecom_data_filter' => array( query_arg => 'ecdf' ), |
173 |
|
174 |
// Some actions ... |
175 |
// ... required for data items. |
176 |
'ecom_data_action_edit' => array( query_arg => 'ecdfe' ), |
177 |
'ecom_data_action_cancel' => array( query_arg => 'ecdfc' ), |
178 |
'ecom_data_action_delete' => array( query_arg => 'ecdfd' ), |
179 |
'ecom_data_action_create' => array( query_arg => 'ecdfcr' ), |
180 |
// ... required for data lists. |
181 |
'ecom_data_form_action' => array( query_arg => 'ecdfa' ), |
182 |
'ecom_data_form_checkbox' => array( query_arg => 'checkbox' ), |
183 |
|
184 |
// Special argument (should become a non-data-action). |
185 |
// Triggers 'selectSource' at backend api (remote api) which causes a database handle switch. |
186 |
'ecom_data_source_key' => array( query_arg => 'ecds' ), |
187 |
|
188 |
), |
189 |
|
190 |
/* |
191 |
// block model (what is used for each block) |
192 |
// is this deprecated??? |
193 |
block => array( |
194 |
'ident' => array( query_arg => 'ident' ), |
195 |
'meta' => array( query_arg => 'meta' ), |
196 |
'action' => array( query_arg => 'action'), |
197 |
'data_locator_key' => array( query_arg => 'dlk' ), |
198 |
'gui_module' => array( query_arg => 'gm' ), |
199 |
'abstract_type' => array( query_arg => 'at' ), |
200 |
), |
201 |
*/ |
202 |
|
203 |
)); |
204 |
|
205 |
|
206 |
// TODO: activate MVC-Views!!! |
207 |
// - Here: Picture a ecom-component as a MVC-View. |
208 |
// - Assign a GUID to each ecom-component! |
209 |
// - Build WebExplorer-Introspection-Module to show stuff like this... (->WebExplorer::Designer) |
210 |
|
211 |
|
212 |
//$this->setup_views( &$this->_registry ); |
213 |
|
214 |
// associate behaviour with "View"-components |
215 |
// identify component by: module name or component identifier (COID) |
216 |
// 'name' is looked up in that to get metadata information about the comp. |
217 |
// component: for 'component = 1', a component registry is required!!! |
218 |
// name: registry-lookup: by-name |
219 |
// COID: registry-lookup: by-COID |
220 |
// caption: caption of area or title of page |
221 |
$this->add_view( array( |
222 |
component => 1, |
223 |
name => 'NavigationList', |
224 |
// COID => '123', |
225 |
caption => "Explorer - NavigationList", |
226 |
)); |
227 |
$this->add_view( array( |
228 |
component => 1, |
229 |
name => 'ExplorerDataList', |
230 |
// COID => '123', |
231 |
caption => "Explorer - ExplorerDataList", |
232 |
)); |
233 |
$this->add_view( array( |
234 |
component => 1, |
235 |
name => 'ExplorerDataItem', |
236 |
// COID => '123', |
237 |
caption => "Explorer - ExplorerDataItem", |
238 |
)); |
239 |
|
240 |
// FIXME!!! enhance!?!? |
241 |
// AIM: "dispatch a Request to a View by using rules..." |
242 |
// Todo: |
243 |
// 'HttpController' is *very* dumb by now, it just iterates |
244 |
// this flat list below triggering the lambdas with their arguments. |
245 |
// Enhance this backend and introduce a mechanism to trigger |
246 |
// a true callback to process a rule (or: "as a rule") on top of that. |
247 |
$this->add_controller( array( |
248 |
|
249 |
// for "module", no component registry is required, just does 'mkObject' under the hood |
250 |
module => 'Application::Request::HttpController', |
251 |
//module_options => blah |
252 |
|
253 |
rules => array( |
254 |
|
255 |
// get last page state |
256 |
create_function('&$_in, &$_out', ' |
257 |
$requestTracker = mkObject("Application::Request::Tracker"); |
258 |
$page_state = $requestTracker->getPointer(); |
259 |
$pre_out = $page_state[options]; |
260 |
//print "pre_out: " . Dumper($pre_out); |
261 |
|
262 |
// clean-up unwanted variables |
263 |
$label = $_in[ecom_label]; |
264 |
switch ($_in[ecom_abstract_type]) { |
265 |
case "list": |
266 |
if ($pre_out[options][ecoms][$label][ecom_data_meta]) { unset($pre_out[options][ecoms][$label][ecom_data_meta]); } |
267 |
if ($pre_out[options][ecoms][$label][ecom_data_meta_x]) { unset($pre_out[options][ecoms][$label][ecom_data_meta_x]); } |
268 |
break; |
269 |
// 2003-04-16: required for xmltree-to-item transition |
270 |
// if we dont do this the "dotted" filter expression would persist across views |
271 |
case "item": |
272 |
if ($pre_out[options][ecoms][$label][ecom_data_filter]) { unset($pre_out[options][ecoms][$label][ecom_data_filter]); } |
273 |
break; |
274 |
case "tree": |
275 |
if ($pre_out[options][ecoms][$label][ecom_data_filter]) { unset($pre_out[options][ecoms][$label][ecom_data_filter]); } |
276 |
if ($pre_out[options][ecoms][$label][ecom_data_meta]) { unset($pre_out[options][ecoms][$label][ecom_data_meta]); } |
277 |
break; |
278 |
} |
279 |
$_out = $pre_out; |
280 |
'), |
281 |
|
282 |
// reset machine |
283 |
create_function('&$_in, &$_out', ' |
284 |
// HACK!!! |
285 |
// FIXME: review and implement in a more clean way? |
286 |
//print "RESET!<br/>"; |
287 |
$_out[options][ecoms][phase_startup] = "RESET"; |
288 |
'), |
289 |
|
290 |
// rewrite idents |
291 |
create_function('&$_in, &$_out', ' |
292 |
|
293 |
// old version: ap == explorer |
294 |
// map Topic to Page if exists |
295 |
//if ($_in[topic]) { |
296 |
// $_in[ap] = $_in[topic]; |
297 |
//} |
298 |
//$idents = array ( ap ); |
299 |
//foreach($idents as $key) { |
300 |
// $_out[options][idents][$key] = $_in[$key]; |
301 |
//} |
302 |
|
303 |
// 2003-06-26: switched from ap=explorer to t=DataBrowser |
304 |
$_out[options][idents][t] = $_in[topic]; |
305 |
|
306 |
'), |
307 |
|
308 |
// check right $_GET[ap] - depreciated |
309 |
//create_function('&$_in, &$_out', 'return ($_in[ap] != "explorer") ? print "Wrong application value [ap]: $_in[ap], sure this is right here?<br>" : null;'), |
310 |
|
311 |
// write components variables to out |
312 |
create_function('&$_in, &$_out', ' |
313 |
$vars = array( |
314 |
ecom_type, ecom_abstract_type, ecom_mode, ecom_data_locator_key, |
315 |
ecom_data_ident, ecom_data_meta, ecom_data_filter, ecom_data_meta_x |
316 |
); |
317 |
// ecom_call_method, ecom_call_args |
318 |
if($_in[ecom_label]) { |
319 |
foreach($vars as $key) { |
320 |
if($_in[$key]) { |
321 |
//print "var: " . $key . " value: " . $_in[$key] . "<br>"; |
322 |
$label = $_in[ecom_label]; |
323 |
$_out[options][ecoms][$label][$key] = $_in[$key]; |
324 |
} |
325 |
} |
326 |
} |
327 |
|
328 |
return; |
329 |
'), |
330 |
|
331 |
// create default ecoms (navigation, chooser [as of 2003-04-05] etc.) |
332 |
create_function('&$_in, &$_out', ' |
333 |
if(!$_out[options][ecoms] || !is_array($_out[options][ecoms])) { |
334 |
$_out[options][ecoms] = array( |
335 |
nav => array( |
336 |
ecom_type => "nav", |
337 |
ecom_abstract_type => "list", |
338 |
ecom_mode => "link", |
339 |
ecom_data_locator_key => "rpc", |
340 |
), |
341 |
chooser => array( |
342 |
ecom_type => "nav", |
343 |
ecom_abstract_type => "list", |
344 |
ecom_mode => "link", |
345 |
ecom_data_locator_key => "rpc", |
346 |
), |
347 |
); |
348 |
} |
349 |
//$_out[options][components] = $_in[components]; |
350 |
return; |
351 |
'), |
352 |
|
353 |
// handle data form action(button) |
354 |
create_function('&$_in, &$_out', ' |
355 |
if($_in[ap] == "Benutzerverwaltung" || $_in[topic] == "Benutzerverwaltung") { |
356 |
if(!$_out[options][ecoms][UMnav]) { |
357 |
$_out[options][ecoms][UMnav] = array( |
358 |
ecom_type => "nav", |
359 |
ecom_abstract_type => "tree", |
360 |
ecom_mode => "link", |
361 |
ecom_data_locator_key => "rpc", |
362 |
); |
363 |
} |
364 |
} |
365 |
'), |
366 |
|
367 |
// handle data form action(button) |
368 |
create_function('&$_in, &$_out', ' |
369 |
$label = $_in[ecom_label]; |
370 |
if($_in[ecom_data_form_action]) { |
371 |
//print "from action button pressed!<br>"; |
372 |
if(is_array($_in[ecom_data_form_checkbox])) { |
373 |
$cnt = sizeof($_in[ecom_data_form_checkbox]); |
374 |
$tmp = array(); |
375 |
foreach($_in[ecom_data_form_checkbox] as $ident) { |
376 |
if($ident) { array_push($tmp, $ident); } |
377 |
} |
378 |
if($cnt == 1) { |
379 |
print "Single selection, ident : " . $tmp[0] . "<br>"; |
380 |
$_out[options][ecoms][$label][ecom_data_ident] = $tmp[0]; |
381 |
$_out[options][ecoms][$label][ecom_abstract_type] = "item"; |
382 |
} elseif($cnt > 1) { |
383 |
// TODO: implement multi-selection actions on rows(items) here!! |
384 |
print "Multi-Selection!! Current Ident(s) $tmp" . "<br>"; |
385 |
$_out[options][ecoms][$label][ecom_data_ident] = $tmp; |
386 |
} |
387 |
} else { |
388 |
print "ident: " . Dumper($_out[options][ecoms][$label][ecom_data_ident]) . "<br>"; |
389 |
} |
390 |
$_out[options][ecoms][$label][ecom_data_meta] = $_in[ecom_data_ident]; |
391 |
$_out[options][ecoms][$label][ecom_mode] = $_in[ecom_data_form_action]; |
392 |
//print "in: " . Dumper($_in) . "<br>"; |
393 |
//print "out: " . Dumper($_out) . "<br>"; |
394 |
} |
395 |
'), |
396 |
|
397 |
|
398 |
// handle data form buttons |
399 |
create_function('&$_in, &$_out', ' |
400 |
$label = $_in[ecom_label]; |
401 |
if($_in[ecom_data_action_edit]) { |
402 |
$_out[options][ecoms][$label][ecom_mode] = "edit"; |
403 |
$_out[options][ecoms][$label][ecom_abstract_type] = "item"; |
404 |
} |
405 |
if($_in[ecom_data_action_cancel]) { |
406 |
$_out[options][ecoms][$label][ecom_mode] = "view"; |
407 |
$_out[options][ecoms][$label][ecom_abstract_type] = "item"; |
408 |
} |
409 |
|
410 |
// Action.Create |
411 |
if($_in[ecom_data_action_create]) { |
412 |
//print Dumper($_out[options][ecoms][$label]); |
413 |
$_out[options][ecoms][$label][ecom_mode] = "create"; |
414 |
$_out[options][ecoms][$label][ecom_abstract_type] = "item"; |
415 |
} |
416 |
|
417 |
// Action.Delete [new of 2003-04-09] |
418 |
if ($_in[ecom_data_action_delete]) { |
419 |
|
420 |
//$_out[options][ecoms][content][ecom_mode] = "view"; |
421 |
|
422 |
// the code here vanished to the component itself! |
423 |
// could/should we do this for "edit" and/or "view" actions as well? |
424 |
// look at ecom/FlexibleDataItem! |
425 |
|
426 |
$_out[options][ecoms][$label][ecom_abstract_type] = "item"; |
427 |
} |
428 |
'), |
429 |
|
430 |
// propagate datasources to ecoms |
431 |
// datasource-change requested? enhance logic here! |
432 |
// by now each ecom-component gets injected the very same |
433 |
// datasource if requested - otherwise everything will fall back to defaults |
434 |
create_function('&$_in, &$_out', ' |
435 |
if ($_in[ecom_data_source_key]) { |
436 |
|
437 |
print "YAI: ecom_data_source_key<br/>"; |
438 |
|
439 |
//print Dumper($_out[options][ecoms]); |
440 |
//print "ds: " . $_in[ecom_data_source_key] . "<br/>"; |
441 |
/* |
442 |
foreach ($_out[options][ecoms] as $name => $ecom) { |
443 |
print "name: $name<br/>"; |
444 |
//$_out[options][sources][selected] = $_in[ecom_data_source]; |
445 |
$_out[options][ecoms][$name][ecom_data_source_key] = $_in[ecom_data_source_key]; |
446 |
} |
447 |
*/ |
448 |
$_out[options][main][ecom_data_source_key] = $_in[ecom_data_source_key]; |
449 |
|
450 |
|
451 |
// 2003-04-07 - enhanced |
452 |
// now activates a special ecom-component - a "RemoteAction" - replacing |
453 |
// the "content"-ecom instead of displaying an empty page / overriding any |
454 |
// view reached by "normal dispatching" |
455 |
|
456 |
$_out[options][ecoms][phase_startup] = array( |
457 |
ecom_type => "call", |
458 |
ecom_abstract_type => "auto", |
459 |
ecom_mode => "link", |
460 |
ecom_data_locator_key => "rpc", |
461 |
// new attributes/properties/arguments that control further / trigger different DataFlow: |
462 |
// FIXME: add these to declaration at top! |
463 |
ecom_call_method => "selectSource", |
464 |
ecom_call_args => $_in[ecom_data_source_key] |
465 |
); |
466 |
|
467 |
} |
468 |
'), |
469 |
|
470 |
|
471 |
/* |
472 |
// translate value of argument "action" (olist => list.view, oedit => item.edit) |
473 |
// action dispatcher |
474 |
create_function('&$_in, &$_out', ' |
475 |
$_out = $_in; |
476 |
switch ($_out[action]) { |
477 |
case "olist": |
478 |
$_out[action] = "list.view"; |
479 |
break; |
480 |
case "oedit": |
481 |
$_out[action] = "item.edit"; |
482 |
break; |
483 |
case "": |
484 |
print "ExplorerController: selecting default action \"list.view\" in rule #2.<br/>"; |
485 |
$_out[options][action] = "list.view"; |
486 |
return; |
487 |
break; |
488 |
} |
489 |
//return "last"; |
490 |
'), |
491 |
|
492 |
|
493 |
// dummy rule - just returns |
494 |
create_function('&$_in, &$_out', ' |
495 |
return; |
496 |
if ($_in[topic] == "DataBrowser.item.edit" || $_in[page] == "oedit") { |
497 |
$_out[view] = "Page::DataBrowser"; |
498 |
$_out[options] = array( caption_context => "Item - [edit]", args => array(HTML, "UB_ITEM")); |
499 |
} |
500 |
'), |
501 |
*/ |
502 |
|
503 |
|
504 |
// tracing-rule - dumps $_in and $_out |
505 |
/* |
506 |
create_function('&$_in, &$_out', ' |
507 |
print "I am here: AnyMVC<br/>"; |
508 |
print "in: " . Dumper($_in); |
509 |
print "out: " . Dumper($_out); |
510 |
//exit; |
511 |
return; |
512 |
'), |
513 |
*/ |
514 |
), |
515 |
)); |
516 |
|
517 |
} |
518 |
|
519 |
|
520 |
} |
521 |
|
522 |
?> |