From 982faeb86921f53e2d227a2e23a6c51356b2b1be Mon Sep 17 00:00:00 2001 From: Paul Gear Date: Sat, 13 Jun 2015 09:26:26 +1000 Subject: [PATCH] Implement more efficient is_dev_attrib_enabled() --- includes/common.php | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/includes/common.php b/includes/common.php index 9f94a2b65..1d1896148 100644 --- a/includes/common.php +++ b/includes/common.php @@ -453,16 +453,6 @@ function get_dev_attribs($device) return $attribs; } -function is_dev_attrib_enabled($device, $attrib) -{ - foreach (get_dev_attribs($device) as $name => $val) { - if ($name == $attrib && $val == 0) { - return false; - } - } - return true; -} - function get_dev_entity_state($device) { $state = array(); @@ -486,6 +476,19 @@ function get_dev_attrib($device, $attrib_type) } } +function is_dev_attrib_enabled($device, $attrib, $default = true) +{ + $val = get_dev_attrib($device, $attrib); + if ($val != NULL) { + // attribute is set + return ($val != 0); + } + else { + // attribute not set + return $default; + } +} + function del_dev_attrib($device, $attrib_type) { return dbDelete('devices_attribs', "`device_id` = ? AND `attrib_type` = ?", array($device['device_id'], $attrib_type));