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