/[cvs]/nfo/php/libs/com.newsblob.phphtmllib/widgets/data_list/GenericGUIDataList.inc
ViewVC logotype

Annotation of /nfo/php/libs/com.newsblob.phphtmllib/widgets/data_list/GenericGUIDataList.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Thu Mar 20 04:17:28 2003 UTC (21 years, 6 months ago) by jonen
Branch: MAIN
+ initial commit

1 jonen 1.1 <?
2     /*
3     ## -----------------------------------------------------------------------------
4     ## $Id: GenericGUIDataList.inc,v 1.2 2003/03/02 04:32:22 cvsmax Exp $
5     ## -----------------------------------------------------------------------------
6     ## $Log: GenericGUIDataList.inc,v $
7     ## Revision 1.2 2003/03/02 04:32:22 cvsmax
8     ## + add decode_item functions
9     ##
10     ## Revision 1.1 2003/03/01 22:57:40 cvsmax
11     ## + inital commit
12     ##
13     ##
14     ## -----------------------------------------------------------------------------
15     */
16    
17     /**
18     * Need to make sure we have the DefaultGUIDataList object
19     */
20     require_once($phphtmllib."/widgets/data_list/DefaultGUIDataList.inc");
21    
22    
23     class GenericGUIDataList extends DefaultGUIDataList {
24    
25     /**
26     * Args needed for object list.
27     * Current use:
28     * - use some bits to create locator metadata (see below)
29     * - use all options to propagate to an AdapterProxy (here: GenericDataSource)
30     * as a query to receive a list of objects as response to a rpc-call.
31     * Todo: glossary: ban "*list* of objects" - it's an object *set* !!! (see CPAN's Set::Object)
32     *
33     */
34     var $_options = NULL;
35    
36     /**
37     * The constructor is used to pass in some additional
38     * metadata informations as "options".
39     * The "locator metadata hash" isn't passed in here
40     * any more. Handling this one occours one level deeper
41     * inside the "GenericDataSource" Proxy.
42     *
43     * It's still possible to set locator metadata directly by
44     * using the optional key 'locator' inside your options hash.
45     * This can be either a DataSource::Locator instance or a plain
46     * hash. However - it gets merged to the master locator
47     * created by GenericDataSource using 'array_join_merge'.
48     *
49     * @param old: LocatorMetadataHash array - layout: array( type => '', metadata => '', dsn => '' )
50     * @param old: Query array - layout: array( type => '', metadata => '', dsn => '' )
51     *
52     * @param new: options array - layout: array( datasource_type => '', [locator => array()] )
53     *
54     *
55     */
56     function GenericGUIDataList($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE, $options = array()) {
57     if ($options) { $this->_options = $options; }
58     $parent = get_parent_class($this);
59     $this->$parent($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE);
60     }
61    
62     function get_data_source( ) {
63    
64     // finally: create phpHtmlLib source handle (XyzDataListSource)
65    
66     // V1:
67     //$source = new GenericDataSource($this->_locator, $this->_options);
68     //$this->set_data_source( &$source );
69    
70     /*
71     // V2:
72     loadModule("DataSource::GenericDataSource");
73     $source = new DataSource_GenericDataSource($this->_locator, $this->_options);
74     $this->set_data_source( &$source );
75     */
76    
77     // V3:
78     /*
79     $proxy = php::mkComponent('DataSource::GenericDataSource', $this->_locator, $this->_options);
80     $source = &$proxy;
81     $this->set_data_source( &$source );
82     */
83    
84     // V4:
85     /*
86     $proxy = php::mkComponent('DataSource::GenericDataSource', array( proxy => '', adapter => ''), $this->_options);
87     $source = &$proxy;
88     $this->set_data_source( &$source );
89     */
90    
91     // V5:
92     //print "options: " . Dumper($this->_options);
93    
94     $initial_locator = php::mkComponent( 'DataSource::Locator', array( adapter_type => 'phpHtmlLib' ) );
95     //print "1st locator: " . Dumper($initial_locator);
96    
97     // OLD
98     //$proxy = php::mkComponent('DataSource::Generic', $initial_locator, $this->_options);
99    
100     //print "Test Query:";
101     //print Dumper($this->_options['query']);
102     $proxy = php::mkComponent('DataSource::Generic', $initial_locator, $this->_options['data_locator_meta']);
103    
104     // debug
105     //print "Proxy: " . Dumper($proxy);
106    
107     // V1:
108     //$source = &$proxy;
109    
110     // V2:
111     //$source->make_adapter_transparent();
112    
113     // V3:
114     $source = $proxy->get_adapter();
115    
116     // V4:
117     //$source = $this->_datasource;
118    
119     //print "objectlist-source: " . Dumper($source);
120     //exit;
121    
122     $this->set_data_source( &$source );
123    
124     }
125    
126     function user_setup() {
127    
128     //return;
129    
130     $source = $this->_datasource;
131     //if (!$source) { return; }
132    
133     //print Dumper($source);
134     $headers = $source->get_header();
135     //print Dumper($headers);
136    
137     $this->set_title( $this->get_title() . ' - ' . $source->get_total_rows() . ' Eintrรคge' );
138    
139     foreach($headers as $val) {
140     $this->add_header_item($val, "150", $val, SORTABLE, SEARCHABLE);
141     }
142    
143     /*
144     $this->add_header_item("Uid", "200", "uid", SORTABLE, SEARCHABLE);
145     $this->add_header_item("Name", "200", "lastName", SORTABLE, SEARCHABLE, "center");
146     */
147     }
148    
149    
150     /**
151     * This function ensures that the data we place
152     * in a column is aligned according to what the
153     * user wants.
154     *
155     * @param mixed - $obj - the data for the td.
156     * @param string - $col_name - the name of the column header
157     * for this row to render.
158     * @param int - $odd_row - tells us if this cell lives in
159     * an odd # row (for alternating row colors)
160     * @param int - the column # we are working on.
161     * @return TDtag object
162     */
163     function wrap_column_item($obj, $col_name) {
164    
165     //make sure its set to something.
166     if ($obj == '') {
167     $obj = "&nbsp;";
168     }
169     // if item is match by expression we will replace it with an link object
170     elseif($this->_options['decode']) {
171     if($this->decode_item_expr($obj)) {
172     $obj = $this->decode_item_expr($obj);
173     }
174     // if item is an Array we will replace it with an selection form object
175     elseif($this->decode_item_array($obj) ) {
176     $obj = $this->decode_item_array($obj);
177     }
178     }
179    
180     //make sure we don't put a right border on the last
181     //column we are working on.
182     //$style = "padding-left: 3px;padding-right:3px;border-top: 1px solid #dddddd;";
183    
184    
185     if ($this->_columns[$col_name]["data_name"] == $this->orderby()) {
186     $style = "background-color: #f4f4f4;";
187     } else {
188     $style = "background-color: #ffffff;";
189     }
190    
191     $align = $this->_columns[$col_name]["align"];
192     $td = new TDtag(array("align" => $align,
193     "style" => $style,
194     "class" => "datalist_data_cell"));
195    
196     if (is_object($obj) && $obj->_tag == "td") {
197     return $obj;
198     } else {
199     $td->add( $obj );
200     }
201     return $td;
202     }
203    
204     function decode_item_array($item) {
205     $options = $this->_options['decode_args'];
206     if( is_array($item) ) {
207     //$cur_row_index = $this->_datasource->get_cur_data_index();
208     //$parent_guid = $this->_datasource->_data[$cur_row_index]['guid'];
209     // build list for selection form
210     if($options['form']) {
211     foreach($item as $key => $value) {
212     $tmp = split($options['seperator'], $value);
213     $ident = $tmp['1'];
214     $meta = $tmp['2'];
215     $list[$key] = $ident;
216     }
217     if(is_array($list) ) {
218     $container = container(
219     form_open( $item[0], $_SERVER["PHP_SELF"], "POST" ),
220     form_open("ecdm", $meta),
221     form_select("ecdid", $list),
222     form_submit("submit","view" ),
223     form_close()
224     );
225     foreach($this->_hidden_items as $label => $value) {
226     $container->add(form_hidden($label, $value));
227     }
228     $item = $container;
229     }
230     } else {
231     $container = container();
232     foreach($item as $key => $value) {
233     $tmp = split($options['seperator'], $value);
234     $ident = $tmp['1'];
235     $meta = $tmp['2'];
236     foreach($this->_hidden_items as $label => $value) {
237     $tmp_array[] = $label . "=" . $value;
238     }
239     $str_hidden = join("&", $tmp_array);
240     $container->add("->", html_a($_SERVER["PHP_SELF"] . "?ecdid=" . $ident . "&ecdm=" . $meta . $str_hidden, $key . " view"), html_br());
241     }
242     $item = $container;
243     }
244     return $item;
245     }
246     }
247    
248     function decode_item_expr($item) {
249     $options = $this->_options['decode_args'];
250     if(substr($item, 0, 2) == "o_") {
251     $tmp = split($options['seperator'], $item);
252     $ident = $tmp['1'];
253     $meta = $tmp['2'];
254     foreach($this->_hidden_items as $label => $value) {
255     $tmp_array[] = $label . "=" . $value;
256     }
257     $str_hidden = join("&", $tmp_array);
258     $item = html_a($_SERVER["PHP_SELF"] . "?ecdid=" . $guid . "&ecdm=" . $meta . $str_hidden, "view");
259     return $item;
260     }
261     }
262    
263     }
264     ?>

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