IcingaTimePeriodRanges: lot of changes

This commit is contained in:
Thomas Gelf 2016-03-17 23:06:06 +01:00
parent 3970f381dd
commit 81e97853c4
1 changed files with 51 additions and 16 deletions

View File

@ -75,6 +75,26 @@ class IcingaTimePeriodRanges implements Iterator, Countable, IcingaConfigRendere
return null;
}
public function getValues()
{
$res = array();
foreach ($this->ranges as $key => $range) {
$res[$key] = $range->timeperiod_value;
}
return (object) $res;
}
public function getOriginalValues()
{
$res = array();
foreach ($this->storedRanges as $key => $range) {
$res[$key] = $range->timeperiod_value;
}
return (object) $res;
}
public function getRanges()
{
return $this->ranges;
@ -88,9 +108,27 @@ class IcingaTimePeriodRanges implements Iterator, Countable, IcingaConfigRendere
public function set($ranges)
{
foreach ($ranges as $range => $value) {
$this->setRange($range, $value);
}
$toDelete = array_diff(array_keys($this->ranges), array_keys($ranges));
foreach ($toDelete as $range) {
$this->remove($range);
}
return $this;
}
public function setRange($range, $value)
{
if ($value === null && array_key_exists($range, $this->ranges)) {
$this->remove($range);
return $this;
}
if (array_key_exists($range, $this->ranges)) {
if ($this->ranges[$range]->timeperiod_value === $value) {
continue;
return $this;
} else {
$this->ranges[$range]->timeperiod_value = $value;
$this->modified = true;
@ -103,13 +141,6 @@ class IcingaTimePeriodRanges implements Iterator, Countable, IcingaConfigRendere
));
$this->modified = true;
}
}
$toDelete = array_diff(array_keys($this->ranges), array_keys($ranges));
foreach ($toDelete as $range) {
$this->remove($range);
$this->modified = true;
}
return $this;
}
@ -181,7 +212,11 @@ class IcingaTimePeriodRanges implements Iterator, Countable, IcingaConfigRendere
$class = $this->getClass();
$this->ranges = $class::loadAll($connection, $query, 'timeperiod_key');
$this->storedRanges = $this->ranges;
$this->storedRanges = array();
foreach ($this->ranges as $key => $range) {
$this->storedRanges[$key] = clone($range);
}
return $this;
}