/[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.7 - (show annotations)
Wed Apr 9 00:37:53 2003 UTC (21 years, 5 months ago) by jonen
Branch: MAIN
Changes since 1.6: +73 -17 lines
+ added actionbar
+ some changes according to request vars

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

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