1 |
jonen |
1.1 |
<? |
2 |
|
|
/* |
3 |
|
|
## ----------------------------------------------------------------------------- |
4 |
joko |
1.3 |
## $Id: GenericGUIDataList.php,v 1.2 2003/04/04 00:45:40 jonen Exp $ |
5 |
jonen |
1.1 |
## ----------------------------------------------------------------------------- |
6 |
jonen |
1.2 |
## $Log: GenericGUIDataList.php,v $ |
7 |
joko |
1.3 |
## Revision 1.2 2003/04/04 00:45:40 jonen |
8 |
|
|
## + reworked decode functions |
9 |
|
|
## |
10 |
jonen |
1.2 |
## Revision 1.1 2003/03/27 01:17:31 jonen |
11 |
|
|
## + inital commit (was orginal 'ObjectList.inc) |
12 |
|
|
## |
13 |
jonen |
1.1 |
## Revision 1.1 2003/03/20 04:17:28 jonen |
14 |
|
|
## + initial commit |
15 |
|
|
## |
16 |
|
|
## Revision 1.2 2003/03/02 04:32:22 cvsmax |
17 |
|
|
## + add decode_item functions |
18 |
|
|
## |
19 |
|
|
## Revision 1.1 2003/03/01 22:57:40 cvsmax |
20 |
|
|
## + inital commit |
21 |
|
|
## |
22 |
|
|
## |
23 |
|
|
## ----------------------------------------------------------------------------- |
24 |
|
|
*/ |
25 |
|
|
|
26 |
|
|
/** |
27 |
|
|
* Need to make sure we have the DefaultGUIDataList object |
28 |
|
|
*/ |
29 |
|
|
require_once($phphtmllib."/widgets/data_list/DefaultGUIDataList.inc"); |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
class GenericGUIDataList extends DefaultGUIDataList { |
33 |
|
|
|
34 |
|
|
/** |
35 |
|
|
* Args needed for object list. |
36 |
|
|
* Current use: |
37 |
|
|
* - use some bits to create locator metadata (see below) |
38 |
|
|
* - use all options to propagate to an AdapterProxy (here: GenericDataSource) |
39 |
|
|
* as a query to receive a list of objects as response to a rpc-call. |
40 |
|
|
* Todo: glossary: ban "*list* of objects" - it's an object *set* !!! (see CPAN's Set::Object) |
41 |
|
|
* |
42 |
|
|
*/ |
43 |
|
|
var $_options = NULL; |
44 |
|
|
|
45 |
jonen |
1.2 |
/** |
46 |
|
|
* Holds a list of hidden elements |
47 |
|
|
* |
48 |
|
|
*/ |
49 |
|
|
var $_hidden_elements = array(); |
50 |
|
|
|
51 |
jonen |
1.1 |
/** |
52 |
|
|
* The constructor is used to pass in some additional |
53 |
|
|
* metadata informations as "options". |
54 |
|
|
* The "locator metadata hash" isn't passed in here |
55 |
|
|
* any more. Handling this one occours one level deeper |
56 |
|
|
* inside the "GenericDataSource" Proxy. |
57 |
|
|
* |
58 |
|
|
* It's still possible to set locator metadata directly by |
59 |
|
|
* using the optional key 'locator' inside your options hash. |
60 |
|
|
* This can be either a DataSource::Locator instance or a plain |
61 |
|
|
* hash. However - it gets merged to the master locator |
62 |
|
|
* created by GenericDataSource using 'array_join_merge'. |
63 |
|
|
* |
64 |
|
|
* @param old: LocatorMetadataHash array - layout: array( type => '', metadata => '', dsn => '' ) |
65 |
|
|
* @param old: Query array - layout: array( type => '', metadata => '', dsn => '' ) |
66 |
|
|
* |
67 |
|
|
* @param new: options array - layout: array( datasource_type => '', [locator => array()] ) |
68 |
|
|
* |
69 |
|
|
* |
70 |
|
|
*/ |
71 |
|
|
function GenericGUIDataList($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE, $options = array()) { |
72 |
|
|
if ($options) { $this->_options = $options; } |
73 |
|
|
$parent = get_parent_class($this); |
74 |
|
|
$this->$parent($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE); |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
function get_data_source( ) { |
78 |
|
|
|
79 |
|
|
// finally: create phpHtmlLib source handle (XyzDataListSource) |
80 |
|
|
|
81 |
|
|
// V1: |
82 |
|
|
//$source = new GenericDataSource($this->_locator, $this->_options); |
83 |
|
|
//$this->set_data_source( &$source ); |
84 |
|
|
|
85 |
|
|
/* |
86 |
|
|
// V2: |
87 |
|
|
loadModule("DataSource::GenericDataSource"); |
88 |
|
|
$source = new DataSource_GenericDataSource($this->_locator, $this->_options); |
89 |
|
|
$this->set_data_source( &$source ); |
90 |
|
|
*/ |
91 |
|
|
|
92 |
|
|
// V3: |
93 |
|
|
/* |
94 |
|
|
$proxy = php::mkComponent('DataSource::GenericDataSource', $this->_locator, $this->_options); |
95 |
|
|
$source = &$proxy; |
96 |
|
|
$this->set_data_source( &$source ); |
97 |
|
|
*/ |
98 |
|
|
|
99 |
|
|
// V4: |
100 |
|
|
/* |
101 |
|
|
$proxy = php::mkComponent('DataSource::GenericDataSource', array( proxy => '', adapter => ''), $this->_options); |
102 |
|
|
$source = &$proxy; |
103 |
|
|
$this->set_data_source( &$source ); |
104 |
|
|
*/ |
105 |
|
|
|
106 |
|
|
// V5: |
107 |
|
|
//print "options: " . Dumper($this->_options); |
108 |
|
|
|
109 |
|
|
$initial_locator = php::mkComponent( 'DataSource::Locator', array( adapter_type => 'phpHtmlLib' ) ); |
110 |
|
|
//print "1st locator: " . Dumper($initial_locator); |
111 |
|
|
|
112 |
|
|
// OLD |
113 |
|
|
//$proxy = php::mkComponent('DataSource::Generic', $initial_locator, $this->_options); |
114 |
|
|
|
115 |
|
|
//print "Test Query:"; |
116 |
|
|
//print Dumper($this->_options['query']); |
117 |
|
|
$proxy = php::mkComponent('DataSource::Generic', $initial_locator, $this->_options['data_locator_meta']); |
118 |
|
|
|
119 |
|
|
// debug |
120 |
|
|
//print "Proxy: " . Dumper($proxy); |
121 |
|
|
|
122 |
|
|
// V1: |
123 |
|
|
//$source = &$proxy; |
124 |
|
|
|
125 |
|
|
// V2: |
126 |
|
|
//$source->make_adapter_transparent(); |
127 |
|
|
|
128 |
|
|
// V3: |
129 |
|
|
$source = $proxy->get_adapter(); |
130 |
|
|
|
131 |
|
|
// V4: |
132 |
|
|
//$source = $this->_datasource; |
133 |
|
|
|
134 |
|
|
//print "objectlist-source: " . Dumper($source); |
135 |
|
|
//exit; |
136 |
|
|
|
137 |
|
|
$this->set_data_source( &$source ); |
138 |
|
|
|
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
function user_setup() { |
142 |
|
|
|
143 |
|
|
//return; |
144 |
|
|
|
145 |
|
|
$source = $this->_datasource; |
146 |
|
|
//if (!$source) { return; } |
147 |
|
|
|
148 |
|
|
//print Dumper($source); |
149 |
|
|
$headers = $source->get_header(); |
150 |
|
|
//print Dumper($headers); |
151 |
|
|
|
152 |
|
|
$this->set_title( $this->get_title() . ' - ' . $source->get_total_rows() . ' Einträge' ); |
153 |
|
|
|
154 |
|
|
foreach($headers as $val) { |
155 |
|
|
$this->add_header_item($val, "150", $val, SORTABLE, SEARCHABLE); |
156 |
|
|
} |
157 |
|
|
|
158 |
|
|
/* |
159 |
|
|
$this->add_header_item("Uid", "200", "uid", SORTABLE, SEARCHABLE); |
160 |
|
|
$this->add_header_item("Name", "200", "lastName", SORTABLE, SEARCHABLE, "center"); |
161 |
|
|
*/ |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
|
165 |
|
|
/** |
166 |
|
|
* This function ensures that the data we place |
167 |
|
|
* in a column is aligned according to what the |
168 |
|
|
* user wants. |
169 |
|
|
* |
170 |
|
|
* @param mixed - $obj - the data for the td. |
171 |
|
|
* @param string - $col_name - the name of the column header |
172 |
|
|
* for this row to render. |
173 |
|
|
* @param int - $odd_row - tells us if this cell lives in |
174 |
|
|
* an odd # row (for alternating row colors) |
175 |
|
|
* @param int - the column # we are working on. |
176 |
|
|
* @return TDtag object |
177 |
|
|
*/ |
178 |
|
|
function wrap_column_item($obj, $col_name) { |
179 |
|
|
|
180 |
|
|
//make sure its set to something. |
181 |
|
|
if ($obj == '') { |
182 |
joko |
1.3 |
$obj = " "; |
183 |
jonen |
1.1 |
} |
184 |
joko |
1.3 |
|
185 |
|
|
// decode item / mungle item data? |
186 |
|
|
// TODO: use Data::Lift here!!! (like already done in YAA::JobList and YAA::JobDetails) |
187 |
|
|
elseif ($this->_options['decode']) { |
188 |
|
|
|
189 |
|
|
// Proposal using Data::Lift: (see YAA::JobList and YAA::JobDetails) |
190 |
|
|
// This class will get shorter and better to maintain! |
191 |
|
|
|
192 |
|
|
// Picture Data::Lift as a container component handling |
193 |
|
|
// *specific* en-/decoding stuff for your very core components. |
194 |
|
|
// This way we will have almost all "specific mungling code" at one place. nice thing! |
195 |
|
|
|
196 |
|
|
/* |
197 |
|
|
|
198 |
|
|
// 1. expr: string -> object (phpHtmlLib-object: 'html_a'-tag) |
199 |
|
|
// returns a phpHtmlLib object of class 'Xyz' containing a http-/html-link |
200 |
|
|
// pointing to a View of a different - linked/referenced - object (reference-interpolation) |
201 |
|
|
$this->lift1 = php::mkComponent('Data::Lift', $obj, array( metatype => 'expression' ) ); |
202 |
|
|
$obj = $this->lift1->to('phpHtmlLib::html_a'); |
203 |
|
|
|
204 |
|
|
// 2. data: hash -> object (phpHtmlLib-object: 'container'-object containing form) |
205 |
|
|
// returns a phpHtmlLib object of class 'Container' containing a html-form made up of |
206 |
|
|
// phpHtmlLib form-tags wrapping all attribute-value pairs of the data hash (object-edit) |
207 |
|
|
$this->lift2 = php::mkComponent('Data::Lift', $obj, array( metatype => 'item' ) ); |
208 |
|
|
$obj = $this->lift2->to('phpHtmlLib::form'); |
209 |
|
|
|
210 |
|
|
*/ |
211 |
|
|
|
212 |
|
|
|
213 |
|
|
// 1. if item is match by expression we will replace it with an link object |
214 |
|
|
if ($this->decode_item_expr($obj)) { |
215 |
|
|
$obj = $this->decode_item_expr($obj); |
216 |
|
|
} |
217 |
|
|
|
218 |
|
|
// 2. if item is an Array we will replace it with an selection form object |
219 |
|
|
elseif ( $this->decode_item_array($obj) ) { |
220 |
jonen |
1.1 |
$obj = $this->decode_item_array($obj); |
221 |
|
|
} |
222 |
joko |
1.3 |
|
223 |
jonen |
1.1 |
} |
224 |
joko |
1.3 |
|
225 |
jonen |
1.1 |
//make sure we don't put a right border on the last |
226 |
|
|
//column we are working on. |
227 |
|
|
//$style = "padding-left: 3px;padding-right:3px;border-top: 1px solid #dddddd;"; |
228 |
|
|
|
229 |
|
|
|
230 |
|
|
if ($this->_columns[$col_name]["data_name"] == $this->orderby()) { |
231 |
|
|
$style = "background-color: #f4f4f4;"; |
232 |
|
|
} else { |
233 |
|
|
$style = "background-color: #ffffff;"; |
234 |
|
|
} |
235 |
|
|
|
236 |
|
|
$align = $this->_columns[$col_name]["align"]; |
237 |
|
|
$td = new TDtag(array("align" => $align, |
238 |
|
|
"style" => $style, |
239 |
|
|
"class" => "datalist_data_cell")); |
240 |
|
|
|
241 |
|
|
if (is_object($obj) && $obj->_tag == "td") { |
242 |
|
|
return $obj; |
243 |
|
|
} else { |
244 |
|
|
$td->add( $obj ); |
245 |
|
|
} |
246 |
|
|
return $td; |
247 |
|
|
} |
248 |
|
|
|
249 |
jonen |
1.2 |
function add_hidden_element($label, $value) { |
250 |
|
|
$this->_hidden_elements[$label] = $value; |
251 |
|
|
} |
252 |
|
|
|
253 |
|
|
|
254 |
joko |
1.3 |
// TODO: refactor to Data::Lift - subcomponent: handling will get way more easy! |
255 |
jonen |
1.1 |
function decode_item_array($item) { |
256 |
|
|
$options = $this->_options['decode_args']; |
257 |
joko |
1.3 |
//print "item: " . Dumper($item); |
258 |
|
|
//print "options: " . Dumper($options); |
259 |
jonen |
1.1 |
if( is_array($item) ) { |
260 |
|
|
//$cur_row_index = $this->_datasource->get_cur_data_index(); |
261 |
|
|
//$parent_guid = $this->_datasource->_data[$cur_row_index]['guid']; |
262 |
|
|
// build list for selection form |
263 |
|
|
if($options['form']) { |
264 |
|
|
foreach($item as $key => $value) { |
265 |
|
|
$tmp = split($options['seperator'], $value); |
266 |
|
|
$ident = $tmp['1']; |
267 |
|
|
$meta = $tmp['2']; |
268 |
|
|
$list[$key] = $ident; |
269 |
|
|
} |
270 |
|
|
if(is_array($list) ) { |
271 |
|
|
$container = container( |
272 |
|
|
form_open( $item[0], $_SERVER["PHP_SELF"], "POST" ), |
273 |
jonen |
1.2 |
form_hidden("ecdm", $meta), |
274 |
jonen |
1.1 |
form_select("ecdid", $list), |
275 |
|
|
form_submit("submit","view" ) |
276 |
|
|
); |
277 |
jonen |
1.2 |
foreach($this->_hidden_elements as $label => $value) { |
278 |
jonen |
1.1 |
$container->add(form_hidden($label, $value)); |
279 |
|
|
} |
280 |
|
|
$container->add(form_close() ); |
281 |
|
|
$item = $container; |
282 |
|
|
} |
283 |
|
|
} else { |
284 |
joko |
1.3 |
//print "<b>2</b><br/>"; |
285 |
jonen |
1.1 |
$container = container(); |
286 |
|
|
foreach($item as $key => $value) { |
287 |
|
|
$tmp = split($options['seperator'], $value); |
288 |
|
|
$ident = $tmp['1']; |
289 |
|
|
$meta = $tmp['2']; |
290 |
jonen |
1.2 |
foreach($this->_hidden_elements as $label => $value) { |
291 |
jonen |
1.1 |
$tmp_array[] = $label . "=" . $value; |
292 |
|
|
} |
293 |
|
|
$str_hidden = join("&", $tmp_array); |
294 |
jonen |
1.2 |
$container->add("->", html_a($_SERVER["PHP_SELF"] . "?ecdid=" . $ident . "&ecdm=" . $meta . "&" . $str_hidden, $key . " view"), html_br()); |
295 |
jonen |
1.1 |
} |
296 |
|
|
$item = $container; |
297 |
|
|
} |
298 |
|
|
return $item; |
299 |
|
|
} |
300 |
|
|
} |
301 |
|
|
|
302 |
joko |
1.3 |
// decodes serialized string representations of object-references |
303 |
|
|
// TODO: refactor to Data::Lift - subcomponent: handling will get way more easy! |
304 |
jonen |
1.1 |
function decode_item_expr($item) { |
305 |
|
|
$options = $this->_options['decode_args']; |
306 |
joko |
1.3 |
//print "item: $item<br/>"; |
307 |
jonen |
1.1 |
if(substr($item, 0, 2) == "o_") { |
308 |
|
|
$tmp = split($options['seperator'], $item); |
309 |
|
|
$ident = $tmp['1']; |
310 |
|
|
$meta = $tmp['2']; |
311 |
jonen |
1.2 |
foreach($this->_hidden_elements as $label => $value) { |
312 |
jonen |
1.1 |
$tmp_array[] = $label . "=" . $value; |
313 |
|
|
} |
314 |
|
|
$str_hidden = join("&", $tmp_array); |
315 |
jonen |
1.2 |
$item = html_a($_SERVER["PHP_SELF"] . "?ecdid=" . $ident . "&ecdm=" . $meta . "&" . $str_hidden, "view"); |
316 |
jonen |
1.1 |
return $item; |
317 |
|
|
} |
318 |
|
|
} |
319 |
|
|
|
320 |
|
|
} |
321 |
|
|
?> |