|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace eXpansion\Framework\AdminGroups\Helpers; |
|
4
|
|
|
|
|
5
|
|
|
use eXpansion\Framework\AdminGroups\Services\AdminGroupConfiguration; |
|
6
|
|
|
use eXpansion\Framework\Core\Model\UserGroups\Group; |
|
7
|
|
|
use eXpansion\Framework\Core\Plugins\UserGroups\Factory; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class AdminGroupConfiguration |
|
11
|
|
|
* |
|
12
|
|
|
* @package eXpansion\Bundle\AdminGroupConfiguration\Helpers; |
|
13
|
|
|
* @author oliver de Cramer <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class AdminGroups |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var AdminGroupConfiguration */ |
|
18
|
|
|
protected $adminGroupConfiguration; |
|
19
|
|
|
|
|
20
|
|
|
/** @var Factory */ |
|
21
|
|
|
protected $userGroupFactory; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* GroupsPlugin constructor. |
|
25
|
|
|
* |
|
26
|
|
|
* @param AdminGroupConfiguration $adminGroupConfiguration |
|
27
|
|
|
* @param Factory $userGroupFactory |
|
28
|
|
|
*/ |
|
29
|
4 |
|
public function __construct( |
|
30
|
|
|
AdminGroupConfiguration $adminGroupConfiguration, |
|
31
|
|
|
Factory $userGroupFactory |
|
32
|
|
|
) { |
|
33
|
4 |
|
$this->adminGroupConfiguration = $adminGroupConfiguration; |
|
34
|
4 |
|
$this->userGroupFactory = $userGroupFactory; |
|
35
|
4 |
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Get list of all user groups. This is usefull for gui actions. |
|
39
|
|
|
* |
|
40
|
|
|
* @return Group[] |
|
41
|
|
|
*/ |
|
42
|
1 |
|
public function getUserGroups() |
|
43
|
|
|
{ |
|
44
|
1 |
|
$groups = []; |
|
45
|
1 |
|
foreach ($this->adminGroupConfiguration->getGroups() as $groupName) { |
|
46
|
1 |
|
$groups[] = $this->getUserGroup("$groupName"); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
1 |
|
return $groups; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Get the group in which a user is. This is usefull for gui actions. |
|
54
|
|
|
* |
|
55
|
|
|
* @param $login |
|
56
|
|
|
* |
|
57
|
|
|
* @return Group |
|
58
|
|
|
*/ |
|
59
|
1 |
|
public function getLoginUserGroups($login) |
|
60
|
|
|
{ |
|
61
|
1 |
|
$groupName = $this->adminGroupConfiguration->getLoginGroupName($login); |
|
62
|
1 |
|
if (empty($groupName)) { |
|
63
|
1 |
|
$groupName = 'guest'; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
1 |
|
return $this->getUserGroup("$groupName"); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
2 |
|
protected function getUserGroup($groupName) |
|
70
|
|
|
{ |
|
71
|
2 |
|
$groupName = "admin:$groupName"; |
|
72
|
|
|
|
|
73
|
2 |
|
$group = $this->userGroupFactory->getGroup($groupName); |
|
74
|
2 |
|
if (!$group) { |
|
75
|
2 |
|
$this->userGroupFactory->create($groupName); |
|
76
|
2 |
|
$group = $this->userGroupFactory->getGroup($groupName); |
|
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
2 |
|
return $group; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param $login |
|
84
|
|
|
* @param $permission |
|
85
|
|
|
* |
|
86
|
|
|
* @return bool |
|
87
|
|
|
*/ |
|
88
|
2 |
|
public function hasPermission($login, $permission) |
|
89
|
|
|
{ |
|
90
|
2 |
|
return $this->adminGroupConfiguration->hasPermission($login, $permission); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.