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