From a9728379f3c796ef4f2fdddb8211febf3d5399d9 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Mon, 12 Jun 2017 17:00:45 +0200 Subject: [locationinfo] Location edit part done so far --- modules-available/locations/inc/location.inc.php | 41 ++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'modules-available/locations') diff --git a/modules-available/locations/inc/location.inc.php b/modules-available/locations/inc/location.inc.php index aff2dec5..85b7e47f 100644 --- a/modules-available/locations/inc/location.inc.php +++ b/modules-available/locations/inc/location.inc.php @@ -130,6 +130,47 @@ class Location return array_values($rows); } + /** + * Get nested array of all the locations and children of given locationid(s). + * + * @param int[]|int $idList List of location ids + * @param bool $locationTree used in recursive calls, don't pass + * @return array list of passed locations plus their children + */ + public static function getRecursive($idList, $locationTree = false) + { + if (!is_array($idList)) { + $idList = array($idList); + } + if ($locationTree === false) { + $locationTree = self::getTree(); + } + $ret = array(); + foreach ($locationTree as $location) { + if (in_array($location['locationid'], $idList)) { + $ret[] = $location; + } elseif (!empty($location['children'])) { + $ret = array_merge($ret, self::getRecursive($idList, $location['children'])); + } + } + return $ret; + } + + /** + * Get flat array of all the locations and children of given locationid(s). + * + * @param int[]|int $idList List of location ids + * @return array list of passed locations plus their children + */ + public static function getRecursiveFlat($idList) + { + $ret = self::getRecursive($idList); + if (!empty($ret)) { + $ret = self::flattenTree($ret); + } + return $ret; + } + public static function buildTree($elements, $parentId = 0) { $branch = array(); -- cgit v1.2.3-55-g7522