X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttConfigHelper.class.php;fp=WEB-INF%2Flib%2FttConfigHelper.class.php;h=95cd12186c4967f8b875adb0f79c186ebb726663;hb=99041558bf625b082fc5058a93e1bd2634c2c9d2;hp=0000000000000000000000000000000000000000;hpb=a67c7fec533237be9be83379eb19fbbf51174c9a;p=timetracker.git diff --git a/WEB-INF/lib/ttConfigHelper.class.php b/WEB-INF/lib/ttConfigHelper.class.php new file mode 100644 index 00000000..95cd1218 --- /dev/null +++ b/WEB-INF/lib/ttConfigHelper.class.php @@ -0,0 +1,98 @@ +config = $config; + $this->config_array = explode(',', $this->config); + } + + // getDefinedValue determines if a value identified by name is defined. + function getDefinedValue($name) { + return in_array($name, $this->$config_array); + } + + // The getIntValue parses an integer value from the source config string. + function getIntValue($name) { + $name_with_colon = $name.':'; + $len = strlen($name_with_colon); + + foreach ($this->config_array as $unparsed_value) { + if (substr($unparsed_value, 0, $len) === $name_with_colon) { + // Found value. + $unparsed_len = strlen($unparsed_value); + $int_value = (int) substr($unparsed_value, -($unparsed_len - $len)); + return $int_value; + } + + } + return false; + } + + // The setIntValue sets an integer value into config array. + function setIntValue($name, $value) { + // Try to find and replace an already existing value. + $name_with_colon = $name.':'; + $len = strlen($name_with_colon); + + foreach ($this->config_array as $key => $unparsed_value) { + if (substr($unparsed_value, 0, $len) === $name_with_colon) { + // Found an already existing value. + // Remove value if our new value is NULL. + if ($value !== null) { + // Replace value. + $this->config_array[$key] = $name.':'.$value; + } else { + // Remove value. + unset($this->config_array[$key]); + } + $this->config = implode(',', $this->config_array); + return; + } + } + // If we get here, the value was not found, so add it. + $this->config_array[] = $name.':'.$value; + $this->config = implode(',', $this->config_array); + return; + } + + // The getConfig returns the config string. + function getConfig() { + return $this->config; + } +}