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