|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Routes. |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Zikula contributors (Zikula) |
|
6
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
|
7
|
|
|
* @author Zikula contributors <[email protected]>. |
|
8
|
|
|
* @link http://www.zikula.org |
|
9
|
|
|
* @link http://zikula.org |
|
10
|
|
|
* @version Generated by ModuleStudio 0.7.0 (http://modulestudio.de). |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Zikula\RoutesModule\Container\Base; |
|
14
|
|
|
|
|
15
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
16
|
|
|
use Zikula\Common\Translator\TranslatorInterface; |
|
17
|
|
|
use Zikula\Common\Translator\TranslatorTrait; |
|
18
|
|
|
use Zikula\Core\Doctrine\EntityAccess; |
|
19
|
|
|
use Zikula\Core\LinkContainer\LinkContainerInterface; |
|
20
|
|
|
use Zikula\PermissionsModule\Api\PermissionApi; |
|
21
|
|
|
use Zikula\UsersModule\Api\CurrentUserApi; |
|
22
|
|
|
use Zikula\RoutesModule\Helper\ControllerHelper; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* This is the link container service implementation class. |
|
26
|
|
|
*/ |
|
27
|
|
|
abstract class AbstractLinkContainer implements LinkContainerInterface |
|
28
|
|
|
{ |
|
29
|
|
|
use TranslatorTrait; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var RouterInterface |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $router; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var PermissionApi |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $permissionApi; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var ControllerHelper |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $controllerHelper; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var CurrentUserApi |
|
48
|
|
|
*/ |
|
49
|
|
|
private $currentUserApi; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Constructor. |
|
53
|
|
|
* Initialises member vars. |
|
54
|
|
|
* |
|
55
|
|
|
* @param TranslatorInterface $translator Translator service instance |
|
56
|
|
|
* @param Routerinterface $router Router service instance |
|
57
|
|
|
* @param PermissionApi $permissionApi PermissionApi service instance |
|
58
|
|
|
* @param ControllerHelper $controllerHelper ControllerHelper service instance |
|
59
|
|
|
* @param CurrentUserApi $currentUserApi CurrentUserApi service instance |
|
60
|
|
|
*/ |
|
61
|
|
View Code Duplication |
public function __construct(TranslatorInterface $translator, RouterInterface $router, PermissionApi $permissionApi, ControllerHelper $controllerHelper, CurrentUserApi $currentUserApi) |
|
|
|
|
|
|
62
|
|
|
{ |
|
63
|
|
|
$this->setTranslator($translator); |
|
64
|
|
|
$this->router = $router; |
|
65
|
|
|
$this->permissionApi = $permissionApi; |
|
66
|
|
|
$this->controllerHelper = $controllerHelper; |
|
67
|
|
|
$this->currentUserApi = $currentUserApi; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Sets the translator. |
|
72
|
|
|
* |
|
73
|
|
|
* @param TranslatorInterface $translator Translator service instance |
|
74
|
|
|
*/ |
|
75
|
|
|
public function setTranslator(/*TranslatorInterface */$translator) |
|
76
|
|
|
{ |
|
77
|
|
|
$this->translator = $translator; |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Returns available header links. |
|
82
|
|
|
* |
|
83
|
|
|
* @param string $type The type to collect links for |
|
84
|
|
|
* |
|
85
|
|
|
* @return array Array of header links |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getLinks($type = LinkContainerInterface::TYPE_ADMIN) |
|
88
|
|
|
{ |
|
89
|
|
|
$utilArgs = ['api' => 'linkContainer', 'action' => 'getLinks']; |
|
90
|
|
|
$allowedObjectTypes = $this->controllerHelper->getObjectTypes('api', $utilArgs); |
|
91
|
|
|
|
|
92
|
|
|
$permLevel = LinkContainerInterface::TYPE_ADMIN == $type ? ACCESS_ADMIN : ACCESS_READ; |
|
93
|
|
|
|
|
94
|
|
|
// Create an array of links to return |
|
95
|
|
|
$links = []; |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
View Code Duplication |
if (LinkContainerInterface::TYPE_ADMIN == $type) { |
|
|
|
|
|
|
99
|
|
|
if ($this->permissionApi->hasPermission($this->getBundleName() . '::', '::', ACCESS_READ)) { |
|
100
|
|
|
$links[] = [ |
|
101
|
|
|
'url' => $this->router->generate('zikularoutesmodule_user_index'), |
|
102
|
|
|
'text' => $this->__('Frontend'), |
|
103
|
|
|
'title' => $this->__('Switch to user area.'), |
|
104
|
|
|
'icon' => 'home' |
|
105
|
|
|
]; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
if (in_array('route', $allowedObjectTypes) |
|
109
|
|
|
&& $this->permissionApi->hasPermission($this->getBundleName() . ':Route:', '::', $permLevel)) { |
|
110
|
|
|
$links[] = [ |
|
111
|
|
|
'url' => $this->router->generate('zikularoutesmodule_route_adminview'), |
|
112
|
|
|
'text' => $this->__('Routes'), |
|
113
|
|
|
'title' => $this->__('Route list') |
|
114
|
|
|
]; |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
View Code Duplication |
if (LinkContainerInterface::TYPE_USER == $type) { |
|
|
|
|
|
|
118
|
|
|
if ($this->permissionApi->hasPermission($this->getBundleName() . '::', '::', ACCESS_ADMIN)) { |
|
119
|
|
|
$links[] = [ |
|
120
|
|
|
'url' => $this->router->generate('zikularoutesmodule_admin_index'), |
|
121
|
|
|
'text' => $this->__('Backend'), |
|
122
|
|
|
'title' => $this->__('Switch to administration area.'), |
|
123
|
|
|
'icon' => 'wrench' |
|
124
|
|
|
]; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
if (in_array('route', $allowedObjectTypes) |
|
128
|
|
|
&& $this->permissionApi->hasPermission($this->getBundleName() . ':Route:', '::', $permLevel)) { |
|
129
|
|
|
$links[] = [ |
|
130
|
|
|
'url' => $this->router->generate('zikularoutesmodule_route_view'), |
|
131
|
|
|
'text' => $this->__('Routes'), |
|
132
|
|
|
'title' => $this->__('Route list') |
|
133
|
|
|
]; |
|
134
|
|
|
} |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
return $links; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Returns the name of the providing bundle. |
|
142
|
|
|
* |
|
143
|
|
|
* @return string The bundle name |
|
144
|
|
|
*/ |
|
145
|
|
|
public function getBundleName() |
|
146
|
|
|
{ |
|
147
|
|
|
return 'ZikulaRoutesModule'; |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.