From b90c97b1f096008b5fa9abf8c50a120a85c47a4e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 30 Nov 2017 18:30:01 +0100 Subject: [roomplanner] Refactor to use runmode --- modules-available/locations/inc/location.inc.php | 25 ++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'modules-available/locations') 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) { -- cgit v1.2.3-55-g7522