1 |
joko |
1.1 |
<?php |
2 |
|
|
// |
3 |
|
|
// $Id$ |
4 |
|
|
// Id: treeClass.php,v 1.1 2003/01/30 17:18:24 cain Exp |
5 |
|
|
// |
6 |
|
|
// $Log: treeClass.php,v $ |
7 |
|
|
// Revision 1.1 2003/01/30 17:18:24 cain |
8 |
|
|
// - moved all examples to docs |
9 |
|
|
// - and make them work properly |
10 |
|
|
// |
11 |
|
|
// Revision 1.1 2002/08/23 17:18:28 cain |
12 |
|
|
// - a good example to show how the tree works |
13 |
|
|
// |
14 |
|
|
// |
15 |
|
|
|
16 |
|
|
require_once('Tree/Memory.php'); |
17 |
|
|
|
18 |
|
|
|
19 |
|
|
class treeClass extends Tree_Memory |
20 |
|
|
{ |
21 |
|
|
|
22 |
|
|
function getPathAsString( $id ) |
23 |
|
|
{ |
24 |
|
|
return preg_replace('/Root\s-\s/','',parent::getPathAsString( $id , ' - ' )); |
25 |
|
|
} |
26 |
|
|
|
27 |
|
|
/** |
28 |
|
|
* just a wrapper to be compatible to vp_DB_Common |
29 |
|
|
* |
30 |
|
|
*/ |
31 |
|
|
function &getAll() |
32 |
|
|
{ |
33 |
|
|
return $this->getNode(); |
34 |
|
|
} |
35 |
|
|
|
36 |
|
|
/** |
37 |
|
|
* this is only for the getAllVisible it is called by the walk-method |
38 |
|
|
* to retreive only the nodes that shall be visible |
39 |
|
|
* |
40 |
|
|
* @param array this is the node to check |
41 |
|
|
* @return mixed an array if the node shall be visible |
42 |
|
|
* nothing if the node shall not be shown |
43 |
|
|
*/ |
44 |
|
|
function _walkForGettingVisibleFolders( $node ) |
45 |
|
|
{ |
46 |
|
|
global $session; |
47 |
|
|
|
48 |
|
|
if( $node['id']==$this->getRootId() ) |
49 |
|
|
return $node; |
50 |
|
|
|
51 |
|
|
$parentsIds = $this->getParentsIds($node['id']); |
52 |
|
|
if( !@$this->_unfoldAll ) |
53 |
|
|
{ |
54 |
|
|
foreach( $parentsIds as $aParentId ) |
55 |
|
|
{ |
56 |
|
|
if( !@$session->temp->openProjectFolders[$aParentId] && |
57 |
|
|
$aParentId!=$node['id']) // dont check the node itself, since we only look if the parents are openend, then this $node is shown! |
58 |
|
|
return false; |
59 |
|
|
} |
60 |
|
|
} |
61 |
|
|
else |
62 |
|
|
{ |
63 |
|
|
// if all folders shall be unfolded save the unfold-ids in the session |
64 |
|
|
$session->temp->openProjectFolders[$node['id']] = $node['id']; |
65 |
|
|
} |
66 |
|
|
return $node; |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
/** |
70 |
|
|
* this returns all the visible projects, the folders returned |
71 |
|
|
* are those which are unfolded, the explorer-like way |
72 |
|
|
* it also handles the 'unfold' parameter, which we simply might be given |
73 |
|
|
* so the unfold/fold works on every page that shows only visible folders |
74 |
|
|
* i think that is really cool :-) |
75 |
|
|
* |
76 |
|
|
* @return array only those folders which are visible |
77 |
|
|
*/ |
78 |
|
|
function getAllVisible() |
79 |
|
|
{ |
80 |
|
|
$this->unfoldHandler(); |
81 |
|
|
return $this->walk( array(&$this,'_walkForGettingVisibleFolders') , 0 , 'ifArray' ); |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
function unfoldHandler() |
85 |
|
|
{ |
86 |
|
|
global $session; |
87 |
|
|
|
88 |
|
|
if( @$_REQUEST['unfoldAll'] ) |
89 |
|
|
{ |
90 |
|
|
$this->_unfoldAll = true; |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
if( @$_REQUEST['unfold'] ) |
94 |
|
|
{ |
95 |
|
|
if( @$session->temp->openProjectFolders[$_REQUEST['unfold']] ) |
96 |
|
|
{ |
97 |
|
|
unset($session->temp->openProjectFolders[$_REQUEST['unfold']]); |
98 |
|
|
} |
99 |
|
|
else |
100 |
|
|
{ |
101 |
|
|
$session->temp->openProjectFolders[$_REQUEST['unfold']] = $_REQUEST['unfold']; |
102 |
|
|
} |
103 |
|
|
} |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
|
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
?> |