/[cvs]/nfo/php/libs/org.netfrag.patches/phphtmllib/widgets/GenericGUIDataList.php
ViewVC logotype

Contents of /nfo/php/libs/org.netfrag.patches/phphtmllib/widgets/GenericGUIDataList.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.9 - (show annotations)
Fri Apr 11 00:44:46 2003 UTC (21 years, 5 months ago) by joko
Branch: MAIN
Changes since 1.8: +8 -5 lines
minor update: shortened seperators

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

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed