cvs: pear /Tree/examples/TreeEditor_MemoryNested closedFolder.gif copy.gif cut.gif delete.gif folder.gif index.php index.tpl mysql_db.sql
openFolder.gif paste.gif treeClass.php
| From: | Wolfram Kriesing | Date: | Fri, 23 Aug 2002 17:18:28 +0000 |
| Subject: | cvs: pear /Tree/examples/TreeEditor_MemoryNested closedFolder.gif copy.gif cut.gif delete.gif folder.gif index.php index.tpl mysql_db.sql openFolder.gif paste.gif treeClass.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-5911@lists.php.net to get a copy of this message | ||
cain Fri Aug 23 13:18:28 2002 EDT
Added files:
/pear/Tree/examples/TreeEditor_MemoryNested closedFolder.gif
copy.gif cut.gif
delete.gif folder.gif
index.php index.tpl
mysql_db.sql
openFolder.gif
paste.gif treeClass.php
Log:
- a good example to show how the tree works
Index: pear/Tree/examples/TreeEditor_MemoryNested/index.php +++ pear/Tree/examples/TreeEditor_MemoryNested/index.php <?php // // $Id: index.php,v 1.1 2002/08/23 17:18:28 cain Exp $ // ################################################## # # init template engine # if( strpos($HTTP_HOST,'ashley') !== false ) // sorry but my template class is there :-) ini_set('include_path',ini_get('include_path').':/usr/local/httpd/includes'); // you need the template class from http://sf.net/projects/simpltpl if( !@include('SimpleTemplate/Engine.php') ) { print 'sorry, you need the template class from <a href="http://sf.net/projects/simpltpl">sourceforge</a> for this.<br>'. 'or if i have time i put the examples <a href="http://wolfram.kriesing.de/programming/">here online</a>'; die(); } require_once('SimpleTemplate/Filter/TagLib.php'); $options = array( 'templateDir' => dirname(__FILE__) ); $tpl = new SimpleTemplate_Engine($options); require_once('SimpleTemplate/Filter/Modifier.php'); $modifiers = new SimpleTemplate_Filter_Modifier($tpl->options); $tpl->registerPrefilter(array(&$modifiers,'imgSrc'),array(dirname(__FILE__),'http://'.$HTTP_HOST.dirname($PHP_SELF))); ################################################## # # actual tree stuff, using Dynamic_DBnested # define('TABLE_TREE','TreeEditor_MemoryNested'); define('DB_DSN','mysql://root@localhost/test'); require_once('treeClass.php'); $options = array( 'table' => TABLE_TREE , 'order' => 'name'); $tree = new treeClass( 'DBnested' , DB_DSN , $options ); # to let it work on the filesystem :-) # $options = array( 'order' => 'name'); # $tree = new treeClass( 'Filesystem' , '/home/wk/tmp' , $options ); $tree->setup(); $tree->setRemoveRecursively(); session_start(); if(!session_is_registered('session')) { $session = new stdClass; // standard PHP-class constructor session_register('session'); $session->data = array(); } else // since the class is read from the session it is not automatically made global { $session = &$_SESSION['session']; } // detect action if( $_REQUEST['action_copy'] || $_REQUEST['action_copy_x'] || $_REQUEST['action_cut'] || $_REQUEST['action_cut_x'] ) { if( $_REQUEST['action_copy'] || $_REQUEST['action_copy_x']) $session->action = 'copy'; if( $_REQUEST['action_cut'] || $_REQUEST['action_cut_x'] ) $session->action = 'cut'; if( is_array($_REQUEST['selectedNodes']) && sizeof($_REQUEST['selectedNodes'])) { $session->data = $_REQUEST['selectedNodes']; } else { $session->action = ''; } } if( $_REQUEST['action_paste'] || $_REQUEST['action_paste_x'] ) { if( is_array($session->data) && sizeof($session->data)) { if( $session->action == 'copy' ) { if( is_array($_REQUEST['selectedNodes']) && sizeof($_REQUEST['selectedNodes'])) { $dest = $_REQUEST['selectedNodes']; $sources = $session->data; foreach( $sources as $aSrc ) { foreach( $dest as $aDest ) { $methodCalls[] = "tree->copy( $aSrc , $aDest )"; $results[] = $tree->copy( $aSrc , $aDest ); } } #$results = 'Sorry COPY is not implemented yet :-('; $session->data = array(); unset($session->action); $tree->setup(); } else { $methodFailed = true; $results = 'Please choose destination folder(s) to paste to!'; } } if( $session->action == 'cut') { if( !$_REQUEST['moveDest'] ) { $methodFailed = true; $results = 'Please choose a destination to paste to!'; } else { foreach( $session->data as $aNodeId ) { $methodCalls[] = "tree->move( $aNodeId , {$_REQUEST['moveDest']} )"; $results[] = $tree->move( $aNodeId , $_REQUEST['moveDest'] ); } $session->data = array(); unset($session->action); $tree->setup(); } } } } if( ($_REQUEST['action_delete'] || $_REQUEST['action_delete_x']) && is_array($_REQUEST['selectedNodes']) && sizeof($_REQUEST['selectedNodes']) ) { $rootId = $tree->getRootId(); foreach( $_REQUEST['selectedNodes'] as $aNodeId ) { if( $rootId == $aNodeId ) { $methodCalls[] = 0; $results[] = 'Cant remove Root with this application!'; $methodFailed = true; } else { $methodCalls[] = "tree->remove( $aNodeId )"; $res = $tree->remove( $aNodeId ); if(PEAR::isError($res)) $methodFailed = true; $results[] = $res; } } $session->data = array(); unset($session->action); $tree->setup(); } if( $_REQUEST['action_add'] && is_array($_REQUEST['selectedNodes']) && sizeof($_REQUEST['selectedNodes']) && $_REQUEST['newFolder'] ) { foreach( $_REQUEST['selectedNodes'] as $aNodeId ) { $methodCalls[] = "tree->add( {$_REQUEST['newFolder']} , $aNodeId )"; $res = $tree->add( $_REQUEST['newFolder'] , $aNodeId ); if(PEAR::isError($res)) $methodFailed = true; $results[] = $res; } $session->data = array(); unset($session->action); $tree->setup(); } $allVisibleFolders = $tree->getAllVisible(); if( !is_array($_REQUEST['selectedNodes']) ) $_REQUEST['selectedNodes'] = array(); ################################################## # # show the template # $tpl->compile('index.tpl'); include($tpl->compiledTemplate); ?> Index: pear/Tree/examples/TreeEditor_MemoryNested/index.tpl +++ pear/Tree/examples/TreeEditor_MemoryNested/index.tpl <!-- $Id$ --> <html> <body> <style> body, table.simple \{ font-family : verdana, geneva, arial; font-size : 11px; background-color: #DCDCDC; \} table,td, input \{ background-color: white; \} input.button,img.button \{ border: 1px outset black; \} td.selected \{ background-color: lightblue; \} a \{ color: red; text-decoration: none; \} </style> <form method="post" action="{$_SERVER['PHP_SELF']}"> {if($session->action == 'cut')} <img src="cut"> <img src="copy"> {else} <input id="cut" src="cut" name="action_cut" type="image" class="button" onmousedown="document.getElementById('cut').style.border='1px inset black'" alt="cut" name="cut" title="cut"> <input id="copy" src="copy" name="action_copy" type="image" class="button" onmousedown="document.getElementById('copy').style.border='1px inset black'" title="copy"> <input id="paste" src="paste" name="action_paste" type="image" class="button" onmousedown="document.getElementById('paste').style.border='1px inset black'" title="paste"> <img src="" width="1" height="22" class="button"> {if($session->action == 'cut')} <img src="delete"> {else} <input id="delete" src="delete" name="action_delete" type="image" class="button" onmousedown="document.getElementById('delete').style.border='1px inset black'" title="delete"> <hr> <table align="left"> {foreach( $allVisibleFolders as $aFolder )} { $class=''} {if( in_array($aFolder['id'],$session->data) )} { $class=' class="selected"'} <tr> <td {$class}> {if( $session->action == 'cut')} <input type="radio" name="moveDest" value="{$aFolder['id']}"> {else} <input type="checkbox" name="selectedNodes[]" value="{$aFolder['id']}"> </td> <td {$class}> {%tree_showNode($aFolder)%} </td> </tr> </table> {if( $session->action!='cut' )} <table class="simple" border="1"> <tr> <th colspan="2">Add Folder</th> </tr> <tr> <td colspan="2"> Choose the parent folder on the left side, <br> under which the new folder shall be created! </td> </tr> <tr> <td>Name</td> <td> <input name="newFolder[name]"> </td> </tr> <tr> <td> </td> <td> <input type="submit" name="action_add" value="add"> </td> </tr> </table> {if($session->action=='cut')} You have chosen 'CUT', those folders are in the clipboard now.<br> Please select the destination and push the 'PASTE' button! <img class="button" src="paste"> <br> {if($session->action=='copy')} You have chosen 'COPY', those folders are in the clipboard now.<br> Please select the destination and push the 'PASTE' button! <img class="button" src="paste"><br> Or choose other folder(s) that you want to put in the clipboard. <br> {if($results)} <font color="red"> {if( $methodFailed )} ERROR {else} OK <br> </font> {if(sizeof($methodCalls))} <table class="simple" border="1"> <tr> <th>methods called</th> <th>returned</th> </tr> {foreach( $methodCalls as $key=>$aCall)} <tr> <td nowrap>{$aCall}</td> <td align="center"> {if(PEAR::isError($results[$key]))} <font color="red">{$results[$key]->getMessage()}</font> <br> {print_r($results[$key])} </td> </tr> </table> {else} <font color="red"> {print_r($results)} </font> </form> <script type="text/javascript" language="JavaScript" src="{$config->vApplRoot}/external/calendar/popcalendar.js.php"></script> </body> </html> <!-- this macro shows a node for the explorer view @param array the current project --> {%macro tree_showNode($aNode)%} {global $tree,$session} {%repeat $aNode['level'] times%} {if( $tree->hasChildren($aNode['id']) )} <a href="{$_SERVER['PHP_SELF']}?unfold={$aNode['id']}"> {if($session->temp->openProjectFolders[$aNode['id']])} <img src="openFolder" border="0"></a> {else} <img src="closedFolder" border="0"></a> {else} <img src="folder"> <b>{$aNode['name']}</b> {if( $tree->getRootId() == $aNode['id'] )} <a href="{$_SERVER['PHP_SELF']}?unfoldAll=true" title="unfold all">++</a> Index: pear/Tree/examples/TreeEditor_MemoryNested/mysql_db.sql +++ pear/Tree/examples/TreeEditor_MemoryNested/mysql_db.sql # phpMyAdmin MySQL-Dump # version 2.3.0 # http://phpwizard.net/phpMyAdmin/ # http://www.phpmyadmin.net/ (download page) # # Host: localhost # Generation Time: Aug 23, 2002 at 05:46 PM # Server version: 3.23.48 # PHP Version: 4.1.0 # Database : `test` # -------------------------------------------------------- # # Table structure for table `TreeEditor_MemoryNested` # CREATE TABLE TreeEditor_MemoryNested ( id int(11) NOT NULL default '0', name varchar(255) NOT NULL default '', l int(11) NOT NULL default '0', r int(11) NOT NULL default '0', parent int(11) NOT NULL default '0', comment varchar(255) NOT NULL default '', PRIMARY KEY (id) ) TYPE=MyISAM; # # Dumping data for table `TreeEditor_MemoryNested` # INSERT INTO TreeEditor_MemoryNested VALUES (8, 'Root', 1, 18, 0, ''); INSERT INTO TreeEditor_MemoryNested VALUES (9, 'PEAR', 8, 17, 8, ''); INSERT INTO TreeEditor_MemoryNested VALUES (10, 'Tree', 15, 16, 9, ''); INSERT INTO TreeEditor_MemoryNested VALUES (11, 'HTML', 13, 14, 9, ''); INSERT INTO TreeEditor_MemoryNested VALUES (12, 'Auth', 11, 12, 9, ''); INSERT INTO TreeEditor_MemoryNested VALUES (13, 'PEAR compatible', 2, 7, 8, ''); INSERT INTO TreeEditor_MemoryNested VALUES (14, 'SimpleTemplate', 5, 6, 13, ''); INSERT INTO TreeEditor_MemoryNested VALUES (15, 'Auth', 3, 4, 13, ''); INSERT INTO TreeEditor_MemoryNested VALUES (16, 'XML', 9, 10, 9, ''); # -------------------------------------------------------- # # Table structure for table `TreeEditor_MemoryNested_seq` # CREATE TABLE TreeEditor_MemoryNested_seq ( id int(10) unsigned NOT NULL auto_increment, PRIMARY KEY (id) ) TYPE=MyISAM; # # Dumping data for table `TreeEditor_MemoryNested_seq` # INSERT INTO TreeEditor_MemoryNested_seq VALUES (16); Index: pear/Tree/examples/TreeEditor_MemoryNested/treeClass.php +++ pear/Tree/examples/TreeEditor_MemoryNested/treeClass.php <?php // // $Log: treeClass.php,v $ // Revision 1.1 2002/08/23 17:18:28 cain // - a good example to show how the tree works // // require_once('Tree/Memory.php'); class treeClass extends Tree_Memory { function getPathAsString( $id ) { return preg_replace('/Root\s-\s/','',parent::getPathAsString( $id , ' - ' )); } /** * just a wrapper to be compatible to vp_DB_Common * */ function &getAll() { return $this->getNode(); } /** * this is only for the getAllVisible it is called by the walk-method * to retreive only the nodes that shall be visible * * @param array this is the node to check * @return mixed an array if the node shall be visible * nothing if the node shall not be shown */ function _walkForGettingVisibleFolders( $node ) { global $session; if( $node['id']==$this->getRootId() ) return $node; $parentsIds = $this->getParentsIds($node['id']); if( !$this->_unfoldAll ) { foreach( $parentsIds as $aParentId ) { if( !$session->temp->openProjectFolders[$aParentId] && $aParentId!=$node['id']) // dont check the node itself, since we only look if the parents are openend, then this $node is shown! return false; } } else { // if all folders shall be unfolded save the unfold-ids in the session $session->temp->openProjectFolders[$node['id']] = $node['id']; } return $node; } /** * this returns all the visible projects, the folders returned * are those which are unfolded, the explorer-like way * it also handles the 'unfold' parameter, which we simply might be given * so the unfold/fold works on every page that shows only visible folders * i think that is really cool :-) * * @return array only those folders which are visible */ function getAllVisible() { $this->unfoldHandler(); return $this->walk( array(&$this,'_walkForGettingVisibleFolders') , 0 , 'ifArray' ); } function unfoldHandler() { global $session; if( $_REQUEST['unfoldAll'] ) { $this->_unfoldAll = true; } if( $_REQUEST['unfold'] ) { if( $session->temp->openProjectFolders[$_REQUEST['unfold']] ) { unset($session->temp->openProjectFolders[$_REQUEST['unfold']]); } else { $session->temp->openProjectFolders[$_REQUEST['unfold']] = $_REQUEST['unfold']; } } } } ?>
Index: pear/Tree/examples/TreeEditor_MemoryNested/index.php +++ pear/Tree/examples/TreeEditor_MemoryNested/index.php <?php // // $Id: index.php,v 1.1 2002/08/23 17:18:28 cain Exp $ // ################################################## # # init template engine # if( strpos($HTTP_HOST,'ashley') !== false ) // sorry but my template class is there :-) ini_set('include_path',ini_get('include_path').':/usr/local/httpd/includes'); // you need the template class from http://sf.net/projects/simpltpl if( !@include('SimpleTemplate/Engine.php') ) { print 'sorry, you need the template class from <a href="http://sf.net/projects/simpltpl">sourceforge</a> for this.<br>'. 'or if i have time i put the examples <a href="http://wolfram.kriesing.de/programming/">here online</a>'; die(); } require_once('SimpleTemplate/Filter/TagLib.php'); $options = array( 'templateDir' => dirname(__FILE__) ); $tpl = new SimpleTemplate_Engine($options); require_once('SimpleTemplate/Filter/Modifier.php'); $modifiers = new SimpleTemplate_Filter_Modifier($tpl->options); $tpl->registerPrefilter(array(&$modifiers,'imgSrc'),array(dirname(__FILE__),'http://'.$HTTP_HOST.dirname($PHP_SELF))); ################################################## # # actual tree stuff, using Dynamic_DBnested # define('TABLE_TREE','TreeEditor_MemoryNested'); define('DB_DSN','mysql://root@localhost/test'); require_once('treeClass.php'); $options = array( 'table' => TABLE_TREE , 'order' => 'name'); $tree = new treeClass( 'DBnested' , DB_DSN , $options ); # to let it work on the filesystem :-) # $options = array( 'order' => 'name'); # $tree = new treeClass( 'Filesystem' , '/home/wk/tmp' , $options ); $tree->setup(); $tree->setRemoveRecursively(); session_start(); if(!session_is_registered('session')) { $session = new stdClass; // standard PHP-class constructor session_register('session'); $session->data = array(); } else // since the class is read from the session it is not automatically made global { $session = &$_SESSION['session']; } // detect action if( $_REQUEST['action_copy'] || $_REQUEST['action_copy_x'] || $_REQUEST['action_cut'] || $_REQUEST['action_cut_x'] ) { if( $_REQUEST['action_copy'] || $_REQUEST['action_copy_x']) $session->action = 'copy'; if( $_REQUEST['action_cut'] || $_REQUEST['action_cut_x'] ) $session->action = 'cut'; if( is_array($_REQUEST['selectedNodes']) && sizeof($_REQUEST['selectedNodes'])) { $session->data = $_REQUEST['selectedNodes']; } else { $session->action = ''; } } if( $_REQUEST['action_paste'] || $_REQUEST['action_paste_x'] ) { if( is_array($session->data) && sizeof($session->data)) { if( $session->action == 'copy' ) { if( is_array($_REQUEST['selectedNodes']) && sizeof($_REQUEST['selectedNodes'])) { $dest = $_REQUEST['selectedNodes']; $sources = $session->data; foreach( $sources as $aSrc ) { foreach( $dest as $aDest ) { $methodCalls[] = "tree->copy( $aSrc , $aDest )"; $results[] = $tree->copy( $aSrc , $aDest ); } } #$results = 'Sorry COPY is not implemented yet :-('; $session->data = array(); unset($session->action); $tree->setup(); } else { $methodFailed = true; $results = 'Please choose destination folder(s) to paste to!'; } } if( $session->action == 'cut') { if( !$_REQUEST['moveDest'] ) { $methodFailed = true; $results = 'Please choose a destination to paste to!'; } else { foreach( $session->data as $aNodeId ) { $methodCalls[] = "tree->move( $aNodeId , {$_REQUEST['moveDest']} )"; $results[] = $tree->move( $aNodeId , $_REQUEST['moveDest'] ); } $session->data = array(); unset($session->action); $tree->setup(); } } } } if( ($_REQUEST['action_delete'] || $_REQUEST['action_delete_x']) && is_array($_REQUEST['selectedNodes']) && sizeof($_REQUEST['selectedNodes']) ) { $rootId = $tree->getRootId(); foreach( $_REQUEST['selectedNodes'] as $aNodeId ) { if( $rootId == $aNodeId ) { $methodCalls[] = 0; $results[] = 'Cant remove Root with this application!'; $methodFailed = true; } else { $methodCalls[] = "tree->remove( $aNodeId )"; $res = $tree->remove( $aNodeId ); if(PEAR::isError($res)) $methodFailed = true; $results[] = $res; } } $session->data = array(); unset($session->action); $tree->setup(); } if( $_REQUEST['action_add'] && is_array($_REQUEST['selectedNodes']) && sizeof($_REQUEST['selectedNodes']) && $_REQUEST['newFolder'] ) { foreach( $_REQUEST['selectedNodes'] as $aNodeId ) { $methodCalls[] = "tree->add( {$_REQUEST['newFolder']} , $aNodeId )"; $res = $tree->add( $_REQUEST['newFolder'] , $aNodeId ); if(PEAR::isError($res)) $methodFailed = true; $results[] = $res; } $session->data = array(); unset($session->action); $tree->setup(); } $allVisibleFolders = $tree->getAllVisible(); if( !is_array($_REQUEST['selectedNodes']) ) $_REQUEST['selectedNodes'] = array(); ################################################## # # show the template # $tpl->compile('index.tpl'); include($tpl->compiledTemplate); ?> Index: pear/Tree/examples/TreeEditor_MemoryNested/index.tpl +++ pear/Tree/examples/TreeEditor_MemoryNested/index.tpl <!-- $Id$ --> <html> <body> <style> body, table.simple \{ font-family : verdana, geneva, arial; font-size : 11px; background-color: #DCDCDC; \} table,td, input \{ background-color: white; \} input.button,img.button \{ border: 1px outset black; \} td.selected \{ background-color: lightblue; \} a \{ color: red; text-decoration: none; \} </style> <form method="post" action="{$_SERVER['PHP_SELF']}"> {if($session->action == 'cut')} <img src="cut"> <img src="copy"> {else} <input id="cut" src="cut" name="action_cut" type="image" class="button" onmousedown="document.getElementById('cut').style.border='1px inset black'" alt="cut" name="cut" title="cut"> <input id="copy" src="copy" name="action_copy" type="image" class="button" onmousedown="document.getElementById('copy').style.border='1px inset black'" title="copy"> <input id="paste" src="paste" name="action_paste" type="image" class="button" onmousedown="document.getElementById('paste').style.border='1px inset black'" title="paste"> <img src="" width="1" height="22" class="button"> {if($session->action == 'cut')} <img src="delete"> {else} <input id="delete" src="delete" name="action_delete" type="image" class="button" onmousedown="document.getElementById('delete').style.border='1px inset black'" title="delete"> <hr> <table align="left"> {foreach( $allVisibleFolders as $aFolder )} { $class=''} {if( in_array($aFolder['id'],$session->data) )} { $class=' class="selected"'} <tr> <td {$class}> {if( $session->action == 'cut')} <input type="radio" name="moveDest" value="{$aFolder['id']}"> {else} <input type="checkbox" name="selectedNodes[]" value="{$aFolder['id']}"> </td> <td {$class}> {%tree_showNode($aFolder)%} </td> </tr> </table> {if( $session->action!='cut' )} <table class="simple" border="1"> <tr> <th colspan="2">Add Folder</th> </tr> <tr> <td colspan="2"> Choose the parent folder on the left side, <br> under which the new folder shall be created! </td> </tr> <tr> <td>Name</td> <td> <input name="newFolder[name]"> </td> </tr> <tr> <td> </td> <td> <input type="submit" name="action_add" value="add"> </td> </tr> </table> {if($session->action=='cut')} You have chosen 'CUT', those folders are in the clipboard now.<br> Please select the destination and push the 'PASTE' button! <img class="button" src="paste"> <br> {if($session->action=='copy')} You have chosen 'COPY', those folders are in the clipboard now.<br> Please select the destination and push the 'PASTE' button! <img class="button" src="paste"><br> Or choose other folder(s) that you want to put in the clipboard. <br> {if($results)} <font color="red"> {if( $methodFailed )} ERROR {else} OK <br> </font> {if(sizeof($methodCalls))} <table class="simple" border="1"> <tr> <th>methods called</th> <th>returned</th> </tr> {foreach( $methodCalls as $key=>$aCall)} <tr> <td nowrap>{$aCall}</td> <td align="center"> {if(PEAR::isError($results[$key]))} <font color="red">{$results[$key]->getMessage()}</font> <br> {print_r($results[$key])} </td> </tr> </table> {else} <font color="red"> {print_r($results)} </font> </form> <script type="text/javascript" language="JavaScript" src="{$config->vApplRoot}/external/calendar/popcalendar.js.php"></script> </body> </html> <!-- this macro shows a node for the explorer view @param array the current project --> {%macro tree_showNode($aNode)%} {global $tree,$session} {%repeat $aNode['level'] times%} {if( $tree->hasChildren($aNode['id']) )} <a href="{$_SERVER['PHP_SELF']}?unfold={$aNode['id']}"> {if($session->temp->openProjectFolders[$aNode['id']])} <img src="openFolder" border="0"></a> {else} <img src="closedFolder" border="0"></a> {else} <img src="folder"> <b>{$aNode['name']}</b> {if( $tree->getRootId() == $aNode['id'] )} <a href="{$_SERVER['PHP_SELF']}?unfoldAll=true" title="unfold all">++</a> Index: pear/Tree/examples/TreeEditor_MemoryNested/mysql_db.sql +++ pear/Tree/examples/TreeEditor_MemoryNested/mysql_db.sql # phpMyAdmin MySQL-Dump # version 2.3.0 # http://phpwizard.net/phpMyAdmin/ # http://www.phpmyadmin.net/ (download page) # # Host: localhost # Generation Time: Aug 23, 2002 at 05:46 PM # Server version: 3.23.48 # PHP Version: 4.1.0 # Database : `test` # -------------------------------------------------------- # # Table structure for table `TreeEditor_MemoryNested` # CREATE TABLE TreeEditor_MemoryNested ( id int(11) NOT NULL default '0', name varchar(255) NOT NULL default '', l int(11) NOT NULL default '0', r int(11) NOT NULL default '0', parent int(11) NOT NULL default '0', comment varchar(255) NOT NULL default '', PRIMARY KEY (id) ) TYPE=MyISAM; # # Dumping data for table `TreeEditor_MemoryNested` # INSERT INTO TreeEditor_MemoryNested VALUES (8, 'Root', 1, 18, 0, ''); INSERT INTO TreeEditor_MemoryNested VALUES (9, 'PEAR', 8, 17, 8, ''); INSERT INTO TreeEditor_MemoryNested VALUES (10, 'Tree', 15, 16, 9, ''); INSERT INTO TreeEditor_MemoryNested VALUES (11, 'HTML', 13, 14, 9, ''); INSERT INTO TreeEditor_MemoryNested VALUES (12, 'Auth', 11, 12, 9, ''); INSERT INTO TreeEditor_MemoryNested VALUES (13, 'PEAR compatible', 2, 7, 8, ''); INSERT INTO TreeEditor_MemoryNested VALUES (14, 'SimpleTemplate', 5, 6, 13, ''); INSERT INTO TreeEditor_MemoryNested VALUES (15, 'Auth', 3, 4, 13, ''); INSERT INTO TreeEditor_MemoryNested VALUES (16, 'XML', 9, 10, 9, ''); # -------------------------------------------------------- # # Table structure for table `TreeEditor_MemoryNested_seq` # CREATE TABLE TreeEditor_MemoryNested_seq ( id int(10) unsigned NOT NULL auto_increment, PRIMARY KEY (id) ) TYPE=MyISAM; # # Dumping data for table `TreeEditor_MemoryNested_seq` # INSERT INTO TreeEditor_MemoryNested_seq VALUES (16); Index: pear/Tree/examples/TreeEditor_MemoryNested/treeClass.php +++ pear/Tree/examples/TreeEditor_MemoryNested/treeClass.php <?php // // $Log: treeClass.php,v $ // Revision 1.1 2002/08/23 17:18:28 cain // - a good example to show how the tree works // // require_once('Tree/Memory.php'); class treeClass extends Tree_Memory { function getPathAsString( $id ) { return preg_replace('/Root\s-\s/','',parent::getPathAsString( $id , ' - ' )); } /** * just a wrapper to be compatible to vp_DB_Common * */ function &getAll() { return $this->getNode(); } /** * this is only for the getAllVisible it is called by the walk-method * to retreive only the nodes that shall be visible * * @param array this is the node to check * @return mixed an array if the node shall be visible * nothing if the node shall not be shown */ function _walkForGettingVisibleFolders( $node ) { global $session; if( $node['id']==$this->getRootId() ) return $node; $parentsIds = $this->getParentsIds($node['id']); if( !$this->_unfoldAll ) { foreach( $parentsIds as $aParentId ) { if( !$session->temp->openProjectFolders[$aParentId] && $aParentId!=$node['id']) // dont check the node itself, since we only look if the parents are openend, then this $node is shown! return false; } } else { // if all folders shall be unfolded save the unfold-ids in the session $session->temp->openProjectFolders[$node['id']] = $node['id']; } return $node; } /** * this returns all the visible projects, the folders returned * are those which are unfolded, the explorer-like way * it also handles the 'unfold' parameter, which we simply might be given * so the unfold/fold works on every page that shows only visible folders * i think that is really cool :-) * * @return array only those folders which are visible */ function getAllVisible() { $this->unfoldHandler(); return $this->walk( array(&$this,'_walkForGettingVisibleFolders') , 0 , 'ifArray' ); } function unfoldHandler() { global $session; if( $_REQUEST['unfoldAll'] ) { $this->_unfoldAll = true; } if( $_REQUEST['unfold'] ) { if( $session->temp->openProjectFolders[$_REQUEST['unfold']] ) { unset($session->temp->openProjectFolders[$_REQUEST['unfold']]); } else { $session->temp->openProjectFolders[$_REQUEST['unfold']] = $_REQUEST['unfold']; } } } } ?>