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