-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContactController.php
51 lines (41 loc) · 1.6 KB
/
ContactController.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
<?php
/* Icinga Notifications Web | (c) 2023 Icinga GmbH | GPLv2 */
namespace Icinga\Module\Notifications\Controllers;
use Icinga\Module\Notifications\Common\Database;
use Icinga\Module\Notifications\Model\Contact;
use Icinga\Module\Notifications\Web\Form\ContactForm;
use Icinga\Web\Notification;
use ipl\Html\FormElement\FieldsetElement;
use ipl\Sql\Connection;
use ipl\Stdlib\Filter;
use ipl\Web\Compat\CompatController;
class ContactController extends CompatController
{
public function init(): void
{
$this->assertPermission('notifications/config/contacts');
}
public function indexAction(): void
{
$contactId = $this->params->getRequired('id');
$form = (new ContactForm(Database::get()))
->loadContact($contactId)
->on(ContactForm::ON_SUCCESS, function (ContactForm $form) {
$form->editContact();
Notification::success(sprintf(
t('Contact "%s" has successfully been saved'),
$form->getContactName()
));
$this->redirectNow('__CLOSE__');
})->on(ContactForm::ON_REMOVE, function (ContactForm $form) {
$form->removeContact();
Notification::success(sprintf(
t('Removed contact "%s" successfully'),
$form->getContactName()
));
$this->redirectNow('__CLOSE__');
})->handleRequest($this->getServerRequest());
$this->addTitleTab(sprintf(t('Contact: %s'), $form->getContactName()));
$this->addContent($form);
}
}