Improve up downtime command form properties

Use a flag instead of a enumeration in delete downtime command form, to remove needless boilerplate.

refs #8624
This commit is contained in:
Matthias Jentsch 2015-05-07 14:05:16 +02:00
parent b35dd4ddfe
commit ffd12e325c
3 changed files with 15 additions and 28 deletions

View File

@ -21,7 +21,7 @@ class DeleteDowntimeCommandForm extends CommandForm
$this->setAttrib('class', 'inline'); $this->setAttrib('class', 'inline');
} }
/** /**
* (non-PHPDoc) * (non-PHPDoc)
* @see \Icinga\Web\Form::createElements() For the method documentation. * @see \Icinga\Web\Form::createElements() For the method documentation.
*/ */

View File

@ -10,46 +10,38 @@ use Icinga\Module\Monitoring\Command\IcingaCommand;
*/ */
class DeleteDowntimeCommand extends IcingaCommand class DeleteDowntimeCommand extends IcingaCommand
{ {
/**
* Downtime for a host
*/
const DOWNTIME_TYPE_HOST = 'host';
/**
* Downtime for a service
*/
const DOWNTIME_TYPE_SERVICE = 'service';
/** /**
* ID of the downtime that is to be deleted * ID of the downtime that is to be deleted
* *
* @var int * @var int
*/ */
protected $downtimeId; protected $downtimeId;
/** /**
* If the command affects a service downtime
* *
* @var type * @var boolean
*/ */
protected $downtimeType = self::DOWNTIME_TYPE_HOST; protected $isService = false;
/** /**
* Set the downtime type, either host or service * Set if this command affects a service
* *
* @param string $type the downtime type * @param type $value
*/ */
public function setDowntimeType($type) public function setIsService($value = true)
{ {
$this->downtimeType = $type; $this->isService = (bool) $value;
} }
/** /**
* * Return whether the command affects a service
*
* @return type * @return type
*/ */
public function getDowntimeType() public function getIsService()
{ {
return $this->downtimeType; return $this->isService;
} }
/** /**

View File

@ -332,14 +332,9 @@ class IcingaCommandFileCommandRenderer implements IcingaCommandRendererInterface
public function renderDeleteDowntime(DeleteDowntimeCommand $command) public function renderDeleteDowntime(DeleteDowntimeCommand $command)
{ {
if ($command->getDowntimeType() === 'host') {
$commandString = 'DEL_HOST_DOWNTIME';
} else {
$commandString = 'DEL_SVC_DOWNTIME';
}
return sprintf( return sprintf(
'%s;%u', '%s;%u',
$commandString, $command->getIsService() ? 'DEL_SVC_DOWNTIME' : 'DEL_HOST_DOWNTIME',
$command->getDowntimeId() $command->getDowntimeId()
); );
} }