From fa5d2b233d5830e8b958306a8cec387c05d6c358 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 13 Apr 2017 18:08:04 +0200 Subject: [locations] Return recursive list of children in getLocationsAssoc() --- modules-available/locations/inc/location.inc.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'modules-available/locations') 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(); -- cgit v1.2.3-55-g7522