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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Tue Apr 8 17:33:22 2003 UTC (21 years, 5 months ago) by jonen
Branch: MAIN
Changes since 1.4: +64 -1 lines
+ fixed problems with hidden form fields(current base URL) at the 'simple search form'

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

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