Author: david
Date: Fri Feb 11 16:07:52 2011
New Revision: 8962
Log:
Build object tree as an array
Modified:
trunk/lib/task/nestedsetBuildTask.class.php
Modified: trunk/lib/task/nestedsetBuildTask.class.php
==============================================================================
--- trunk/lib/task/nestedsetBuildTask.class.php Fri Feb 11 15:54:23 2011
(r8961)
+++ trunk/lib/task/nestedsetBuildTask.class.php Fri Feb 11 16:07:52 2011
(r8962)
@@ -66,27 +66,43 @@
$conn = $databaseManager->getDatabase('propel')->getConnection();
$sth = $conn->query($sql);
- $results = $sth->fetchAll(PDO::FETCH_ASSOC);
+ $infoObjects = $sth->fetchAll(PDO::FETCH_ASSOC);
$tree = array();
- foreach ($results as $row)
+
+ // Add root node to tree
+ foreach ($infoObjects as $key => $item)
{
- if ($row['parent_id'] !== null)
+ if (QubitInformationObject::ROOT_ID == $item['id'])
{
- if (isset($tree[$row['parent_id']]))
- {
- array_push($tree[$row['parent_id']]['children'], $row['id']);
- }
- else
- {
- $tree[$row['parent_id']]['children'] = array($row['id']);
- }
+ array_push($tree, $item + array('children' => array()));
+ unset($infoObjects[$key]);
+ break;
}
}
- self::get_width($tree[1]);
+ // Recursively add child nodes
+ self::addChildren($tree[0], $infoObjects);
+
+ //self::get_width($tree[1]);
+
+ print_r($tree);
+ }
+
+ protected function addChildren(&$node, &$infoObjects)
+ {
+ foreach ($infoObjects as $key => $item)
+ {
+ if ($node['id'] == $item['parent_id'])
+ {
+ $child = $item + array('children' => array());
+
+ self::addChildren($child, $infoObjects);
- print_r($tree[1]['width']);
+ array_push($node['children'], $child);
+ unset($infoObjects[$key]);
+ }
+ }
}
protected function get_width(&$node)
--
You received this message because you are subscribed to the Google Groups
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/qubit-commits?hl=en.