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