1 |
jonen |
1.1 |
<?php |
2 |
|
|
|
3 |
|
|
/** |
4 |
joko |
1.10 |
* $Id: MVC.php,v 1.9 2003/04/09 00:05:50 jonen Exp $ |
5 |
jonen |
1.1 |
* |
6 |
|
|
* $Log: MVC.php,v $ |
7 |
joko |
1.10 |
* Revision 1.9 2003/04/09 00:05:50 jonen |
8 |
|
|
* added request values and functions needed for extended form handling |
9 |
|
|
* |
10 |
jonen |
1.9 |
* Revision 1.8 2003/04/08 17:53:08 joko |
11 |
|
|
* NEW: Module 'RemoteAction' in 'phase_startup' |
12 |
|
|
* |
13 |
joko |
1.8 |
* Revision 1.7 2003/04/07 22:32:27 jonen |
14 |
|
|
* + minor changes related to new ecom 'chooser' |
15 |
|
|
* |
16 |
jonen |
1.7 |
* Revision 1.6 2003/04/06 01:32:57 jonen |
17 |
|
|
* + minor changes |
18 |
|
|
* |
19 |
jonen |
1.6 |
* Revision 1.5 2003/04/05 21:18:29 joko |
20 |
|
|
* added Chooser and associated 'ecds'-parameter |
21 |
|
|
* new rule (at bottom) to dispatch datasource-keys to each ecom-component |
22 |
|
|
* |
23 |
joko |
1.5 |
* Revision 1.4 2003/04/04 23:59:19 jonen |
24 |
|
|
* + minor changes according to data form submits |
25 |
|
|
* |
26 |
jonen |
1.4 |
* Revision 1.3 2003/04/04 01:28:13 jonen |
27 |
|
|
* + added function to purge unwanted merged vars |
28 |
|
|
* + handle form submit's now |
29 |
|
|
* |
30 |
jonen |
1.3 |
* Revision 1.2 2003/03/20 07:54:52 jonen |
31 |
|
|
* + added docu |
32 |
|
|
* |
33 |
jonen |
1.2 |
* Revision 1.1 2003/03/20 03:48:47 jonen |
34 |
|
|
* + initial commit |
35 |
|
|
* |
36 |
jonen |
1.1 |
* Revision 1.2 2003/03/18 00:00:20 cvsmax |
37 |
|
|
* + added thoughts and models for preparing control data to Explorer |
38 |
|
|
* |
39 |
|
|
* Revision 1.1 2003/03/08 02:36:39 cvsmax |
40 |
|
|
* + moved from *.inc |
41 |
|
|
* + mungled namespace with WebExplorer |
42 |
|
|
* |
43 |
|
|
* Revision 1.1 2003/03/03 22:26:16 joko |
44 |
|
|
* + initial commit, inherits from WebMVC |
45 |
|
|
* |
46 |
|
|
* Revision 1.1 2003/03/02 00:49:36 joko |
47 |
|
|
* + initial commit |
48 |
|
|
* |
49 |
|
|
* |
50 |
|
|
*/ |
51 |
jonen |
1.2 |
|
52 |
|
|
/** |
53 |
|
|
* WebExplorer::MVC - this the MVC used by the WebExplorer. |
54 |
|
|
* Its derived from the 'Site::WebAppMVC' module. |
55 |
|
|
* |
56 |
|
|
* @author Sebastian Utz <seut@tunemedia.de> |
57 |
|
|
* @package org.netfrag.app |
58 |
|
|
* @name WebExplorer::MVC |
59 |
|
|
*/ |
60 |
|
|
|
61 |
jonen |
1.1 |
loadModule('Site::WebAppMVC'); |
62 |
|
|
|
63 |
|
|
class WebExplorer_MVC extends Site_WebAppMVC { |
64 |
|
|
|
65 |
|
|
//var $_backend = null; |
66 |
|
|
var $_raw = array(); |
67 |
|
|
var $_registry = array(); |
68 |
|
|
|
69 |
|
|
function WebExplorer_MVC(&$args) { |
70 |
|
|
|
71 |
|
|
parent::constructor(); |
72 |
|
|
|
73 |
|
|
// new!!! a registry for Views!!! |
74 |
|
|
//$regdb = $this->getStaticRegistryDatabase(); |
75 |
|
|
//$this->_registry = mkObject('Application::ComponentRegistry', &$regdb, 'REGDB_PAYLOAD'); |
76 |
|
|
|
77 |
|
|
// new!!! storing the raw request here |
78 |
|
|
$this->_raw[request] = &$args[request]; |
79 |
|
|
|
80 |
|
|
// new!!! user_setup, phpHtmlLib-style... |
81 |
|
|
$this->user_setup(); |
82 |
|
|
|
83 |
|
|
} |
84 |
|
|
|
85 |
|
|
// setup MVC (model-view-controller) metadata information |
86 |
|
|
function user_setup() { |
87 |
|
|
|
88 |
|
|
$this->add_model( array( |
89 |
|
|
//args => array( 'classname', 'guid', 'action', 'data_locator_key', 'block' ), |
90 |
joko |
1.5 |
request_args => array( |
91 |
|
|
// ApplicationPage |
92 |
|
|
'ap', |
93 |
|
|
// important/required parameters for valid ecom-components |
94 |
|
|
'ecom_label', 'ecom_type', 'ecom_abstract_type', 'ecom_mode', |
95 |
|
|
// parameters about data identifiers, locations, sources and associated meta-information |
96 |
|
|
'ecom_data_locator_key', |
97 |
|
|
'ecom_data_ident', |
98 |
|
|
'ecom_data_meta', |
99 |
joko |
1.10 |
'ecom_data_action_edit', 'ecom_data_action_cancel', 'ecom_data_action_delete', |
100 |
jonen |
1.9 |
'ecom_data_form_checkbox', 'ecom_data_form_action', |
101 |
joko |
1.5 |
'ecom_data_source_key' |
102 |
|
|
), |
103 |
jonen |
1.1 |
request_arg => array( |
104 |
|
|
'ap' => array( query_arg => 'ap' ), |
105 |
|
|
'ecom_label' => array( query_arg => 'ecl' ), |
106 |
|
|
'ecom_type' => array( query_arg => 'ect' ), |
107 |
|
|
'ecom_abstract_type' => array( query_arg => 'ecat' ), |
108 |
jonen |
1.3 |
'ecom_mode' => array( query_arg => 'ecmod' ), |
109 |
jonen |
1.1 |
'ecom_data_locator_key' => array( query_arg => 'ecdlk' ), |
110 |
|
|
'ecom_data_ident' => array( query_arg => 'ecdid' ), |
111 |
|
|
'ecom_data_meta' => array( query_arg => 'ecdm' ), |
112 |
joko |
1.10 |
'ecom_data_action_edit' => array( query_arg => 'ecdfe' ), |
113 |
|
|
'ecom_data_action_cancel' => array( query_arg => 'ecdfc' ), |
114 |
|
|
'ecom_data_action_delete' => array( query_arg => 'ecdfd' ), |
115 |
jonen |
1.9 |
'ecom_data_form_action' => array( query_arg => 'ecdfa' ), |
116 |
|
|
'ecom_data_form_checkbox' => array( query_arg => 'checkbox' ), |
117 |
joko |
1.5 |
'ecom_data_source_key' => array( query_arg => 'ecds' ), |
118 |
jonen |
1.1 |
), |
119 |
|
|
|
120 |
|
|
/* |
121 |
|
|
// block model (what is used for each block) |
122 |
|
|
block => array( |
123 |
|
|
'ident' => array( query_arg => 'ident' ), |
124 |
|
|
'meta' => array( query_arg => 'meta' ), |
125 |
|
|
'action' => array( query_arg => 'action'), |
126 |
|
|
'data_locator_key' => array( query_arg => 'dlk' ), |
127 |
|
|
'gui_module' => array( query_arg => 'gm' ), |
128 |
|
|
'abstract_type' => array( query_arg => 'at' ), |
129 |
|
|
), |
130 |
|
|
*/ |
131 |
|
|
|
132 |
|
|
)); |
133 |
|
|
|
134 |
|
|
//$this->setup_views( &$this->_registry ); |
135 |
|
|
|
136 |
|
|
// associate behaviour with "View"-components |
137 |
|
|
// identify component by: module name or component identifier (COID) |
138 |
|
|
// 'name' is looked up in that to get metadata information about the comp. |
139 |
|
|
// component: for 'component = 1', a component registry is required!!! |
140 |
|
|
// name: registry-lookup: by-name |
141 |
|
|
// COID: registry-lookup: by-COID |
142 |
|
|
// caption: caption of area or title of page |
143 |
|
|
$this->add_view( array( |
144 |
|
|
component => 1, |
145 |
|
|
name => 'NavigationList', |
146 |
|
|
// COID => '123', |
147 |
|
|
caption => "Explorer - NavigationList", |
148 |
|
|
)); |
149 |
|
|
$this->add_view( array( |
150 |
|
|
component => 1, |
151 |
|
|
name => 'ExplorerDataList', |
152 |
|
|
// COID => '123', |
153 |
|
|
caption => "Explorer - ExplorerDataList", |
154 |
|
|
)); |
155 |
|
|
$this->add_view( array( |
156 |
|
|
component => 1, |
157 |
|
|
name => 'ExplorerDataItem', |
158 |
|
|
// COID => '123', |
159 |
|
|
caption => "Explorer - ExplorerDataItem", |
160 |
|
|
)); |
161 |
jonen |
1.6 |
|
162 |
jonen |
1.1 |
// FIXME!!! enhance!?!? |
163 |
|
|
// AIM: "dispatch a Request to a View by using rules..." |
164 |
|
|
// Todo: |
165 |
|
|
// 'HttpController' is *very* dumb by now, it just iterates |
166 |
|
|
// this flat list below triggering the lambdas with their arguments. |
167 |
|
|
// Enhance this backend and introduce a mechanism to trigger |
168 |
|
|
// a true callback to process a rule (or: "as a rule") on top of that. |
169 |
|
|
$this->add_controller( array( |
170 |
joko |
1.5 |
|
171 |
jonen |
1.1 |
// for "module", no component registry is required, just does 'mkObject' under the hood |
172 |
|
|
module => 'Application::Request::HttpController', |
173 |
jonen |
1.6 |
//module_options => blah |
174 |
|
|
|
175 |
jonen |
1.1 |
rules => array( |
176 |
|
|
|
177 |
|
|
// get last page state |
178 |
|
|
create_function('&$_in, &$_out', ' |
179 |
|
|
$requestTracker = mkObject("Application::Request::Tracker"); |
180 |
|
|
$page_state = $requestTracker->getPointer(); |
181 |
jonen |
1.3 |
$pre_out = $page_state[options]; |
182 |
|
|
//print Dumper($pre_out); |
183 |
|
|
// clean-up unwanted variables |
184 |
|
|
$label = $_in[ecom_label]; |
185 |
|
|
switch ($_in[ecom_abstract_type]) { |
186 |
|
|
case "list": |
187 |
|
|
if($pre_out[options][ecoms][$label][ecom_data_meta]) { unset($pre_out[options][ecoms][$label][ecom_data_meta]); } |
188 |
|
|
break; |
189 |
|
|
} |
190 |
|
|
$_out = $pre_out; |
191 |
jonen |
1.1 |
'), |
192 |
|
|
|
193 |
joko |
1.10 |
// reset machine |
194 |
|
|
create_function('&$_in, &$_out', ' |
195 |
|
|
// HACK!!! |
196 |
|
|
// FIXME: review and implement in a more clean way? |
197 |
|
|
//print "RESET!<br/>"; |
198 |
|
|
|
199 |
|
|
$_out[options][ecoms][phase_startup] = "RESET"; |
200 |
|
|
'), |
201 |
|
|
|
202 |
jonen |
1.1 |
// rewrite idents |
203 |
|
|
create_function('&$_in, &$_out', ' |
204 |
|
|
$idents = array ( ap, ); |
205 |
|
|
foreach($idents as $key) { |
206 |
|
|
$_out[options][idents][$key] = $_in[$key]; |
207 |
|
|
} |
208 |
|
|
'), |
209 |
|
|
|
210 |
|
|
// check right $_GET[ap] |
211 |
jonen |
1.6 |
create_function('&$_in, &$_out', 'return ($_in[ap] != "explorer") ? print "Wrong application value: $_in[ap], sure this is right here?<br>" : null;'), |
212 |
jonen |
1.1 |
|
213 |
|
|
// write components variables to out |
214 |
|
|
create_function('&$_in, &$_out', ' |
215 |
joko |
1.10 |
$vars = array( |
216 |
|
|
ecom_type, ecom_abstract_type, ecom_mode, ecom_data_locator_key, ecom_data_ident, ecom_data_meta |
217 |
|
|
); |
218 |
|
|
// ecom_call_method, ecom_call_args |
219 |
jonen |
1.1 |
if($_in[ecom_label]) { |
220 |
|
|
foreach($vars as $key) { |
221 |
|
|
if($_in[$key]) { |
222 |
|
|
$label = $_in[ecom_label]; |
223 |
|
|
$_out[options][ecoms][$label][$key] = $_in[$key]; |
224 |
|
|
} |
225 |
|
|
} |
226 |
|
|
} |
227 |
|
|
|
228 |
|
|
return; |
229 |
|
|
'), |
230 |
|
|
|
231 |
joko |
1.5 |
// create default ecoms (navigation, chooser [as of 2003-04-05] etc.) |
232 |
jonen |
1.1 |
create_function('&$_in, &$_out', ' |
233 |
|
|
if(!$_out[options][ecoms] || !is_array($_out[options][ecoms])) { |
234 |
|
|
$_out[options][ecoms] = array( |
235 |
|
|
nav => array( |
236 |
|
|
ecom_type => "nav", |
237 |
|
|
ecom_abstract_type => "list", |
238 |
jonen |
1.7 |
ecom_mode => "link", |
239 |
jonen |
1.1 |
ecom_data_locator_key => "rpc", |
240 |
|
|
), |
241 |
joko |
1.5 |
chooser => array( |
242 |
jonen |
1.7 |
ecom_type => "nav", |
243 |
joko |
1.5 |
ecom_abstract_type => "list", |
244 |
jonen |
1.7 |
ecom_mode => "link", |
245 |
joko |
1.5 |
ecom_data_locator_key => "rpc", |
246 |
|
|
), |
247 |
jonen |
1.1 |
); |
248 |
|
|
} |
249 |
|
|
//$_out[options][components] = $_in[components]; |
250 |
|
|
return; |
251 |
|
|
'), |
252 |
jonen |
1.9 |
|
253 |
|
|
|
254 |
|
|
// handle data form action(button) |
255 |
|
|
create_function('&$_in, &$_out', ' |
256 |
|
|
$label = $_in[ecom_label]; |
257 |
|
|
if($_in[ecom_data_form_action] && is_array($_in[ecom_data_form_checkbox])) { |
258 |
|
|
$cnt = sizeof($_in[ecom_data_form_checkbox]); |
259 |
|
|
if($cnt == 1) { |
260 |
|
|
foreach($_in[ecom_data_form_checkbox] as $ident) { |
261 |
|
|
$_out[options][ecoms][$label][ecom_data_ident] = $ident; |
262 |
|
|
} |
263 |
|
|
$_out[options][ecoms][$label][ecom_data_meta] = $_in[ecom_data_ident]; |
264 |
|
|
$_out[options][ecoms][$label][ecom_mode] = $_in[ecom_data_form_action]; |
265 |
|
|
$_out[options][ecoms][$label][ecom_abstract_type] = "item"; |
266 |
|
|
} else { |
267 |
|
|
// TODO: implement multi-selection actions on rows(items) here!! |
268 |
|
|
} |
269 |
|
|
} |
270 |
|
|
'), |
271 |
|
|
|
272 |
jonen |
1.1 |
|
273 |
jonen |
1.4 |
// handle data form buttons |
274 |
jonen |
1.3 |
create_function('&$_in, &$_out', ' |
275 |
|
|
$label = $_in[ecom_label]; |
276 |
joko |
1.10 |
if($_in[ecom_data_action_edit]) { $_out[options][ecoms][$label][ecom_mode] = "edit"; } |
277 |
|
|
if($_in[ecom_data_action_cancel]) { $_out[options][ecoms][$label][ecom_mode] = "view"; } |
278 |
|
|
|
279 |
|
|
// Action.Delete [new of 2003-04-09] |
280 |
|
|
if ($_in[ecom_data_action_delete]) { |
281 |
|
|
|
282 |
|
|
// the code here vanished to the component itself! |
283 |
|
|
// could/should we do this for "edit" and/or "view" actions as well? |
284 |
|
|
// look at ecom/FlexibleDataItem! |
285 |
|
|
|
286 |
|
|
} |
287 |
|
|
|
288 |
jonen |
1.3 |
'), |
289 |
joko |
1.5 |
|
290 |
|
|
// propagate datasources to ecoms |
291 |
|
|
// datasource-change requested? enhance logic here! |
292 |
|
|
// by now each ecom-component gets injected the very same |
293 |
|
|
// datasource if requested - otherwise everything will fall back to defaults |
294 |
|
|
create_function('&$_in, &$_out', ' |
295 |
|
|
if ($_in[ecom_data_source_key]) { |
296 |
joko |
1.8 |
|
297 |
joko |
1.10 |
print "YAI: ecom_data_source_key<br/>"; |
298 |
joko |
1.8 |
|
299 |
joko |
1.5 |
//print Dumper($_out[options][ecoms]); |
300 |
|
|
//print "ds: " . $_in[ecom_data_source_key] . "<br/>"; |
301 |
|
|
/* |
302 |
|
|
foreach ($_out[options][ecoms] as $name => $ecom) { |
303 |
|
|
print "name: $name<br/>"; |
304 |
|
|
//$_out[options][sources][selected] = $_in[ecom_data_source]; |
305 |
|
|
$_out[options][ecoms][$name][ecom_data_source_key] = $_in[ecom_data_source_key]; |
306 |
|
|
} |
307 |
|
|
*/ |
308 |
|
|
$_out[options][main][ecom_data_source_key] = $_in[ecom_data_source_key]; |
309 |
joko |
1.8 |
|
310 |
|
|
|
311 |
|
|
// 2003-04-07 - enhanced |
312 |
|
|
// now activates a special ecom-component - a "RemoteAction" - replacing |
313 |
|
|
// the "content"-ecom instead of displaying an empty page / overriding any |
314 |
|
|
// view reached by "normal dispatching" |
315 |
|
|
|
316 |
|
|
$_out[options][ecoms][phase_startup] = array( |
317 |
|
|
ecom_type => "call", |
318 |
|
|
ecom_abstract_type => "auto", |
319 |
|
|
ecom_mode => "link", |
320 |
|
|
ecom_data_locator_key => "rpc", |
321 |
|
|
// new attributes/properties/arguments that control further / trigger different DataFlow: |
322 |
joko |
1.10 |
// FIXME: add these to declaration at top! |
323 |
joko |
1.8 |
ecom_call_method => "selectSource", |
324 |
|
|
ecom_call_args => $_in[ecom_data_source_key] |
325 |
|
|
); |
326 |
|
|
|
327 |
joko |
1.5 |
} |
328 |
|
|
'), |
329 |
|
|
|
330 |
jonen |
1.4 |
|
331 |
jonen |
1.1 |
/* |
332 |
|
|
// translate value of argument "action" (olist => list.view, oedit => item.edit) |
333 |
|
|
// action dispatcher |
334 |
|
|
create_function('&$_in, &$_out', ' |
335 |
|
|
$_out = $_in; |
336 |
|
|
switch ($_out[action]) { |
337 |
|
|
case "olist": |
338 |
|
|
$_out[action] = "list.view"; |
339 |
|
|
break; |
340 |
|
|
case "oedit": |
341 |
|
|
$_out[action] = "item.edit"; |
342 |
|
|
break; |
343 |
|
|
case "": |
344 |
|
|
print "ExplorerController: selecting default action \"list.view\" in rule #2.<br/>"; |
345 |
|
|
$_out[options][action] = "list.view"; |
346 |
|
|
return; |
347 |
|
|
break; |
348 |
|
|
} |
349 |
|
|
//return "last"; |
350 |
|
|
'), |
351 |
|
|
|
352 |
|
|
|
353 |
|
|
// dummy rule - just returns |
354 |
|
|
create_function('&$_in, &$_out', ' |
355 |
|
|
return; |
356 |
|
|
if ($_in[topic] == "DataBrowser.item.edit" || $_in[page] == "oedit") { |
357 |
|
|
$_out[view] = "Page::DataBrowser"; |
358 |
|
|
$_out[options] = array( caption_context => "Item - [edit]", args => array(HTML, "UB_ITEM")); |
359 |
|
|
} |
360 |
|
|
'), |
361 |
|
|
*/ |
362 |
|
|
|
363 |
|
|
|
364 |
|
|
// tracing-rule - dumps $_in and $_out |
365 |
|
|
/* |
366 |
|
|
create_function('&$_in, &$_out', ' |
367 |
|
|
print "I am here: AnyMVC<br/>"; |
368 |
|
|
print "in: " . Dumper($_in); |
369 |
|
|
print "out: " . Dumper($_out); |
370 |
|
|
//exit; |
371 |
|
|
return; |
372 |
|
|
'), |
373 |
|
|
*/ |
374 |
|
|
), |
375 |
|
|
)); |
376 |
|
|
|
377 |
|
|
} |
378 |
|
|
|
379 |
|
|
|
380 |
|
|
} |
381 |
|
|
|
382 |
|
|
?> |