cvs: pear /Tree/Memory Array.php
| From: | Wolfram Kriesing | Date: | Thu, 06 Feb 2003 19:10:49 +0000 |
| Subject: | cvs: pear /Tree/Memory Array.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-8736@lists.php.net to get a copy of this message | ||
cain Thu Feb 6 14:10:49 2003 EDT
Modified files:
/pear/Tree/Memory Array.php
Log:
- bugfix in setup, for detecting the auto-id
- some cleaning up
Index: pear/Tree/Memory/Array.php
diff -u pear/Tree/Memory/Array.php:1.6 pear/Tree/Memory/Array.php:1.7
--- pear/Tree/Memory/Array.php:1.6 Wed Feb 5 12:39:45 2003
+++ pear/Tree/Memory/Array.php Thu Feb 6 14:10:49 2003
@@ -16,7 +16,7 @@
// | Authors: Wolfram Kriesing <wolfram@kriesing.de> |
// +----------------------------------------------------------------------+
//
-// $Id: Array.php,v 1.6 2003/02/05 17:39:45 cain Exp $
+// $Id: Array.php,v 1.7 2003/02/06 19:10:49 cain Exp $
require_once('Tree/Error.php');
@@ -90,6 +90,11 @@
if (!isset($newData['id']) || !$newData['id']) { // if the
current element has no id, we generate one
$newData['id'] = $this->_id++; // build a unique numeric id
$array[$nodeKey]['id'] = $newData['id']; // set the id
+ } else {
+ $idAsInt = (int)$newData['id'];
+ if ($idAsInt > $this->_id) {
+ $this->_id = $idAsInt;
+ }
}
//print "a node name=".$aNode['name'].'<br>';
$newData['parentId'] = $parentId; // set the parent-id, since we only
have a 'children' array
@@ -204,21 +209,20 @@
{
if (!isset($data['id'])) {
$data['id'] = $this->_id++;
- } elseif(is_int($data['id'] && $data['id'] > $this->_id))
{
+ } elseif((int)$data['id'] > $this->_id) {
// update the $this->_id if the data['id'] has a higher number, since
// we dont want to overwrite anything. just in case
- $this->_id = $data['id'];
+ $this->_id = (int)$data['id'];
}
$data['parentId'] = $parentId;
$this->data[$data['id']] = $data;
//$path = $this->getPathById($parentId);
-
if (!isset($this->_array['children'])) { // there might not be a root
element yet
$data['parentId'] = 0;
$this->_array['children'][] = $data;
} else {
-
array_walk($this->_array['children'],array(&$this,'_add'),array($data,$parentId));
+
array_walk($this->_array['children'],array(&$this,'_add'),array($data,$parentId,$previousId));
}
//$this->_array
@@ -229,6 +233,12 @@
function _add( &$val , $key , $data )
{
if ($val['id']==$data[1]) { // is the id of the current elment ($val) == to the
parentId ($data[1])
+/* if (isset($data[2])) { // is there a previousId given?
+ foreach ($val['children'] as $aChild)
+ } else {
+ $val['children'][] = $data[0];
+ }
+*/
$val['children'][] = $data[0];
} else { // if we havent found the new element go on searching
if (isset($val['children'])) {
@@ -288,7 +298,9 @@
*/
function remove($id)
{
- $this->_remove($this->_array,$id);
+ if ($this->data[$id]) { // we only need to search for element that
do exist :-) otherwise we save some processing time
+ $this->_remove($this->_array,$id);
+ }
}
/**