summaryrefslogtreecommitdiffstats
path: root/modules-available/locations
diff options
context:
space:
mode:
authorSimon Rettberg2017-06-12 17:00:45 +0200
committerSimon Rettberg2017-06-12 17:00:45 +0200
commita9728379f3c796ef4f2fdddb8211febf3d5399d9 (patch)
tree6a31d35f1d01d5f77614cd9a4c6922181a45ebd0 /modules-available/locations
parent[locationinfo] Started rewrite for panel-based approach (diff)
downloadslx-admin-a9728379f3c796ef4f2fdddb8211febf3d5399d9.tar.gz
slx-admin-a9728379f3c796ef4f2fdddb8211febf3d5399d9.tar.xz
slx-admin-a9728379f3c796ef4f2fdddb8211febf3d5399d9.zip
[locationinfo] Location edit part done so far
Diffstat (limited to 'modules-available/locations')
-rw-r--r--modules-available/locations/inc/location.inc.php41
1 files changed, 41 insertions, 0 deletions
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();