-
Notifications
You must be signed in to change notification settings - Fork 275
/
DisableNotificationsExpireCommandForm.php
76 lines (71 loc) · 2.37 KB
/
DisableNotificationsExpireCommandForm.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Monitoring\Form\Command\Instance;
use DateTime;
use DateInterval;
use Icinga\Module\Monitoring\Command\Instance\DisableNotificationsExpireCommand;
use Icinga\Module\Monitoring\Form\Command\CommandForm;
use Icinga\Web\Form\Element\DateTimePicker;
use Icinga\Web\Form\Element\Note;
use Icinga\Web\Notification;
use Icinga\Web\Request;
/**
* Form for disabling host and service notifications w/ an optional expire date and time on an Icinga instance
*/
class DisableNotificationsExpireCommandForm extends CommandForm
{
/**
* (non-PHPDoc)
* @see \Zend_Form::init() For the method documentation.
*/
public function init()
{
$this->setSubmitLabel(mt('monitoring', 'Disable Notifications'));
}
/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::createElements() For the method documentation.
*/
public function createElements(array $formData = array())
{
$this->addElement(
new Note(
'command-info',
array(
'value' => mt(
'monitoring',
'This command is used to disable host and service notifications for a specific time.'
)
)
)
);
$expireTime = new DateTime();
$expireTime->add(new DateInterval('PT1H'));
$this->addElement(
new DateTimePicker(
'expire_time',
array(
'required' => true,
'label' => mt('monitoring', 'Expire Time'),
'description' => mt('monitoring', 'Set the expire time.'),
'value' => $expireTime
)
)
);
return $this;
}
/**
* (non-PHPDoc)
* @see \Icinga\Web\Form::onSuccess() For the method documentation.
*/
public function onSuccess(Request $request)
{
$disableNotifications = new DisableNotificationsExpireCommand();
$disableNotifications
->setExpireTime($this->getElement('expire_time')->getValue()->getTimestamp());
$this->getTransport($request)->send($disableNotifications);
Notification::success(mt('monitoring', 'Disabling host and service notifications..'));
return true;
}
}