summaryrefslogtreecommitdiffstats
path: root/modules-available/locations
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/locations')
-rw-r--r--modules-available/locations/inc/location.inc.php25
-rw-r--r--modules-available/locations/lang/en/template-tags.json2
2 files changed, 26 insertions, 1 deletions
diff --git a/modules-available/locations/inc/location.inc.php b/modules-available/locations/inc/location.inc.php
index 1581f744..42026f8b 100644
--- a/modules-available/locations/inc/location.inc.php
+++ b/modules-available/locations/inc/location.inc.php
@@ -37,6 +37,11 @@ class Location
return Database::queryFirst("SELECT * FROM location WHERE locationid = :locationId", compact('locationId'));
}
+ /**
+ * Get name of location
+ * @param int $locationId id of location to get name for
+ * @return string|false Name of location, false if locationId doesn't exist
+ */
public static function getName($locationId)
{
self::getLocationsAssoc();
@@ -46,6 +51,26 @@ class Location
return self::$assocLocationCache[$locationId]['locationname'];
}
+ /**
+ * Get all the names of the given location and its parents, up
+ * to the root element. Array keys will be locationids, value the names.
+ * @param int $locationId
+ * @return array|false locations, from furthest to nearest or false if locationId doesn't exist
+ */
+ public static function getNameChain($locationId)
+ {
+ self::getLocationsAssoc();
+ settype($locationId, 'int');
+ if (!isset(self::$assocLocationCache[$locationId]))
+ return false;
+ $ret = array();
+ while (isset(self::$assocLocationCache[$locationId])) {
+ $ret[$locationId] = self::$assocLocationCache[$locationId]['locationname'];
+ $locationId = self::$assocLocationCache[$locationId]['parentlocationid'];
+ }
+ return array_reverse($ret, true);
+ }
+
public static function getLocationsAssoc()
{
if (self::$assocLocationCache === false) {
diff --git a/modules-available/locations/lang/en/template-tags.json b/modules-available/locations/lang/en/template-tags.json
index e3c0b056..ddb90f83 100644
--- a/modules-available/locations/lang/en/template-tags.json
+++ b/modules-available/locations/lang/en/template-tags.json
@@ -32,4 +32,4 @@
"lang_thisListByLocation": "Locations",
"lang_thisListBySubnet": "Subnets",
"lang_unassignedMachines": "Machines not matching any location"
-} \ No newline at end of file
+}