Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Skip rows without an ID while converting to a tree.

git-svn-id: svn://dklab.ru/lib/DbSimple/trunk@170 78bb956b-1e24-0410-b8d0-c528fdc9eae3
  • Loading branch information...
commit 1241a17ca4a67b17634392a6ba78040748dd4e27 1 parent 092b093
dk authored
Showing with 9 additions and 2 deletions.
  1. +9 −2 lib/DbSimple/Generic.php
View
11 lib/DbSimple/Generic.php
@@ -986,12 +986,18 @@ function _transformResultToForest($rows, $idName, $pidName)
foreach ($rows as $i=>$r) {
$row =& $rows[$i];
$id = $row[$idName];
+ if ($id === null) {
+ // Rows without an ID are totally invalid and makes the result tree to
+ // be empty (because PARENT_ID = null means "a root of the tree"). So
+ // skip them totally.
+ continue;
+ }
$pid = $row[$pidName];
if ($id == $pid) $pid = null;
$children[$pid][$id] =& $row;
if (!isset($children[$id])) $children[$id] = array();
$row['childNodes'] =& $children[$id];
- $ids[$row[$idName]] = true;
+ $ids[$id] = true;
}
// Root elements are elements with non-found PIDs.
$forest = array();
@@ -1003,7 +1009,8 @@ function _transformResultToForest($rows, $idName, $pidName)
if (!isset($ids[$pid])) {
$forest[$row[$idName]] =& $row;
}
- unset($row[$idName]); unset($row[$pidName]);
+ unset($row[$idName]);
+ unset($row[$pidName]);
}
return $forest;
}
Please sign in to comment.
Something went wrong with that request. Please try again.