summaryrefslogtreecommitdiffstats
path: root/modules-available/locations
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/locations')
-rw-r--r--modules-available/locations/inc/location.inc.php12
1 files changed, 9 insertions, 3 deletions
diff --git a/modules-available/locations/inc/location.inc.php b/modules-available/locations/inc/location.inc.php
index 9977379f..8f3447da 100644
--- a/modules-available/locations/inc/location.inc.php
+++ b/modules-available/locations/inc/location.inc.php
@@ -8,7 +8,7 @@ class Location
private static $treeCache = false;
private static $subnetMapCache = false;
- private static function getTree()
+ public static function getTree()
{
if (self::$treeCache === false) {
self::$treeCache = self::queryLocations();
@@ -61,12 +61,18 @@ class Location
'locationid' => (int)$node['locationid'],
'parentlocationid' => (int)$node['parentlocationid'],
'parents' => $parents,
+ 'children' => empty($node['children']) ? array() : array_map(function ($item) { return $item['locationid']; }, $node['children']),
'locationname' => $node['locationname'],
'depth' => $depth,
'isleaf' => true,
);
if (!empty($node['children'])) {
- $output += self::flattenTreeAssoc($node['children'], array_merge($parents, array((int)$node['locationid'])), $depth + 1);
+ $childNodes = self::flattenTreeAssoc($node['children'], array_merge($parents, array((int)$node['locationid'])), $depth + 1);
+ $output[(int)$node['locationid']]['children'] = array_merge($output[(int)$node['locationid']]['children'],
+ array_reduce($childNodes, function ($carry, $item) {
+ return array_merge($carry, $item['children']);
+ }, array()));
+ $output += $childNodes;
}
}
foreach ($output as &$entry) {
@@ -119,7 +125,7 @@ class Location
return array_values($rows);
}
- public static function buildTree($elements, $parentId = 0)
+ private static function buildTree($elements, $parentId = 0)
{
$branch = array();
$sort = array();