diff --git a/application/forms/BasketForm.php b/application/forms/BasketForm.php index 8ff6cca6..4ac942c4 100644 --- a/application/forms/BasketForm.php +++ b/application/forms/BasketForm.php @@ -52,9 +52,9 @@ class BasketForm extends DirectorObjectForm $types = $this->getAvailableTypes(); $options = [ - 'IGNORE' => $this->translate('Ignore'), - 'ALL' => $this->translate('All of them'), - '[]' => $this->translate('Custom Selection'), + Basket::SELECTION_NONE => $this->translate('Ignore'), + Basket::SELECTION_ALL => $this->translate('All of them'), + Basket::SELECTION_CUSTOM => $this->translate('Custom Selection'), ]; $this->addHtmlHint($this->translate( @@ -92,13 +92,13 @@ class BasketForm extends DirectorObjectForm /** @var Basket $object */ $values = []; foreach ($this->getAvailableTypes() as $type => $label) { - $values[$type] = 'IGNORE'; + $values[$type] = Basket::SELECTION_NONE; } foreach ($object->getChosenObjects() as $type => $selection) { if ($selection === true) { - $values[$type] = 'ALL'; + $values[$type] = Basket::SELECTION_ALL; } elseif (is_array($selection)) { - $values[$type] = '[]'; + $values[$type] = Basket::SELECTION_CUSTOM; } } diff --git a/library/Director/DirectorObject/Automation/Basket.php b/library/Director/DirectorObject/Automation/Basket.php index f7eb8e53..e0b62913 100644 --- a/library/Director/DirectorObject/Automation/Basket.php +++ b/library/Director/DirectorObject/Automation/Basket.php @@ -15,8 +15,9 @@ use Icinga\Module\Director\Exception\DuplicateKeyException; */ class Basket extends DbObject implements ExportInterface { - const SELECTION_ALL = true; - const SELECTION_NONE = false; + const SELECTION_ALL = 'ALL'; + const SELECTION_NONE = 'IGNORE'; + const SELECTION_CUSTOM = '[]'; protected $table = 'director_basket'; @@ -141,11 +142,11 @@ class Basket extends DbObject implements ExportInterface { BasketSnapshot::assertValidType($type); // '1' -> from Form! - if ($objects === 'ALL') { + if ($objects === self::SELECTION_ALL) { $objects = true; - } elseif ($objects === null || $objects === 'IGNORE') { + } elseif ($objects === null || $objects === self::SELECTION_NONE) { return; - } elseif ($objects === '[]' || is_array($objects)) { + } elseif ($objects === self::SELECTION_CUSTOM || is_array($objects)) { if (! isset($this->chosenObjects[$type]) || ! is_array($this->chosenObjects[$type])) { $this->chosenObjects[$type] = []; } @@ -157,16 +158,14 @@ class Basket extends DbObject implements ExportInterface } } - if ($objects === '[]') { + if ($objects === self::SELECTION_CUSTOM) { $objects = []; } } if ($objects === true) { $this->chosenObjects[$type] = true; - } elseif ($objects === '0') { - // nothing - } else { + } elseif ($objects !== '0') { // TODO: what would generate '0'? foreach ($objects as $object) { $this->addObject($type, $object); }