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