summaryrefslogtreecommitdiffstats
path: root/modules-available/locations
diff options
context:
space:
mode:
authorSimon Rettberg2017-04-13 18:08:04 +0200
committerSimon Rettberg2017-04-13 18:08:04 +0200
commitfa5d2b233d5830e8b958306a8cec387c05d6c358 (patch)
tree5794f73577fdc3d5459f67c50cce14c1980fcb08 /modules-available/locations
parent[locationinfo] install.inc.php: Fix upgrade order (diff)
downloadslx-admin-fa5d2b233d5830e8b958306a8cec387c05d6c358.tar.gz
slx-admin-fa5d2b233d5830e8b958306a8cec387c05d6c358.tar.xz
slx-admin-fa5d2b233d5830e8b958306a8cec387c05d6c358.zip
[locations] Return recursive list of children in getLocationsAssoc()
Diffstat (limited to 'modules-available/locations')
-rw-r--r--modules-available/locations/inc/location.inc.php10
1 files changed, 8 insertions, 2 deletions
diff --git a/modules-available/locations/inc/location.inc.php b/modules-available/locations/inc/location.inc.php
index 73080094..a64f5c79 100644
--- a/modules-available/locations/inc/location.inc.php
+++ b/modules-available/locations/inc/location.inc.php
@@ -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();