IcingaTimePeriodRanges: lot of changes
This commit is contained in:
parent
3970f381dd
commit
81e97853c4
|
@ -75,6 +75,26 @@ class IcingaTimePeriodRanges implements Iterator, Countable, IcingaConfigRendere
|
||||||
return null;
|
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()
|
public function getRanges()
|
||||||
{
|
{
|
||||||
return $this->ranges;
|
return $this->ranges;
|
||||||
|
@ -88,9 +108,27 @@ class IcingaTimePeriodRanges implements Iterator, Countable, IcingaConfigRendere
|
||||||
public function set($ranges)
|
public function set($ranges)
|
||||||
{
|
{
|
||||||
foreach ($ranges as $range => $value) {
|
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 (array_key_exists($range, $this->ranges)) {
|
||||||
if ($this->ranges[$range]->timeperiod_value === $value) {
|
if ($this->ranges[$range]->timeperiod_value === $value) {
|
||||||
continue;
|
return $this;
|
||||||
} else {
|
} else {
|
||||||
$this->ranges[$range]->timeperiod_value = $value;
|
$this->ranges[$range]->timeperiod_value = $value;
|
||||||
$this->modified = true;
|
$this->modified = true;
|
||||||
|
@ -103,13 +141,6 @@ class IcingaTimePeriodRanges implements Iterator, Countable, IcingaConfigRendere
|
||||||
));
|
));
|
||||||
$this->modified = true;
|
$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;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -181,7 +212,11 @@ class IcingaTimePeriodRanges implements Iterator, Countable, IcingaConfigRendere
|
||||||
|
|
||||||
$class = $this->getClass();
|
$class = $this->getClass();
|
||||||
$this->ranges = $class::loadAll($connection, $query, 'timeperiod_key');
|
$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;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue