-
Notifications
You must be signed in to change notification settings - Fork 206
Expand file tree
/
Copy pathUsergroupController.php
More file actions
56 lines (48 loc) · 1.96 KB
/
Copy pathUsergroupController.php
File metadata and controls
56 lines (48 loc) · 1.96 KB
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
<?php
namespace Icinga\Module\Director\Controllers;
use gipfl\Web\Widget\Hint;
use Icinga\Module\Director\Forms\IcingaDeleteUsergroupForm;
use Icinga\Module\Director\Web\Controller\ObjectController;
use Icinga\Web\Notification;
use ipl\Web\Url;
class UsergroupController extends ObjectController
{
public function deleteAction(): void
{
$this->addTitle($this->translate('Delete Usergroup'));
$directMemberQuery = $this->db()
->select()
->from('icinga_usergroup_user')
->where('usergroup_id', $this->object->get('id'));
$appliedMemberQuery = $this->db()
->select()
->from('icinga_usergroup_user_resolved')
->where('usergroup_id', $this->object->get('id'));
if ($this->db()->count($directMemberQuery) > 0 || $this->db()->count($appliedMemberQuery) > 0) {
$this->content()->add(
Hint::info(sprintf(
$this->translate('The usergroup "%s" has members. Do you still want to delete it?'),
$this->object->getObjectName()
))
);
} else {
$this->content()->add(
Hint::info(sprintf(
$this->translate('The usergroup "%s" does not have any members. You can go ahead and delete it.'),
$this->object->getObjectName()
))
);
}
$this->content()->add(
(new IcingaDeleteUsergroupForm($this->object, $this->db(), $this->branch))
->on(IcingaDeleteUsergroupForm::ON_SUBMIT, function () {
Notification::success(sprintf(
$this->translate('User group %s has been deleted.'),
$this->object->getObjectName()
));
$this->redirectNow(Url::fromPath('director/usergroups'));
})
->handleRequest($this->getServerRequest())
);
}
}