1 |
<?php |
2 |
|
3 |
/** |
4 |
* $Id: utils.php,v 1.6 2003/05/10 18:17:19 jonen Exp $ |
5 |
* |
6 |
* $Log: utils.php,v $ |
7 |
* Revision 1.6 2003/05/10 18:17:19 jonen |
8 |
* + added 'create/add new' links |
9 |
* |
10 |
* Revision 1.5 2003/04/18 13:38:40 jonen |
11 |
* + added use of url::short function at 'decode_item_expr' |
12 |
* |
13 |
* Revision 1.4 2003/04/16 16:22:01 joko |
14 |
* + introduced url::short |
15 |
* |
16 |
* Revision 1.3 2003/04/09 07:57:15 joko |
17 |
* revamped 'function decode_item_expr' |
18 |
* introduced shortcut 'link::store' |
19 |
* |
20 |
* Revision 1.2 2003/04/09 00:32:42 jonen |
21 |
* some tests according to form rendering at the decode functions |
22 |
* |
23 |
* Revision 1.1 2003/04/06 01:28:04 jonen |
24 |
* + initial commit |
25 |
* + moved decode functions here |
26 |
* + reworked decode functions to use new LinkBuilder class |
27 |
* |
28 |
* |
29 |
* |
30 |
*/ |
31 |
|
32 |
/** |
33 |
* Container holds most helper functions are used at the WebExplorer itself |
34 |
* or at its components, e.g. decode functions used at the GUI modules. |
35 |
* |
36 |
* |
37 |
* @author Sebastian Utz <seut@tunemedia.de> |
38 |
* @package org.netfrag.app |
39 |
* @name WebExplorer::utils |
40 |
* |
41 |
*/ |
42 |
|
43 |
|
44 |
class WebExplorer_utils { |
45 |
|
46 |
|
47 |
|
48 |
// TODO: refactor to Data::Lift - subcomponent: handling will get way more easy! |
49 |
function decode_item_array(&$item, $hidden_elements, $options) { |
50 |
//$options = $this->_options['decode_args']; |
51 |
//print "item: " . Dumper($item); |
52 |
//print "options: " . Dumper($options); |
53 |
if( is_array($item) ) { |
54 |
//$cur_row_index = $this->_datasource->get_cur_data_index(); |
55 |
//$parent_guid = $this->_datasource->_data[$cur_row_index]['guid']; |
56 |
// build list for selection form |
57 |
if($options['form']) { |
58 |
foreach($item as $key => $value) { |
59 |
$link_meta = php::untwingle_reference($value, $options); |
60 |
$link_vars = array( |
61 |
'ecdid' => $link_meta[ident], |
62 |
'ecdm' => $link_meta[type] |
63 |
); |
64 |
|
65 |
foreach($hidden_elements as $label => $value) { |
66 |
$link_vars[$label] = $value; |
67 |
} |
68 |
|
69 |
// V1 - create new LinkBuilder instance and get link GUID by saving vars |
70 |
$link_guid = link::store($link_vars); |
71 |
|
72 |
// V2 - more flexible - adjustable link shrinking via some constant defined elsewhere |
73 |
//$link_guid = url::short('', $link_vars); |
74 |
|
75 |
$list[$key] = $link_guid; |
76 |
} |
77 |
if(is_array($list) ) { |
78 |
$container = container( |
79 |
//form_open( $item[0], $_SERVER['PHP_SELF'], "POST" ), |
80 |
form_select("lbid", $list), |
81 |
form_submit("submit","view" ) |
82 |
); |
83 |
//$container->add(form_close() ); |
84 |
$item = $container; |
85 |
} |
86 |
} else { |
87 |
//print "<b>2</b><br/>"; |
88 |
$container = container(); |
89 |
|
90 |
// add default 'add new' link |
91 |
$link_vars_create = array( |
92 |
'ecdid' => $options[label], |
93 |
'ecdm' => $options[parent_guid], |
94 |
'ecdmx' => $options[parent_class], |
95 |
'ecmod' => "create", |
96 |
'ecat' => 'item' |
97 |
); |
98 |
foreach($hidden_elements as $label => $value) { |
99 |
if(!$link_vars_create[$label]) { |
100 |
$link_vars_create[$label] = $value; |
101 |
} |
102 |
} |
103 |
$url_short = url::short($_SERVER["PHP_SELF"], $link_vars_create); |
104 |
$container->add(_HTML_SPACE, html_a( $url_short, $key . " add new"), html_br()); |
105 |
|
106 |
if(count($item) != 0) { |
107 |
foreach($item as $key => $value) { |
108 |
$link_meta = php::untwingle_reference($value, $options); |
109 |
$link_vars = array( |
110 |
'ecdid' => $link_meta[ident], |
111 |
'ecdm' => $link_meta[type], |
112 |
'ecat' => 'item' |
113 |
); |
114 |
|
115 |
foreach($hidden_elements as $label => $value) { |
116 |
if(!$link_vars[$label]) { |
117 |
$link_vars[$label] = $value; |
118 |
} |
119 |
//$tmp_array[] = $label . "=" . $value; |
120 |
} |
121 |
|
122 |
//$str_hidden = join("&", $tmp_array); |
123 |
//$container->add("->", html_a($_SERVER["PHP_SELF"] . "?ecdid=" . $ident . "&ecdm=" . $meta . "&" . $str_hidden, $key . " view"), html_br()); |
124 |
|
125 |
// V1 - create new LinkBuilder instance and get link GUID by saving vars |
126 |
//$link_guid = link::store($link_vars); |
127 |
//$container->add("->", html_a($_SERVER["PHP_SELF"] . "?lbid=" . $link_guid, $key . " view"), html_br()); |
128 |
|
129 |
// V2 - more flexible - adjustable link shrinking via some constant defined elsewhere |
130 |
$url_short = url::short($_SERVER["PHP_SELF"], $link_vars); |
131 |
$container->add( _HTML_SPACE, html_a( $url_short, $key . " - " . " view"), html_br()); |
132 |
|
133 |
} |
134 |
} |
135 |
$item = $container; |
136 |
} |
137 |
//return $item; |
138 |
return 1; |
139 |
} |
140 |
} |
141 |
|
142 |
// decodes serialized string representations of object-references |
143 |
// TODO: refactor to Data::Lift - subcomponent: handling will get way more easy! |
144 |
function decode_item_expr(&$item, $hidden_elements, $options) { |
145 |
|
146 |
//return; |
147 |
|
148 |
// debug |
149 |
//$options = $this->_options['decode_args']; |
150 |
//print "item: $item<br/>"; |
151 |
|
152 |
if($item == "_REF") { |
153 |
$link_vars_create = array( |
154 |
'ecdid' => $options[label], |
155 |
'ecdm' => $options[parent_guid], |
156 |
'ecdmx' => $options[parent_class], |
157 |
'ecmod' => "create", |
158 |
'ecat' => 'item' |
159 |
); |
160 |
foreach($hidden_elements as $label => $value) { |
161 |
if(!$link_vars_create[$label]) { |
162 |
$link_vars_create[$label] = $value; |
163 |
} |
164 |
} |
165 |
$url_short = url::short($_SERVER["PHP_SELF"], $link_vars_create); |
166 |
$item = html_a( $url_short, " create"); |
167 |
} else { |
168 |
// resolve 'o_{guid}_{classname}' - encoded string |
169 |
$link_meta = php::untwingle_reference($item); |
170 |
//print Dumper($link_meta); |
171 |
|
172 |
if (!is_array($link_meta)) { |
173 |
//return $item; |
174 |
//print "NO<br/>"; |
175 |
return; |
176 |
} |
177 |
|
178 |
$link_vars = array( |
179 |
'ecdid' => $link_meta[ident], |
180 |
'ecdm' => $link_meta[type], |
181 |
'ecat' => 'item' |
182 |
); |
183 |
|
184 |
foreach($hidden_elements as $label => $value) { |
185 |
if(!$link_vars[$label]) { |
186 |
$link_vars[$label] = $value; |
187 |
} |
188 |
} |
189 |
|
190 |
// V1 |
191 |
//$str_hidden = join("&", $tmp_array); |
192 |
//$item = html_a($_SERVER["PHP_SELF"] . "?ecdid=" . $ident . "&ecdm=" . $meta . "&" . $str_hidden, "view"); |
193 |
|
194 |
// V2 |
195 |
//$link_guid = link::store($link_vars); |
196 |
//$item = html_a($_SERVER["PHP_SELF"] . "?lbid=" . $link_guid, "view"); |
197 |
|
198 |
// V3 - more flexible - adjustable link shrinking via some constant defined elsewhere |
199 |
$url_short = url::short($_SERVER["PHP_SELF"], $link_vars); |
200 |
$item = html_a( $url_short, " view"); |
201 |
} |
202 |
|
203 |
return 1; |
204 |
} |
205 |
|
206 |
|
207 |
|
208 |
} |
209 |
|
210 |
|
211 |
?> |