summaryrefslogtreecommitdiffstats
path: root/modules-available/locations
diff options
context:
space:
mode:
authorSimon Rettberg2017-12-01 13:42:04 +0100
committerSimon Rettberg2017-12-01 13:42:04 +0100
commit5393703f6e1485ddff94a50f63bcdd216ab629f4 (patch)
treece2db7130302bd4fb78b170e1fbd75496a1b4510 /modules-available/locations
parentMerge remote-tracking branch 'origin/permission-manager' into permission-manager (diff)
parent[roomplanner] Sort already placed machines to the bottom (diff)
downloadslx-admin-5393703f6e1485ddff94a50f63bcdd216ab629f4.tar.gz
slx-admin-5393703f6e1485ddff94a50f63bcdd216ab629f4.tar.xz
slx-admin-5393703f6e1485ddff94a50f63bcdd216ab629f4.zip
Merge branch 'master' into permission-manager
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
+}