1 |
<? |
2 |
/* |
3 |
## ------------------------------------------------------------------------- |
4 |
## $Id: GenericGUIDataList.php,v 1.9 2003/04/11 00:44:46 joko Exp $ |
5 |
## ------------------------------------------------------------------------- |
6 |
## $Log: GenericGUIDataList.php,v $ |
7 |
## Revision 1.9 2003/04/11 00:44:46 joko |
8 |
## minor update: shortened seperators |
9 |
## |
10 |
## Revision 1.8 2003/04/09 07:54:42 joko |
11 |
## cleaned up decoding part |
12 |
## |
13 |
## Revision 1.7 2003/04/09 00:37:53 jonen |
14 |
## + added actionbar |
15 |
## + some changes according to request vars |
16 |
## |
17 |
## Revision 1.6 2003/04/08 17:48:31 jonen |
18 |
## + bugfix again |
19 |
## |
20 |
## Revision 1.5 2003/04/08 17:33:22 jonen |
21 |
## + fixed problems with hidden form fields(current base URL) at the 'simple search form' |
22 |
## |
23 |
## Revision 1.4 2003/04/06 01:41:07 jonen |
24 |
## - removed duplicated decode functions |
25 |
## |
26 |
## Revision 1.3 2003/04/04 21:26:06 joko |
27 |
## added comments regarding possible (future) refactoring using the Data::Lift-infrastructure |
28 |
## |
29 |
## Revision 1.2 2003/04/04 00:45:40 jonen |
30 |
## + reworked decode functions |
31 |
## |
32 |
## Revision 1.1 2003/03/27 01:17:31 jonen |
33 |
## + inital commit (was orginal 'ObjectList.inc) |
34 |
## |
35 |
## Revision 1.1 2003/03/20 04:17:28 jonen |
36 |
## + initial commit |
37 |
## |
38 |
## Revision 1.2 2003/03/02 04:32:22 cvsmax |
39 |
## + add decode_item functions |
40 |
## |
41 |
## Revision 1.1 2003/03/01 22:57:40 cvsmax |
42 |
## + inital commit |
43 |
## |
44 |
## ------------------------------------------------------------------------- |
45 |
*/ |
46 |
|
47 |
|
48 |
/** |
49 |
* Need to make sure we have the DefaultGUIDataList object |
50 |
*/ |
51 |
require_once($phphtmllib."/widgets/data_list/DefaultGUIDataList.inc"); |
52 |
|
53 |
|
54 |
class GenericGUIDataList extends DefaultGUIDataList { |
55 |
|
56 |
/** |
57 |
* Args needed for object list. |
58 |
* Current use: |
59 |
* - use some bits to create locator metadata (see below) |
60 |
* - use all options to propagate to an AdapterProxy (here: GenericDataSource) |
61 |
* as a query to receive a list of objects as response to a rpc-call. |
62 |
* Todo: glossary: ban "*list* of objects" - it's an object *set* !!! (see CPAN's Set::Object) |
63 |
* |
64 |
*/ |
65 |
var $_options = NULL; |
66 |
|
67 |
/** |
68 |
* Holds a list of hidden elements |
69 |
* |
70 |
*/ |
71 |
var $_hidden_elements = array(); |
72 |
|
73 |
|
74 |
/** |
75 |
* The constructor is used to pass in some additional |
76 |
* metadata informations as "options". |
77 |
* The "locator metadata hash" isn't passed in here |
78 |
* any more. Handling this one occours one level deeper |
79 |
* inside the "GenericDataSource" Proxy. |
80 |
* |
81 |
* It's still possible to set locator metadata directly by |
82 |
* using the optional key 'locator' inside your options hash. |
83 |
* This can be either a DataSource::Locator instance or a plain |
84 |
* hash. However - it gets merged to the master locator |
85 |
* created by GenericDataSource using 'array_join_merge'. |
86 |
* |
87 |
* @param old: LocatorMetadataHash array - layout: array( type => '', metadata => '', dsn => '' ) |
88 |
* @param old: Query array - layout: array( type => '', metadata => '', dsn => '' ) |
89 |
* |
90 |
* @param new: options array - layout: array( datasource_type => '', [locator => array()] ) |
91 |
* |
92 |
* |
93 |
*/ |
94 |
function GenericGUIDataList($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE, $options = array()) { |
95 |
if ($options) { $this->_options = $options; } |
96 |
|
97 |
// call parent constructor |
98 |
$parent = get_parent_class($this); |
99 |
$this->$parent($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE); |
100 |
} |
101 |
|
102 |
|
103 |
function get_data_source( ) { |
104 |
|
105 |
// finally: create phpHtmlLib source handle (XyzDataListSource) |
106 |
|
107 |
// V1: |
108 |
//$source = new GenericDataSource($this->_locator, $this->_options); |
109 |
//$this->set_data_source( &$source ); |
110 |
|
111 |
/* |
112 |
// V2: |
113 |
loadModule("DataSource::GenericDataSource"); |
114 |
$source = new DataSource_GenericDataSource($this->_locator, $this->_options); |
115 |
$this->set_data_source( &$source ); |
116 |
*/ |
117 |
|
118 |
// V3: |
119 |
/* |
120 |
$proxy = php::mkComponent('DataSource::GenericDataSource', $this->_locator, $this->_options); |
121 |
$source = &$proxy; |
122 |
$this->set_data_source( &$source ); |
123 |
*/ |
124 |
|
125 |
// V4: |
126 |
/* |
127 |
$proxy = php::mkComponent('DataSource::GenericDataSource', array( proxy => '', adapter => ''), $this->_options); |
128 |
$source = &$proxy; |
129 |
$this->set_data_source( &$source ); |
130 |
*/ |
131 |
|
132 |
// V5: |
133 |
//print "options: " . Dumper($this->_options); |
134 |
|
135 |
$initial_locator = php::mkComponent( 'DataSource::Locator', array( adapter_type => 'phpHtmlLib' ) ); |
136 |
//print "1st locator: " . Dumper($initial_locator); |
137 |
|
138 |
// OLD |
139 |
//$proxy = php::mkComponent('DataSource::Generic', $initial_locator, $this->_options); |
140 |
|
141 |
//print "Test Query:"; |
142 |
//print Dumper($this->_options['query']); |
143 |
$proxy = php::mkComponent('DataSource::Generic', $initial_locator, $this->_options['data_locator_meta']); |
144 |
|
145 |
// debug |
146 |
//print "Proxy: " . Dumper($proxy); |
147 |
|
148 |
// V1: |
149 |
//$source = &$proxy; |
150 |
|
151 |
// V2: |
152 |
//$source->make_adapter_transparent(); |
153 |
|
154 |
// V3: |
155 |
$source = $proxy->get_adapter(); |
156 |
|
157 |
// V4: |
158 |
//$source = $this->_datasource; |
159 |
|
160 |
//print "objectlist-source: " . Dumper($source); |
161 |
//exit; |
162 |
|
163 |
$this->set_data_source( &$source ); |
164 |
|
165 |
} |
166 |
|
167 |
function user_setup() { |
168 |
|
169 |
//return; |
170 |
|
171 |
$source = $this->_datasource; |
172 |
//if (!$source) { return; } |
173 |
|
174 |
//print Dumper($source); |
175 |
$headers = $source->get_header(); |
176 |
//print Dumper($headers); |
177 |
|
178 |
$this->set_title( $this->get_title() . ' - ' . $source->get_total_rows() . ' Einträge' ); |
179 |
|
180 |
foreach($headers as $val) { |
181 |
$this->add_header_item($val, "150", $val, SORTABLE, SEARCHABLE); |
182 |
} |
183 |
|
184 |
/* |
185 |
$this->add_header_item("Uid", "200", "uid", SORTABLE, SEARCHABLE); |
186 |
$this->add_header_item("Name", "200", "lastName", SORTABLE, SEARCHABLE, "center"); |
187 |
*/ |
188 |
} |
189 |
|
190 |
|
191 |
/** |
192 |
* This function ensures that the data we place |
193 |
* in a column is aligned according to what the |
194 |
* user wants. |
195 |
* |
196 |
* @param mixed - $obj - the data for the td. |
197 |
* @param string - $col_name - the name of the column header |
198 |
* for this row to render. |
199 |
* @param int - $odd_row - tells us if this cell lives in |
200 |
* an odd # row (for alternating row colors) |
201 |
* @param int - the column # we are working on. |
202 |
* @return TDtag object |
203 |
*/ |
204 |
function wrap_column_item($obj, $col_name) { |
205 |
|
206 |
//make sure its set to something. |
207 |
if ($obj == '') { |
208 |
$obj = " "; |
209 |
} |
210 |
|
211 |
// decode item / mungle item data? |
212 |
// TODO: use Data::Lift here!!! (like already done in YAA::JobList and YAA::JobDetails) |
213 |
elseif ($this->_options['decode']) { |
214 |
|
215 |
// Proposal using Data::Lift: (see YAA::JobList and YAA::JobDetails) |
216 |
// This class will get shorter and better to maintain! |
217 |
|
218 |
// Picture Data::Lift as a container component handling |
219 |
// *specific* en-/decoding stuff for your very core components. |
220 |
// This way we will have almost all "specific mungling code" at one place. nice thing! |
221 |
|
222 |
/* |
223 |
|
224 |
// 1. expr: string -> object (phpHtmlLib-object: 'html_a'-tag) |
225 |
// returns a phpHtmlLib object of class 'Xyz' containing a http-/html-link |
226 |
// pointing to a View of a different - linked/referenced - object (reference-interpolation) |
227 |
$this->lift1 = php::mkComponent('Data::Lift', $obj, array( metatype => 'expression' ) ); |
228 |
$obj = $this->lift1->to('phpHtmlLib::html_a'); |
229 |
|
230 |
// 2. data: hash -> object (phpHtmlLib-object: 'container'-object containing form) |
231 |
// returns a phpHtmlLib object of class 'Container' containing a html-form made up of |
232 |
// phpHtmlLib form-tags wrapping all attribute-value pairs of the data hash (object-edit) |
233 |
$this->lift2 = php::mkComponent('Data::Lift', $obj, array( metatype => 'item' ) ); |
234 |
$obj = $this->lift2->to('phpHtmlLib::form'); |
235 |
|
236 |
*/ |
237 |
|
238 |
$utils = php::mkComponent('WebExplorer::utils'); |
239 |
$hidden = $this->_hidden_elements; |
240 |
$options = $this->_options['decode_args']; |
241 |
|
242 |
// a) Iterate through the attributes of the item and replace each |
243 |
// value with an appropriate link object if it has a certain format. |
244 |
if ($utils->decode_item_expr($obj, $hidden, $options)) { |
245 |
|
246 |
// b) Otherwise: If item is an Array we will replace it with a selection form object. |
247 |
} else { |
248 |
$utils->decode_item_array($obj, $hidden, $options); |
249 |
} |
250 |
|
251 |
} |
252 |
|
253 |
//make sure we don't put a right border on the last |
254 |
//column we are working on. |
255 |
//$style = "padding-left: 3px;padding-right:3px;border-top: 1px solid #dddddd;"; |
256 |
|
257 |
|
258 |
if ($this->_columns[$col_name]["data_name"] == $this->orderby()) { |
259 |
$style = "background-color: #f4f4f4;"; |
260 |
} else { |
261 |
$style = "background-color: #ffffff;"; |
262 |
} |
263 |
|
264 |
$align = $this->_columns[$col_name]["align"]; |
265 |
$td = new TDtag(array("align" => $align, |
266 |
"style" => $style, |
267 |
"class" => "datalist_data_cell")); |
268 |
|
269 |
if (is_object($obj) && $obj->_tag == "td") { |
270 |
return $obj; |
271 |
} else { |
272 |
$td->add( $obj ); |
273 |
} |
274 |
return $td; |
275 |
} |
276 |
|
277 |
function add_hidden_element($label, $value) { |
278 |
$this->_hidden_elements[$label] = $value; |
279 |
} |
280 |
|
281 |
|
282 |
/** |
283 |
* This function builds the simple search TD |
284 |
* |
285 |
* @return ContainerWidget |
286 |
*/ |
287 |
function _build_simple_search_form() { |
288 |
|
289 |
//if there is only 1 item enabled for search |
290 |
//then the search looks simple. |
291 |
$fields = $this->_get_searchable_fields(); |
292 |
$cnt = count($fields); |
293 |
if ($cnt == 0) { |
294 |
return NULL; |
295 |
} |
296 |
|
297 |
$container = new ContainerWidget; |
298 |
|
299 |
// get current request vars and add them ad hidden items |
300 |
$url_vars = $this->_get_current_url_vars(); |
301 |
foreach($url_vars as $label => $value) { |
302 |
$container->push(form_hidden($label, $value)); |
303 |
} |
304 |
|
305 |
if ($cnt == 1) { |
306 |
//user only has 1 field to show. |
307 |
list($name, $field) = each($fields); |
308 |
$container->push("Find ".$name." "); |
309 |
} else { |
310 |
//user has many fields to show. |
311 |
$container->push("Find ", |
312 |
form_select($this->_vars["search_fieldVar"], $fields, $this->search_field())); |
313 |
} |
314 |
|
315 |
if ($this->get_simple_search_modifier()) { |
316 |
//the user wants the search modifier turned on. |
317 |
$container->push($this->_build_simple_search_modifier()); |
318 |
} |
319 |
|
320 |
$container->push(form_text($this->_vars["search_valueVar"], $this->search_value_filter($this->search_value()), "20", "100", array("style"=>"vertical-align:middle;")), |
321 |
form_submit($this->get_form_name(), "Search", array("style"=>"vertical-align:middle;"))); |
322 |
|
323 |
if ($this->is_advanced_search_enabled()) { |
324 |
$span = html_span(html_a("ass","Advanced Search", "title")); |
325 |
$container->push(" ", $span); |
326 |
} |
327 |
|
328 |
if ($cnt == 1) { |
329 |
$container->push(form_hidden($this->_vars["search_fieldVar"], $field)); |
330 |
} |
331 |
|
332 |
|
333 |
//$container->push(form_close() ); |
334 |
return $container; |
335 |
} |
336 |
|
337 |
|
338 |
/** |
339 |
* this is the method that builds |
340 |
* the contents for the middle actionbar |
341 |
* td cell. |
342 |
* |
343 |
* @return ContainerWidget object |
344 |
*/ |
345 |
function actionbar_cell() { |
346 |
$action_list = $this->_options['actionbar']['list']; |
347 |
$action_name = $this->_options['actionbar']['name']; |
348 |
|
349 |
if($action_name && is_array($action_list)) { |
350 |
$action_form = container("Select action", _HTML_SPACE, |
351 |
form_select($action_name, $action_list), |
352 |
form_submit("ok","OK" ) |
353 |
); |
354 |
return $action_form; |
355 |
} else { |
356 |
return _HTML_SPACE; |
357 |
} |
358 |
} |
359 |
|
360 |
|
361 |
/* |
362 |
* this method returns the current requested variables |
363 |
* |
364 |
* @return array |
365 |
*/ |
366 |
function _get_current_url_vars() { |
367 |
$cur_url_vars = array(); |
368 |
|
369 |
// get new LinkBuilder instance |
370 |
$linkbuilder = new LinkBuilder(); |
371 |
|
372 |
$url_vars = php::array_join_merge($_GET, $_POST); |
373 |
if(is_array($url_vars)) { |
374 |
foreach($url_vars as $key => $value) { |
375 |
// if there is an LinkBuilder guid instead of variables, encode it |
376 |
if($key == 'lbid') { |
377 |
$lb_vars = $linkbuilder->load($value); |
378 |
foreach($lb_vars as $lbkey => $lbval) { |
379 |
$cur_url_vars[$lbkey] = $lbval; |
380 |
} |
381 |
} else { |
382 |
$cur_url_vars[$key] = $value; |
383 |
} |
384 |
} |
385 |
} |
386 |
return $cur_url_vars; |
387 |
} |
388 |
|
389 |
} |
390 |
?> |