cvs: pear /Tree Memory.php
| From: | Wolfram Kriesing | Date: | Mon, 25 Feb 2002 10:50:54 +0000 |
| Subject: | cvs: pear /Tree Memory.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-2613@lists.php.net to get a copy of this message | ||
cain Mon Feb 25 05:50:54 2002 EDT
Modified files:
/pear/Tree Memory.php
Log:
- fixed bug which didnt create next/previous relations properly, due to former DB design of this
class
- enhanced varDump a bit
Index: pear/Tree/Memory.php
diff -u pear/Tree/Memory.php:1.2 pear/Tree/Memory.php:1.3
--- pear/Tree/Memory.php:1.2 Wed Feb 6 18:28:49 2002
+++ pear/Tree/Memory.php Mon Feb 25 05:50:54 2002
@@ -16,7 +16,7 @@
// | Authors: Wolfram Kriesing <wolfram@kriesing.de> |
// +----------------------------------------------------------------------+
//
-// $Id: Memory.php,v 1.2 2002/02/06 23:28:49 cain Exp $
+// $Id: Memory.php,v 1.3 2002/02/25 10:50:54 cain Exp $
require_once('Tree/Common.php');
@@ -260,7 +260,27 @@
$this->children[ $values['parentId'] ][] = $values['id'];
}
-#print_r($this->data);
+ // walk through all the children on each level and set the next/previous relations
+ // of those children, since all children for "children[$id]" are on the same
level we can do
+ // this here :-)
+ foreach( $this->children as $children )
+ {
+ $lastPrevId = 0;
+ if(sizeof($children))
+ foreach( $children as $key )
+ {
+ if( $lastPrevId )
+ {
+ $this->data[$lastPrevId]['nextId'] = $key; // remember the nextId
too, so the build process can be sped up
+ $this->data[$lastPrevId]['next'] = &$this->data[$key];
+
+ $this->data[$key]['prevId'] = $lastPrevId;
+ $this->data[$key]['previous'] = &$this->data[ $lastPrevId
];
+ }
+ $lastPrevId = $key;
+ }
+ }
+
#print_r($this->children);
if( $this->debug )
@@ -283,23 +303,6 @@
// most if checks in this foreach are for the following reason, if not stated
otherwise:
// dont make an data[''] or data[0] since this was not read from the DB,
because id is autoincrement and starts at 1
// and also in an xml tree there can not be an element </> , i hope :-)
-
-# it doesnt work properly for XML files
-# yet, since the data returned are not sorted by parentId
-# as assued here, correct that in here !!!
- if( $lastParentId != $value['parentId'] ) // if we are still on the same
level (since it is sorted by parentId we can do this)
- {
- $lastPrevId = 0; // every first element on a level has no
previous (prevId=0)
- }
- else
- {
- if( $lastPrevId ) // see comment above
- {
- $this->data[$lastPrevId]['nextId'] = $key; // remember the
nextId too, so the build process can be sped up
- $this->data[$lastPrevId]['next'] =
&$this->data[$key];
- }
- }
-
if( $value['parentId'] ) // see comment above
{
$this->data[$key]['parent'] = &$this->data[
$value['parentId'] ];
@@ -307,19 +310,14 @@
$this->data[ $value['parentId'] ]['children'][] =
&$this->data[$key];
}
- if( $lastPrevId ) // see comment above
- {
- $this->data[$key]['prevId'] = $lastPrevId;
- $this->data[$key]['previous'] = &$this->data[ $lastPrevId
];
- }
-
+ // was a child saved (in the above 'if')
if( sizeof( $this->children[$key] ) ) // see comment above
{
+ // refer to the first child in the [child] and [childId] keys
$this->data[$key]['childId'] = $this->children[$key][0];
$this->data[$key]['child'] = &$this->data[
$this->children[$key][0] ];
}
- $lastPrevId = $key;
$lastParentId = $value['parentId'];
}
}
@@ -1007,6 +1005,7 @@
break;
}
$curId = $this->getNextId($curId);
+#print "curId = $curId<br>";
}
while( $curId );
@@ -1160,14 +1159,24 @@
foreach( $node as $aNode )
{
- print '<u>Element: </u>';
+ print '<u>Element</u> :';
foreach( $aNode as $key=>$aElement )
{
print "$key";
if( in_array( $key , $dontDump ) )
{
- print "['id']=".$aElement['id'];
+ if( !$aElement['id'] && is_array($aElement) )
+ {
+ print "['ids']=";
+ $ids = array();
+ foreach( $aElement as $aSubElement )
+ $ids[] = $aSubElement['id'];
+ print implode(', ',$ids);
+ }
+ else
+
+ print "['id']=".$aElement['id'];
}
else
{