diff options
author | Simon Rettberg | 2017-04-13 18:08:04 +0200 |
---|---|---|
committer | Simon Rettberg | 2017-04-13 18:08:04 +0200 |
commit | fa5d2b233d5830e8b958306a8cec387c05d6c358 (patch) | |
tree | 5794f73577fdc3d5459f67c50cce14c1980fcb08 /modules-available/locations/inc | |
parent | [locationinfo] install.inc.php: Fix upgrade order (diff) | |
download | slx-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/inc')
-rw-r--r-- | modules-available/locations/inc/location.inc.php | 10 |
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(); |