summaryrefslogtreecommitdiffstats
path: root/modules-available/locations/inc
diff options
context:
space:
mode:
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()