/[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.1 - (hide annotations)
Sat Apr 19 16:12:23 2003 UTC (21 years, 5 months ago) by jonen
Branch: MAIN
initial commit

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

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