diff options
author | Simon Rettberg | 2017-12-01 13:42:04 +0100 |
---|---|---|
committer | Simon Rettberg | 2017-12-01 13:42:04 +0100 |
commit | 5393703f6e1485ddff94a50f63bcdd216ab629f4 (patch) | |
tree | ce2db7130302bd4fb78b170e1fbd75496a1b4510 /modules-available/locations/inc | |
parent | Merge remote-tracking branch 'origin/permission-manager' into permission-manager (diff) | |
parent | [roomplanner] Sort already placed machines to the bottom (diff) | |
download | slx-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/inc')
-rw-r--r-- | modules-available/locations/inc/location.inc.php | 25 |
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 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) { |