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