diff options
author | Simon Rettberg | 2017-11-30 18:30:01 +0100 |
---|---|---|
committer | Simon Rettberg | 2017-11-30 18:30:01 +0100 |
commit | b90c97b1f096008b5fa9abf8c50a120a85c47a4e (patch) | |
tree | 2e6de58e0de3d044549946b352cb6b2bd61916fd /modules-available/locations/inc | |
parent | Update translations (diff) | |
download | slx-admin-b90c97b1f096008b5fa9abf8c50a120a85c47a4e.tar.gz slx-admin-b90c97b1f096008b5fa9abf8c50a120a85c47a4e.tar.xz slx-admin-b90c97b1f096008b5fa9abf8c50a120a85c47a4e.zip |
[roomplanner] Refactor to use runmode
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 476f4c68..0576e660 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) { |