summaryrefslogtreecommitdiffstats
path: root/modules-available/locations/inc
diff options
context:
space:
mode:
authorSimon Rettberg2016-06-08 13:00:39 +0200
committerSimon Rettberg2016-06-08 13:00:39 +0200
commit62f218da95ac407c69cc0956c257ddc2ae9293c3 (patch)
tree4eb8b5a95752920a2fc8de80b01b640caf690451 /modules-available/locations/inc
parentPhpStorm stuff (diff)
downloadslx-admin-62f218da95ac407c69cc0956c257ddc2ae9293c3.tar.gz
slx-admin-62f218da95ac407c69cc0956c257ddc2ae9293c3.tar.xz
slx-admin-62f218da95ac407c69cc0956c257ddc2ae9293c3.zip
[location] Move getLocationRootChain to heler class
Diffstat (limited to 'modules-available/locations/inc')
-rw-r--r--modules-available/locations/inc/location.inc.php25
1 files changed, 25 insertions, 0 deletions
diff --git a/modules-available/locations/inc/location.inc.php b/modules-available/locations/inc/location.inc.php
index 4bfe9f7a..25e888d8 100644
--- a/modules-available/locations/inc/location.inc.php
+++ b/modules-available/locations/inc/location.inc.php
@@ -153,6 +153,12 @@ class Location
return $ids;
}
+ /**
+ * Get closest location by matching subnets. Deepest match in tree wins.
+ *
+ * @param string $ip IP address of client
+ * @return bool|int locationid, or false if no match
+ */
public static function getFromIp($ip)
{
$locationId = false;
@@ -172,6 +178,25 @@ class Location
}
/**
+ * Get all location IDs from the given location up to the root.
+ *
+ * @param int $locationId
+ * @return int[] location ids, including $locationId
+ */
+ public function getLocationRootChain($locationId)
+ {
+ settype($locationId, 'integer');
+ $locations = Location::getLocationsAssoc();
+ $find = $locationId;
+ $matchingLocations = array();
+ while (isset($locations[$find]) && !in_array($find, $matchingLocations)) {
+ $matchingLocations[] = $find;
+ $find = (int)$locations[$find]['parentlocationid'];
+ }
+ return $matchingLocations;
+ }
+
+ /**
* @return array list of subnets as numeric array
*/
public static function getSubnets()