/[cvs]/nfo/php/libs/org.netfrag.glib/Data/Lift/hash/topic/ExplorerTree.php
ViewVC logotype

Annotation of /nfo/php/libs/org.netfrag.glib/Data/Lift/hash/topic/ExplorerTree.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Sat Apr 19 16:34:37 2003 UTC (21 years, 5 months ago) by jonen
Branch: MAIN
Changes since 1.1: +6 -3 lines
removed dumper

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

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