/[cvs]/nfo/php/libs/org.netfrag.app/WebExplorer/MVC.php
ViewVC logotype

Contents of /nfo/php/libs/org.netfrag.app/WebExplorer/MVC.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.21 - (show annotations)
Sun Dec 14 01:51:29 2003 UTC (20 years, 6 months ago) by jonen
Branch: MAIN
CVS Tags: HEAD
Changes since 1.20: +40 -5 lines
implemented 'SELECT' mode for selecting existing object-refereneces as child-nodes

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

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed