-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavbarMenuItem.php
More file actions
122 lines (99 loc) · 2.38 KB
/
Copy pathNavbarMenuItem.php
File metadata and controls
122 lines (99 loc) · 2.38 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
namespace ADT\FancyAdmin\Model\Menu;
use ADT\FancyAdmin\Model\Security\SecurityUser;
use Nette\Application\UI\Component;
use Nette\Security\Resource;
class NavbarMenuItem
{
protected string $label = 'Test';
protected string $faIcon = 'chart-simple';
protected ?NavbarSubmenu $submenu = null;
protected ?string $link = null;
protected array $linkArgs = [];
protected ?Resource $resource = null;
public function getLabel(): string
{
return $this->label;
}
public function setLabel(string $label): self
{
$this->label = $label;
return $this;
}
public function getFaIcon(): string
{
return $this->faIcon;
}
public function setFaIcon(string $faIcon): self
{
$this->faIcon = $faIcon;
return $this;
}
public function getSubmenu(): ?NavbarSubmenu
{
return $this->submenu;
}
public function isEnabledSubmenu(SecurityUser $user): bool
{
$enabled = false;
if ($this->getAclResource() || count($this->getSubmenu()->getSubMenuItems()) === 0) {
return $user->isAllowed($this->getAclResource());
}
foreach ($this->getSubmenu()->getSubMenuItems() as $subMenuItem) {
if (!$subMenuItem->getAclResource() || $user->isAllowed($subMenuItem->getAclResource())) {
$enabled = true;
break;
}
}
return $enabled;
}
private function setSubmenu(NavbarSubmenu $submenu): self
{
$this->submenu = $submenu;
return $this;
}
public function getLink(): ?string
{
return $this->link;
}
public function setLink(string $link): self
{
$this->link = $link;
return $this;
}
public function getLinkArgs(): array
{
return $this->linkArgs;
}
public function setLinkArgs(array $linkArgs): self
{
$this->linkArgs = $linkArgs;
return $this;
}
public function setupSubmenuItems(callable $setupSubmenuItem): self
{
$submenu = $this->submenu ?? new NavbarSubmenu($this);
$setupSubmenuItem($submenu);
$this->setSubmenu($submenu);
return $this;
}
public function isCurrent(Component $presenter): bool {
if ($this->getSubmenu()) {
foreach ($this->getSubmenu()->getSubMenuItems() as $submenuItem) {
if ($submenuItem->isCurrent($presenter)) {
return true;
}
}
}
return $presenter->isLinkCurrent($this->getLink(), $this->getLinkArgs());
}
public function getAclResource(): ?Resource
{
return $this->resource;
}
public function setAclResource(?Resource $resource): self
{
$this->resource = $resource;
return $this;
}
}