|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Zikula package. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright Zikula Foundation - http://zikula.org/ |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Zikula\GroupsModule\Container; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
15
|
|
|
use Zikula\Common\Translator\TranslatorInterface; |
|
16
|
|
|
use Zikula\Core\LinkContainer\LinkContainerInterface; |
|
17
|
|
|
use Zikula\GroupsModule\Entity\Repository\GroupApplicationRepository; |
|
18
|
|
|
use Zikula\GroupsModule\Entity\RepositoryInterface\GroupRepositoryInterface; |
|
19
|
|
|
use Zikula\PermissionsModule\Api\PermissionApi; |
|
20
|
|
|
|
|
21
|
|
|
class LinkContainer implements LinkContainerInterface |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var TranslatorInterface |
|
25
|
|
|
*/ |
|
26
|
|
|
private $translator; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var RouterInterface |
|
30
|
|
|
*/ |
|
31
|
|
|
private $router; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @var PermissionApi |
|
35
|
|
|
*/ |
|
36
|
|
|
private $permissionApi; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var GroupRepositoryInterface |
|
40
|
|
|
*/ |
|
41
|
|
|
private $groupRepository; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @var GroupApplicationRepository |
|
45
|
|
|
*/ |
|
46
|
|
|
private $groupApplicationRepository; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* LinkContainer constructor. |
|
50
|
|
|
* |
|
51
|
|
|
* @param TranslatorInterface $translator TranslatorInterface service instance |
|
52
|
|
|
* @param RouterInterface $router RouterInterface service instance |
|
53
|
|
|
* @param PermissionApi $permissionApi PermissionApi service instance |
|
54
|
|
|
* @param GroupRepositoryInterface $groupRepository |
|
55
|
|
|
* @param GroupApplicationRepository $groupApplicationRepository |
|
56
|
|
|
*/ |
|
57
|
|
|
public function __construct( |
|
58
|
|
|
TranslatorInterface $translator, |
|
59
|
|
|
RouterInterface $router, |
|
60
|
|
|
PermissionApi $permissionApi, |
|
61
|
|
|
GroupRepositoryInterface $groupRepository, |
|
62
|
|
|
GroupApplicationRepository $groupApplicationRepository |
|
63
|
|
|
) { |
|
64
|
|
|
$this->translator = $translator; |
|
65
|
|
|
$this->router = $router; |
|
66
|
|
|
$this->permissionApi = $permissionApi; |
|
67
|
|
|
$this->groupRepository = $groupRepository; |
|
68
|
|
|
$this->groupApplicationRepository = $groupApplicationRepository; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* get Links of any type for this extension |
|
73
|
|
|
* required by the interface |
|
74
|
|
|
* |
|
75
|
|
|
* @param string $type |
|
76
|
|
|
* @return array |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getLinks($type = LinkContainerInterface::TYPE_ADMIN) |
|
79
|
|
|
{ |
|
80
|
|
|
$method = 'get' . ucfirst(strtolower($type)); |
|
81
|
|
|
if (method_exists($this, $method)) { |
|
82
|
|
|
return $this->$method(); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return []; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* get the Admin links for this extension |
|
90
|
|
|
* |
|
91
|
|
|
* @return array |
|
92
|
|
|
*/ |
|
93
|
|
|
private function getAdmin() |
|
94
|
|
|
{ |
|
95
|
|
|
$links = []; |
|
96
|
|
|
|
|
97
|
|
|
if ($this->permissionApi->hasPermission($this->getBundleName() . '::', '::', ACCESS_EDIT)) { |
|
98
|
|
|
$links[] = [ |
|
99
|
|
|
'url' => $this->router->generate('zikulagroupsmodule_group_adminlist'), |
|
100
|
|
|
'text' => $this->translator->__('Groups list'), |
|
101
|
|
|
'icon' => 'list' |
|
102
|
|
|
]; |
|
103
|
|
|
} |
|
104
|
|
|
if ($this->permissionApi->hasPermission($this->getBundleName() . '::', '::', ACCESS_ADD)) { |
|
105
|
|
|
$links[] = [ |
|
106
|
|
|
'url' => $this->router->generate('zikulagroupsmodule_group_create'), |
|
107
|
|
|
'text' => $this->translator->__('New group'), |
|
108
|
|
|
'icon' => 'plus' |
|
109
|
|
|
]; |
|
110
|
|
|
} |
|
111
|
|
|
if ($this->permissionApi->hasPermission($this->getBundleName() . '::', '::', ACCESS_ADMIN)) { |
|
112
|
|
|
$links[] = [ |
|
113
|
|
|
'url' => $this->router->generate('zikulagroupsmodule_config_config'), |
|
114
|
|
|
'text' => $this->translator->__('Settings'), |
|
115
|
|
|
'icon' => 'wrench' |
|
116
|
|
|
]; |
|
117
|
|
|
} |
|
118
|
|
|
$apps = $this->groupApplicationRepository->findAll(); |
|
119
|
|
|
$appCount = count($apps); |
|
120
|
|
|
if (($appCount > 0) && $this->permissionApi->hasPermission($this->getBundleName() . '::', '::', ACCESS_EDIT)) { |
|
121
|
|
|
$links[] = [ |
|
122
|
|
|
'url' => $this->router->generate('zikulagroupsmodule_group_adminlist') . "#applications", |
|
123
|
|
|
'text' => $this->translator->__f('%n Pending applications', ['%n' => $appCount]), |
|
124
|
|
|
'icon' => 'exclamation-triangle' |
|
125
|
|
|
]; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return $links; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* get the Account links for this extension |
|
133
|
|
|
* |
|
134
|
|
|
* @return array |
|
135
|
|
|
*/ |
|
136
|
|
|
private function getUser() |
|
137
|
|
|
{ |
|
138
|
|
|
$links = []; |
|
139
|
|
|
$links[] = [ |
|
140
|
|
|
'url' => $this->router->generate('zikulagroupsmodule_group_list'), |
|
141
|
|
|
'text' => $this->translator->__('Group list'), |
|
142
|
|
|
'icon' => 'group' |
|
143
|
|
|
]; |
|
144
|
|
|
if ($this->permissionApi->hasPermission($this->getBundleName() . '::', '::', ACCESS_EDIT)) { |
|
145
|
|
|
$links[] = [ |
|
146
|
|
|
'url' => $this->router->generate('zikulagroupsmodule_group_adminlist'), |
|
147
|
|
|
'text' => $this->translator->__('Groups admin'), |
|
148
|
|
|
'icon' => 'wrench' |
|
149
|
|
|
]; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
return $links; |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* get the Account links for this extension |
|
157
|
|
|
* |
|
158
|
|
|
* @return array |
|
159
|
|
|
*/ |
|
160
|
|
|
private function getAccount() |
|
161
|
|
|
{ |
|
162
|
|
|
$links = []; |
|
163
|
|
|
|
|
164
|
|
|
// Check if there is at least one group to show |
|
165
|
|
|
$groups = $this->groupRepository->findAll(); |
|
166
|
|
|
if (count($groups) > 0) { |
|
167
|
|
|
$links[] = [ |
|
168
|
|
|
'url' => $this->router->generate('zikulagroupsmodule_group_list'), |
|
169
|
|
|
'text' => $this->translator->__('Groups manager'), |
|
170
|
|
|
'icon' => 'group' |
|
171
|
|
|
]; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
return $links; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* set the BundleName as required by the interface |
|
179
|
|
|
* |
|
180
|
|
|
* @return string |
|
181
|
|
|
*/ |
|
182
|
|
|
public function getBundleName() |
|
183
|
|
|
{ |
|
184
|
|
|
return 'ZikulaGroupsModule'; |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|