1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* WebHemi. |
4
|
|
|
* |
5
|
|
|
* PHP version 7.1 |
6
|
|
|
* |
7
|
|
|
* @copyright 2012 - 2018 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\Data\Storage; |
15
|
|
|
|
16
|
|
|
use WebHemi\Data\Entity\EntitySet; |
17
|
|
|
use WebHemi\Data\Entity\PolicyEntity; |
18
|
|
|
use WebHemi\Data\Query\QueryInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class PolicyStorage. |
22
|
|
|
*/ |
23
|
|
|
class PolicyStorage extends AbstractStorage |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Returns a full set of policy data. |
27
|
|
|
* |
28
|
|
|
* @param int $limit |
29
|
|
|
* @param int $offset |
30
|
|
|
* @return EntitySet |
31
|
|
|
*/ |
32
|
|
|
public function getPolicyList( |
33
|
|
|
int $limit = QueryInterface::MAX_ROW_LIMIT, |
34
|
|
|
int $offset = 0 |
35
|
|
|
) : EntitySet { |
36
|
|
|
$this->normalizeLimitAndOffset($limit, $offset); |
37
|
|
|
|
38
|
|
|
$data = $this->getQueryAdapter()->fetchData( |
39
|
|
|
'getPolicyList', |
40
|
|
|
[ |
41
|
|
|
':limit' => $limit, |
42
|
|
|
':offset' => $offset |
43
|
|
|
] |
44
|
|
|
); |
45
|
|
|
|
46
|
|
|
return $this->getEntitySet(PolicyEntity::class, $data); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Returns a set of policy data identified by resource ID. |
51
|
|
|
* |
52
|
|
|
* @param int $resourceId |
53
|
|
|
* @param int $limit |
54
|
|
|
* @param int $offset |
55
|
|
|
* @return EntitySet |
56
|
|
|
*/ |
57
|
|
|
public function getPolicyListByResource( |
58
|
|
|
int $resourceId, |
59
|
|
|
int $limit = QueryInterface::MAX_ROW_LIMIT, |
60
|
|
|
int $offset = 0 |
61
|
|
|
) : EntitySet { |
62
|
|
|
$this->normalizeLimitAndOffset($limit, $offset); |
63
|
|
|
|
64
|
|
|
$data = $this->getQueryAdapter()->fetchData( |
65
|
|
|
'getPolicyListByResource', |
66
|
|
|
[ |
67
|
|
|
':idResource' => $resourceId, |
68
|
|
|
':limit' => $limit, |
69
|
|
|
':offset' => $offset |
70
|
|
|
] |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
return $this->getEntitySet(PolicyEntity::class, $data); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Returns a set of policy data identified by application ID. |
78
|
|
|
* |
79
|
|
|
* @param int $applicationId |
80
|
|
|
* @param int $limit |
81
|
|
|
* @param int $offset |
82
|
|
|
* @return EntitySet |
83
|
|
|
*/ |
84
|
|
|
public function getPolicyListByApplication( |
85
|
|
|
int $applicationId, |
86
|
|
|
int $limit = QueryInterface::MAX_ROW_LIMIT, |
87
|
|
|
int $offset = 0 |
88
|
|
|
) : EntitySet { |
89
|
|
|
$this->normalizeLimitAndOffset($limit, $offset); |
90
|
|
|
|
91
|
|
|
$data = $this->getQueryAdapter()->fetchData( |
92
|
|
|
'getPolicyListByApplication', |
93
|
|
|
[ |
94
|
|
|
':idApplication' => $applicationId, |
95
|
|
|
':limit' => $limit, |
96
|
|
|
':offset' => $offset |
97
|
|
|
] |
98
|
|
|
); |
99
|
|
|
|
100
|
|
|
return $this->getEntitySet(PolicyEntity::class, $data); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Returns a set of policy data identified by user ID. |
105
|
|
|
* |
106
|
|
|
* @param int $userId |
107
|
|
|
* @param int $limit |
108
|
|
|
* @param int $offset |
109
|
|
|
* @return EntitySet |
110
|
|
|
*/ |
111
|
1 |
|
public function getPolicyListByUser( |
112
|
|
|
int $userId, |
113
|
|
|
int $limit = QueryInterface::MAX_ROW_LIMIT, |
114
|
|
|
int $offset = 0 |
115
|
|
|
) : EntitySet { |
116
|
1 |
|
$this->normalizeLimitAndOffset($limit, $offset); |
117
|
|
|
|
118
|
1 |
|
$data = $this->getQueryAdapter()->fetchData( |
119
|
1 |
|
'getPolicyListByUser', |
120
|
|
|
[ |
121
|
1 |
|
':idUser' => $userId, |
122
|
1 |
|
':limit' => $limit, |
123
|
1 |
|
':offset' => $offset |
124
|
|
|
] |
125
|
|
|
); |
126
|
|
|
|
127
|
1 |
|
return $this->getEntitySet(PolicyEntity::class, $data); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Returns a set of policy data identified by user group ID. |
132
|
|
|
* |
133
|
|
|
* @param int $userGroupId |
134
|
|
|
* @param int $limit |
135
|
|
|
* @param int $offset |
136
|
|
|
* @return EntitySet |
137
|
|
|
*/ |
138
|
1 |
|
public function getPolicyListByUserGroup( |
139
|
|
|
int $userGroupId, |
140
|
|
|
int $limit = QueryInterface::MAX_ROW_LIMIT, |
141
|
|
|
int $offset = 0 |
142
|
|
|
) : EntitySet { |
143
|
1 |
|
$this->normalizeLimitAndOffset($limit, $offset); |
144
|
|
|
|
145
|
1 |
|
$data = $this->getQueryAdapter()->fetchData( |
146
|
1 |
|
'getPolicyListByUserGroup', |
147
|
|
|
[ |
148
|
1 |
|
':idUserGroup' => $userGroupId, |
149
|
1 |
|
':limit' => $limit, |
150
|
1 |
|
':offset' => $offset |
151
|
|
|
] |
152
|
|
|
); |
153
|
|
|
|
154
|
1 |
|
return $this->getEntitySet(PolicyEntity::class, $data); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Returns a set of policy data identified by both resource and application IDs. |
159
|
|
|
* |
160
|
|
|
* @param int $resourceId |
161
|
|
|
* @param int $applicationId |
162
|
|
|
* @param int $limit |
163
|
|
|
* @param int $offset |
164
|
|
|
* @return EntitySet |
165
|
|
|
*/ |
166
|
|
|
public function getPolicyListByResourceAndApplication( |
167
|
|
|
int $resourceId, |
168
|
|
|
int $applicationId, |
169
|
|
|
int $limit = QueryInterface::MAX_ROW_LIMIT, |
170
|
|
|
int $offset = 0 |
171
|
|
|
) : EntitySet { |
172
|
|
|
$this->normalizeLimitAndOffset($limit, $offset); |
173
|
|
|
|
174
|
|
|
$data = $this->getQueryAdapter()->fetchData( |
175
|
|
|
'getPolicyListByResourceAndApplication', |
176
|
|
|
[ |
177
|
|
|
':idResource' => $resourceId, |
178
|
|
|
':idApplication' => $applicationId, |
179
|
|
|
':limit' => $limit, |
180
|
|
|
':offset' => $offset |
181
|
|
|
] |
182
|
|
|
); |
183
|
|
|
|
184
|
|
|
return $this->getEntitySet(PolicyEntity::class, $data); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Returns policy data identified by (unique) ID. |
189
|
|
|
* |
190
|
|
|
* @param int $identifier |
191
|
|
|
* @return null|PolicyEntity |
192
|
|
|
*/ |
193
|
|
|
public function getPolicyById(int $identifier) : ? PolicyEntity |
194
|
|
|
{ |
195
|
|
|
$data = $this->getQueryAdapter()->fetchData( |
196
|
|
|
'getPolicyById', |
197
|
|
|
[ |
198
|
|
|
':idPolicy' => $identifier |
199
|
|
|
] |
200
|
|
|
); |
201
|
|
|
|
202
|
|
|
/** @var null|PolicyEntity $entity */ |
203
|
|
|
$entity = $this->getEntity(PolicyEntity::class, $data[0] ?? []); |
204
|
|
|
|
205
|
|
|
return $entity; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Returns policy data by name. |
210
|
|
|
* |
211
|
|
|
* @param string $name |
212
|
|
|
* @return null|PolicyEntity |
213
|
|
|
*/ |
214
|
|
|
public function getPolicyByName(string $name) : ? PolicyEntity |
215
|
|
|
{ |
216
|
|
|
$data = $this->getQueryAdapter()->fetchData( |
217
|
|
|
'getPolicyByName', |
218
|
|
|
[ |
219
|
|
|
':name' => $name |
220
|
|
|
] |
221
|
|
|
); |
222
|
|
|
|
223
|
|
|
/** @var null|PolicyEntity $entity */ |
224
|
|
|
$entity = $this->getEntity(PolicyEntity::class, $data[0] ?? []); |
225
|
|
|
|
226
|
|
|
return $entity; |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
|