/**
  * (non-PHPDoc)
  * @see \Icinga\Web\Form::onSuccess() For the method documentation.
  */
 public function onSuccess()
 {
     foreach ($this->objects as $object) {
         /** @var \Icinga\Module\Monitoring\Object\Host $object */
         $childHosts = (int) $this->getElement('child_hosts')->getValue();
         $allServices = $this->getElement('all_services')->isChecked();
         if ($childHosts === 0) {
             $hostDowntime = new ScheduleHostDowntimeCommand();
             if ($allServices === true) {
                 $hostDowntime->setForAllServices();
             }
         } else {
             $hostDowntime = new PropagateHostDowntimeCommand();
             if ($childHosts === 1) {
                 $hostDowntime->setTriggered();
             }
             if ($allServices === true) {
                 foreach ($object->services as $service) {
                     $serviceDowntime = new ScheduleServiceDowntimeCommand();
                     $serviceDowntime->setObject($service);
                     $this->scheduleDowntime($serviceDowntime, $this->request);
                 }
             }
         }
         $hostDowntime->setObject($object);
         $this->scheduleDowntime($hostDowntime, $this->request);
     }
     Notification::success($this->translatePlural('Scheduling host downtime..', 'Scheduling host downtimes..', count($this->objects)));
     return true;
 }
 /**
  * (non-PHPDoc)
  * @see \Icinga\Web\Form::onSuccess() For the method documentation.
  */
 public function onSuccess()
 {
     foreach ($this->objects as $object) {
         /** @var \Icinga\Module\Monitoring\Object\Service $object */
         $downtime = new ScheduleServiceDowntimeCommand();
         $downtime->setObject($object);
         $this->scheduleDowntime($downtime, $this->request);
     }
     Notification::success($this->translatePlural('Scheduling service downtime..', 'Scheduling service downtimes..', count($this->objects)));
     return true;
 }
 /**
  * (non-PHPDoc)
  * @see \Icinga\Web\Form::onSuccess() For the method documentation.
  */
 public function onSuccess()
 {
     $end = $this->getValue('end')->getTimestamp();
     if ($end <= $this->getValue('start')->getTimestamp()) {
         $endElement = $this->_elements['end'];
         $endElement->setValue($endElement->getValue()->format($endElement->getFormat()));
         $endElement->addError($this->translate('The end time must be greater than the start time'));
         return false;
     }
     $now = new DateTime();
     if ($end <= $now->getTimestamp()) {
         $endElement = $this->_elements['end'];
         $endElement->setValue($endElement->getValue()->format($endElement->getFormat()));
         $endElement->addError($this->translate('A downtime must not be in the past'));
         return false;
     }
     foreach ($this->objects as $object) {
         /** @var \Icinga\Module\Monitoring\Object\Host $object */
         if (($childHostsEl = $this->getElement('child_hosts')) !== null) {
             $childHosts = (int) $childHostsEl->getValue();
         } else {
             $childHosts = 0;
         }
         $allServices = $this->getElement('all_services')->isChecked();
         if ($childHosts === 0) {
             $hostDowntime = new ScheduleHostDowntimeCommand();
             if ($allServices === true) {
                 $hostDowntime->setForAllServices();
             }
         } else {
             $hostDowntime = new PropagateHostDowntimeCommand();
             if ($childHosts === 1) {
                 $hostDowntime->setTriggered();
             }
             if ($allServices === true) {
                 foreach ($object->services as $service) {
                     $serviceDowntime = new ScheduleServiceDowntimeCommand();
                     $serviceDowntime->setObject($service);
                     $this->scheduleDowntime($serviceDowntime, $this->request);
                 }
             }
         }
         $hostDowntime->setObject($object);
         $this->scheduleDowntime($hostDowntime, $this->request);
     }
     Notification::success($this->translatePlural('Scheduling host downtime..', 'Scheduling host downtimes..', count($this->objects)));
     return true;
 }
 public function renderScheduleDowntime(ScheduleServiceDowntimeCommand $command)
 {
     $object = $command->getObject();
     if ($command->getObject()->getType() === $command::TYPE_HOST) {
         /** @var \Icinga\Module\Monitoring\Object\Host $object */
         /** @var \Icinga\Module\Monitoring\Command\Object\ScheduleHostDowntimeCommand $command */
         if ($command instanceof PropagateHostDowntimeCommand) {
             /** @var \Icinga\Module\Monitoring\Command\Object\PropagateHostDowntimeCommand $command */
             $commandName = $command->getTriggered() === true ? 'SCHEDULE_AND_PROPAGATE_TRIGGERED_HOST_DOWNTIME' : 'SCHEDULE_AND_PROPAGATE_HOST_DOWNTIME';
         } elseif ($command->getForAllServices() === true) {
             $commandName = 'SCHEDULE_HOST_SVC_DOWNTIME';
         } else {
             $commandName = 'SCHEDULE_HOST_DOWNTIME';
         }
         $commandString = sprintf('%s;%s', $commandName, $object->getName());
     } else {
         /** @var \Icinga\Module\Monitoring\Object\Service $object */
         $commandString = sprintf('%s;%s;%s', 'SCHEDULE_SVC_DOWNTIME', $object->getHost()->getName(), $object->getName());
     }
     return sprintf('%s;%u;%u;%u;%u;%u;%s;%s', $commandString, $command->getStart(), $command->getEnd(), $command->getFixed(), $command->getTriggerId(), $command->getDuration(), $command->getAuthor(), $command->getComment());
 }
 /**
  * (non-PHPDoc)
  * @see \Icinga\Web\Form::onSuccess() For the method documentation.
  */
 public function onSuccess()
 {
     $end = $this->getValue('end')->getTimestamp();
     if ($end <= $this->getValue('start')->getTimestamp()) {
         $endElement = $this->_elements['end'];
         $endElement->setValue($endElement->getValue()->format($endElement->getFormat()));
         $endElement->addError($this->translate('The end time must be greater than the start time'));
         return false;
     }
     $now = new DateTime();
     if ($end <= $now->getTimestamp()) {
         $endElement = $this->_elements['end'];
         $endElement->setValue($endElement->getValue()->format($endElement->getFormat()));
         $endElement->addError($this->translate('A downtime must not be in the past'));
         return false;
     }
     foreach ($this->objects as $object) {
         /** @var \Icinga\Module\Monitoring\Object\Service $object */
         $downtime = new ScheduleServiceDowntimeCommand();
         $downtime->setObject($object);
         $this->scheduleDowntime($downtime, $this->request);
     }
     Notification::success($this->translatePlural('Scheduling service downtime..', 'Scheduling service downtimes..', count($this->objects)));
     return true;
 }
 public function renderScheduleDowntime(ScheduleServiceDowntimeCommand $command)
 {
     $endpoint = 'actions/schedule-downtime';
     $data = array('author' => $command->getAuthor(), 'comment' => $command->getComment(), 'start_time' => $command->getStart(), 'end_time' => $command->getEnd(), 'duration' => $command->getDuration(), 'fixed' => $command->getFixed(), 'trigger_name' => $command->getTriggerId());
     $commandData = $data;
     if ($command instanceof PropagateHostDowntimeCommand) {
         /** @var \Icinga\Module\Monitoring\Command\Object\PropagateHostDowntimeCommand $command */
         $commandData['child_options'] = $command->getTriggered() ? 1 : 2;
     }
     $this->applyFilter($commandData, $command->getObject());
     $apiCommand = IcingaApiCommand::create($endpoint, $commandData);
     if ($command instanceof ScheduleHostDowntimeCommand && $command->getForAllServices()) {
         $commandData = $data + array('type' => 'Service', 'filter' => 'host.name == host_name', 'filter_vars' => array('host_name' => $command->getObject()->getName()));
         $apiCommand->setNext(IcingaApiCommand::create($endpoint, $commandData));
     }
     return $apiCommand;
 }