|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the Zikula package. |
|
7
|
|
|
* |
|
8
|
|
|
* Copyright Zikula - https://ziku.la/ |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Zikula\UsersBundle\Helper; |
|
15
|
|
|
|
|
16
|
|
|
use Symfony\Component\DependencyInjection\Attribute\Autowire; |
|
17
|
|
|
use Zikula\UsersBundle\UsersConstant; |
|
18
|
|
|
|
|
19
|
|
|
class ChoiceHelper |
|
20
|
|
|
{ |
|
21
|
|
|
private array $roleHierarchy; |
|
22
|
|
|
|
|
23
|
|
|
public function __construct( |
|
24
|
|
|
#[Autowire(param: 'security.role_hierarchy.roles')] |
|
25
|
|
|
array $roleHierarchy |
|
26
|
|
|
) { |
|
27
|
|
|
$this->roleHierarchy = $roleHierarchy; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function getRoles(): array |
|
31
|
|
|
{ |
|
32
|
|
|
$systemRoles = [ |
|
33
|
|
|
'User' => 'ROLE_USER', |
|
34
|
|
|
'Editor' => 'ROLE_EDITOR', |
|
35
|
|
|
'Administrator' => 'ROLE_ADMIN', |
|
36
|
|
|
'Super administrator' => 'ROLE_SUPER_ADMIN', |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
$definedRoles = []; |
|
40
|
|
|
array_walk_recursive($this->roleHierarchy, static function ($role) use (&$roles) { |
|
41
|
|
|
$definedRoles[$role] = $role; |
|
|
|
|
|
|
42
|
|
|
}); |
|
43
|
|
|
|
|
44
|
|
|
$roles = $systemRoles; |
|
45
|
|
|
foreach ($definedRoles as $role) { |
|
46
|
|
|
if (!in_array($role, $roles, true)) { |
|
47
|
|
|
$roles[$role] = $role; |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return $roles; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function getActivatedValues(): array |
|
55
|
|
|
{ |
|
56
|
|
|
return [ |
|
57
|
|
|
'Active' => UsersConstant::ACTIVATED_ACTIVE, |
|
58
|
|
|
'Inactive' => UsersConstant::ACTIVATED_INACTIVE, |
|
59
|
|
|
'Pending' => UsersConstant::ACTIVATED_PENDING_REG, |
|
60
|
|
|
]; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|