|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* WebHemi. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 7.1 |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright 2012 - 2017 Gixx-web (http://www.gixx-web.com) |
|
8
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License (MIT) |
|
9
|
|
|
* |
|
10
|
|
|
* @link http://www.gixx-web.com |
|
11
|
|
|
*/ |
|
12
|
|
|
declare(strict_types = 1); |
|
13
|
|
|
|
|
14
|
|
|
namespace WebHemi\Middleware\Action\Admin\ControlPanel\Groups; |
|
15
|
|
|
|
|
16
|
|
|
use RuntimeException; |
|
17
|
|
|
use WebHemi\Configuration\ServiceInterface as ConfigurationInterface; |
|
18
|
|
|
use WebHemi\Data\Entity\User\UserGroupEntity; |
|
19
|
|
|
use WebHemi\Data\Storage\User\UserGroupStorage; |
|
20
|
|
|
use WebHemi\DateTime; |
|
21
|
|
|
use WebHemi\Environment\ServiceInterface as EnvironmentInterface; |
|
22
|
|
|
use WebHemi\Middleware\Action\AbstractMiddlewareAction; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class ViewAction |
|
26
|
|
|
*/ |
|
27
|
|
|
class ViewAction extends AbstractMiddlewareAction |
|
28
|
|
|
{ |
|
29
|
|
|
/** @var ConfigurationInterface */ |
|
30
|
|
|
protected $configuration; |
|
31
|
|
|
/** @var EnvironmentInterface */ |
|
32
|
|
|
protected $environmentManager; |
|
33
|
|
|
/** @var UserGroupStorage */ |
|
34
|
|
|
protected $userGroupStorage; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* GroupManagementAction constructor. |
|
38
|
|
|
* |
|
39
|
|
|
* @param ConfigurationInterface $configuration |
|
40
|
|
|
* @param EnvironmentInterface $environmentManager |
|
41
|
|
|
* @param UserGroupStorage $userGroupStorage |
|
42
|
|
|
*/ |
|
43
|
|
|
public function __construct( |
|
44
|
|
|
ConfigurationInterface $configuration, |
|
45
|
|
|
EnvironmentInterface $environmentManager, |
|
46
|
|
|
UserGroupStorage $userGroupStorage |
|
47
|
|
|
) { |
|
48
|
|
|
$this->configuration = $configuration; |
|
49
|
|
|
$this->environmentManager = $environmentManager; |
|
50
|
|
|
$this->userGroupStorage = $userGroupStorage; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Gets template map name or template file path. |
|
55
|
|
|
* |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getTemplateName() : string |
|
59
|
|
|
{ |
|
60
|
|
|
return 'admin-control-panel-groups-view'; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Gets template data. |
|
65
|
|
|
* |
|
66
|
|
|
* @return array |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getTemplateData() : array |
|
69
|
|
|
{ |
|
70
|
|
|
$data = null; |
|
71
|
|
|
|
|
72
|
|
|
$params = $this->getRoutingParameters(); |
|
73
|
|
|
|
|
74
|
|
|
if (isset($params['userGroupId'])) { |
|
75
|
|
|
$data = $this->getUserGroupDetails((int) $params['userGroupId']); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return [ |
|
79
|
|
|
'data' => $data |
|
80
|
|
|
]; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Gets user group details. |
|
85
|
|
|
* |
|
86
|
|
|
* @param int $userGroupId |
|
87
|
|
|
* @return array |
|
88
|
|
|
* @throws RuntimeException |
|
89
|
|
|
*/ |
|
90
|
|
|
protected function getUserGroupDetails(int $userGroupId) : array |
|
91
|
|
|
{ |
|
92
|
|
|
$userGroupEntity = $this->userGroupStorage->getUserGroupById($userGroupId); |
|
93
|
|
|
|
|
94
|
|
|
if (!$userGroupEntity instanceof UserGroupEntity) { |
|
95
|
|
|
throw new RuntimeException( |
|
96
|
|
|
sprintf( |
|
97
|
|
|
'The requested user group entity with the given ID not found: %s', |
|
98
|
|
|
(string) $userGroupId |
|
99
|
|
|
), |
|
100
|
|
|
404 |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
$data = [ |
|
105
|
|
|
'readonly' => $userGroupEntity->getReadOnly(), |
|
106
|
|
|
'group' => [ |
|
107
|
|
|
'Id' => $userGroupEntity->getUserGroupId(), |
|
108
|
|
|
'Name' => $userGroupEntity->getName(), |
|
109
|
|
|
'Title' => $userGroupEntity->getTitle(), |
|
110
|
|
|
'Description' => $userGroupEntity->getDescription(), |
|
111
|
|
|
'Is read-only?' => $userGroupEntity->getReadOnly() ? 'Yes' : 'No', |
|
112
|
|
|
'Date created' => $userGroupEntity->getDateCreated()->format('Y-m-d H:i:s'), |
|
113
|
|
|
], |
|
114
|
|
|
]; |
|
115
|
|
|
|
|
116
|
|
|
$dateModified = $userGroupEntity->getDateModified(); |
|
117
|
|
|
|
|
118
|
|
|
if (!$userGroupEntity->getReadOnly() && $dateModified instanceof DateTime) { |
|
119
|
|
|
$data['group']['Date modified'] = $dateModified->format('Y-m-d H:i:s'); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
return $data; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|