1 |
jonen |
1.1 |
<? |
2 |
|
|
/** |
3 |
|
|
* This file contains a Data::Lift actor component. |
4 |
|
|
* |
5 |
|
|
* @author Andreas Motl <andreas.motl@ilo.de> |
6 |
|
|
* @package org.netfrag.glib |
7 |
|
|
* @name Data::Lift::hash::topic::Tree |
8 |
|
|
* |
9 |
|
|
*/ |
10 |
|
|
|
11 |
|
|
/** |
12 |
|
|
* Cvs-Log: |
13 |
|
|
* |
14 |
joko |
1.3 |
* $Id: ExplorerTree.php,v 1.2 2003/04/19 16:34:37 jonen Exp $ |
15 |
jonen |
1.2 |
* |
16 |
|
|
* $Log: ExplorerTree.php,v $ |
17 |
joko |
1.3 |
* Revision 1.2 2003/04/19 16:34:37 jonen |
18 |
|
|
* removed dumper |
19 |
|
|
* |
20 |
jonen |
1.2 |
* Revision 1.1 2003/04/19 16:12:23 jonen |
21 |
|
|
* initial commit |
22 |
jonen |
1.1 |
* |
23 |
|
|
* Revision 1.1 2003/04/18 15:49:52 joko |
24 |
|
|
* initial commit |
25 |
|
|
* |
26 |
|
|
* |
27 |
|
|
*/ |
28 |
|
|
|
29 |
|
|
/** |
30 |
|
|
* Data::Lift::hash::topic::ExplorerTree |
31 |
|
|
* |
32 |
|
|
* |
33 |
|
|
* @author Andreas Motl <andreas.motl@ilo.de> |
34 |
|
|
* @copyright (c) 2003 - All Rights reserved. |
35 |
|
|
* @license GNU LGPL (GNU Lesser General Public License) |
36 |
|
|
* |
37 |
|
|
* @link http://www.netfrag.org/~joko/ |
38 |
|
|
* @link http://www.gnu.org/licenses/lgpl.txt |
39 |
|
|
* |
40 |
|
|
* @package org.netfrag.glib |
41 |
|
|
* @subpackage DataLift |
42 |
|
|
* @name Data::Lift::hash::topic::Tree |
43 |
|
|
* |
44 |
|
|
* @link http://cvs.netfrag.org/php/libs/org.netfrag.glib |
45 |
|
|
* |
46 |
|
|
*/ |
47 |
|
|
class Data_Lift_hash_topic_ExplorerTree { |
48 |
|
|
|
49 |
|
|
|
50 |
|
|
function transform($source, $atnode = null) { |
51 |
|
|
|
52 |
|
|
$buffer = array(); |
53 |
|
|
|
54 |
|
|
//foreach ($source as $key => $val) { |
55 |
|
|
foreach ($source as $key => $val) { |
56 |
|
|
//print "Key=$key, Val=$val<br/>"; |
57 |
|
|
$node = $this->mkNode($key, $val); |
58 |
|
|
//$node = $this->mkNode($val, $key); |
59 |
|
|
array_push($buffer, $node); |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
//print Dumper($container); |
63 |
|
|
return $buffer; |
64 |
|
|
|
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
function mkNode($name, $payload = null) { |
68 |
|
|
|
69 |
|
|
static $level; |
70 |
|
|
static $anchor; |
71 |
|
|
|
72 |
|
|
if(!is_array($payload) && $payload) { $name = $payload; } |
73 |
|
|
|
74 |
|
|
if (!is_array($anchor)) { $anchor = array(); } |
75 |
|
|
|
76 |
|
|
// TODO: propagate to this place inside some argument container |
77 |
|
|
// (make adjustable from View) |
78 |
|
|
$level_max = 3; |
79 |
|
|
//print "level: $level<br/>"; |
80 |
|
|
|
81 |
|
|
// build url to single node |
82 |
|
|
//$url = linkargs::topic($name); |
83 |
|
|
|
84 |
|
|
// FIXME: HACK !!! |
85 |
|
|
// Do we already have a Nirvana-API for such things? |
86 |
|
|
// Propagating this through the lift seems impossible... |
87 |
|
|
//$parent_identifier = $_GET[ecdid]; |
88 |
|
|
|
89 |
|
|
|
90 |
|
|
/* |
91 |
|
|
$main_buf = array(); |
92 |
|
|
//for ($i = 0; $i < $level - 1; $i++) { |
93 |
|
|
for ($i = 0; $i <= 2; $i++) { |
94 |
|
|
if (!$anchor[$i]) { continue; } |
95 |
|
|
array_push($main_buf, $anchor[$i]); |
96 |
|
|
} |
97 |
|
|
$main = join('.', $main_buf); |
98 |
|
|
|
99 |
|
|
//$filter = join('.', $anchor); |
100 |
|
|
// FIXME: this is limited to three levels only |
101 |
|
|
//$appendix = $anchor[2] ? (':' . join('.', array( $anchor[2], $anchor[3] ))) : ''; |
102 |
|
|
$appendix = ''; |
103 |
|
|
$appendix_buf = array(); |
104 |
|
|
for ($i = 2; $i <= sizeof($anchor); $i++) { |
105 |
|
|
//for ($i = $level - 1; $i <= sizeof($anchor); $i++) { |
106 |
|
|
if (!$anchor[$i]) { continue; } |
107 |
|
|
array_push($appendix_buf, $anchor[$i]); |
108 |
|
|
} |
109 |
|
|
if ($appendix_buf) { |
110 |
|
|
$appendix = ':' . join('.', $appendix_buf); |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
//$filter = join('.', array( $anchor[0], $anchor[1] )) . $appendix; |
114 |
|
|
$filter = $main . $appendix; |
115 |
|
|
*/ |
116 |
|
|
|
117 |
|
|
$buf = array(); |
118 |
|
|
for ($i = 0; $i <= $level; $i = $i + 3) { |
119 |
|
|
$part = array(); |
120 |
|
|
for ($j = $i; $j <= $i + 3; $j++) { |
121 |
|
|
if (!$anchor[$j]) { continue; } |
122 |
|
|
array_push($part, $anchor[$j]); |
123 |
|
|
//get parent ident |
124 |
|
|
$parent_identifier = $anchor[$j]; |
125 |
|
|
} |
126 |
|
|
array_push($buf, join('.', $part)); |
127 |
|
|
} |
128 |
|
|
$filter = join(':', $buf); |
129 |
|
|
|
130 |
|
|
// build propare link arguments to refer to a node as item to let it become editable |
131 |
|
|
//$link_args = array( ecat => 'item', ecdm => $parent_identifier, ecdf => $filter ); |
132 |
|
|
|
133 |
|
|
$link_args = $this->_link_args['list']; |
134 |
|
|
if($parent_identifier) { $link_args['ecdm'] = $parent_identifier; } |
135 |
|
|
//print $parent_identifier . "<br>"; |
136 |
|
|
|
137 |
|
|
// The identfier (by now the filename) transitions to a meta-argument here |
138 |
|
|
// to make room for the sub-nodename becoming the identifier. ($name!) |
139 |
|
|
$url = url::viewdatanode($name, $link_args); |
140 |
|
|
|
141 |
|
|
// vivify single node |
142 |
joko |
1.3 |
$node = array( name => $name, link => $url ); |
143 |
jonen |
1.1 |
|
144 |
|
|
if (is_array($payload)) { |
145 |
|
|
// count the tree-level |
146 |
|
|
$level++; |
147 |
|
|
array_push($anchor, $name); |
148 |
|
|
if ($level <= $level_max) { |
149 |
|
|
$cnode = $this->transform($payload); |
150 |
|
|
//array_push($buffer, $cnode); |
151 |
|
|
//array_push($buffer, $this->mkContainer(array())); |
152 |
|
|
$node = $this->mkContainer($cnode, $node); |
153 |
|
|
} |
154 |
|
|
$level--; |
155 |
|
|
array_pop($anchor); |
156 |
|
|
} else { |
157 |
|
|
// TODO: !! |
158 |
|
|
$node[attributes][alt] = $name; |
159 |
|
|
} |
160 |
|
|
|
161 |
|
|
return $node; |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
function mkContainer($data = array(), $parent = null) { |
165 |
|
|
|
166 |
|
|
// autocreate parent if undef |
167 |
|
|
if (!$parent) { $parent = $this->mkNode('dummy'); } |
168 |
|
|
|
169 |
|
|
// sort keys of children alphabetically |
170 |
|
|
// TODO: add behavior to this |
171 |
|
|
asort($data); |
172 |
|
|
|
173 |
|
|
// vivify list of children |
174 |
|
|
$node = array( |
175 |
|
|
'children' => $data, |
176 |
|
|
); |
177 |
|
|
// merge them together and return result |
178 |
|
|
$result = php::array_join_merge($parent, $node); |
179 |
|
|
return $result; |
180 |
|
|
} |
181 |
|
|
|
182 |
joko |
1.3 |
function perform(&$data) { |
183 |
|
|
|
184 |
|
|
// new of 2003-05-13: link_args no propagated to this place from generic (already in-place) options-container |
185 |
|
|
//print Dumper($this->_options); |
186 |
|
|
$link_args = $this->_options[link_args]; |
187 |
jonen |
1.1 |
|
188 |
|
|
//print "Link Vars: " . Dumper($link_args); |
189 |
|
|
$this->_link_args = $link_args; |
190 |
joko |
1.3 |
|
191 |
jonen |
1.2 |
//print Dumper($data); |
192 |
jonen |
1.1 |
|
193 |
|
|
//array_multisort($data); |
194 |
|
|
//asort($data); |
195 |
|
|
|
196 |
|
|
// V1 |
197 |
|
|
$data = $this->transform($data); |
198 |
|
|
//$data = $this->mkContainer( $data, $this->mkNode('root') ); |
199 |
|
|
$data = $this->mkContainer( $data, $this->mkNode($link_args['t'])); |
200 |
|
|
|
201 |
|
|
// V2 |
202 |
|
|
//$data = $this->mkNode('root', $data); |
203 |
|
|
|
204 |
|
|
return $data; |
205 |
|
|
|
206 |
|
|
} |
207 |
|
|
|
208 |
|
|
} |
209 |
|
|
|
210 |
|
|
?> |