/[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.6 - (show annotations)
Tue Apr 8 17:48:31 2003 UTC (21 years, 5 months ago) by jonen
Branch: MAIN
Changes since 1.5: +9 -4 lines
+ bugfix again

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

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