|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* WebHemi. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5.6 |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright 2012 - 2016 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
|
|
|
namespace WebHemi\Data\Storage\AccessManagement; |
|
13
|
|
|
|
|
14
|
|
|
use DateTime; |
|
15
|
|
|
use WebHemi\Data\Entity\DataEntityInterface; |
|
16
|
|
|
use WebHemi\Data\Entity\AccessManagement\PolicyEntity; |
|
17
|
|
|
use WebHemi\Data\Storage\AbstractDataStorage; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class PolicyStorage. |
|
21
|
|
|
*/ |
|
22
|
|
|
class PolicyStorage extends AbstractDataStorage |
|
23
|
|
|
{ |
|
24
|
|
|
/** @var string */ |
|
25
|
|
|
protected $dataGroup = 'webhemi_am_policy'; |
|
26
|
|
|
/** @var string */ |
|
27
|
|
|
protected $idKey = 'id_am_policy'; |
|
28
|
|
|
/** @var string */ |
|
29
|
|
|
private $resourceId = 'fk_am_resource'; |
|
30
|
|
|
/** @var string */ |
|
31
|
|
|
private $applicationId = 'fk_application'; |
|
32
|
|
|
/** @var string */ |
|
33
|
|
|
private $title = 'title'; |
|
34
|
|
|
/** @var string */ |
|
35
|
|
|
private $description = 'description'; |
|
36
|
|
|
/** @var string */ |
|
37
|
|
|
private $isReadOnly = 'is_read_only'; |
|
38
|
|
|
/** @var string */ |
|
39
|
|
|
private $isAllowed = 'is_allowed'; |
|
40
|
|
|
/** @var string */ |
|
41
|
|
|
private $dateCreated = 'date_created'; |
|
42
|
|
|
/** @var string */ |
|
43
|
|
|
private $dateModified = 'date_modified'; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Populates an entity with storage data. |
|
47
|
|
|
* |
|
48
|
|
|
* @param DataEntityInterface $entity |
|
49
|
|
|
* @param array $data |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function populateEntity(DataEntityInterface &$entity, array $data) |
|
52
|
|
|
{ |
|
53
|
|
|
/* @var PolicyEntity $entity */ |
|
54
|
|
|
$entity->setPolicyId($data[$this->idKey]) |
|
55
|
|
|
->setResourceId($data[$this->resourceId]) |
|
56
|
|
|
->setApplicationId($data[$this->applicationId]) |
|
57
|
|
|
->setTitle($data[$this->title]) |
|
58
|
|
|
->setDescription($data[$this->description]) |
|
59
|
|
|
->setReadOnly($data[$this->isReadOnly]) |
|
60
|
|
|
->setAllowed($data[$this->isAllowed]) |
|
61
|
|
|
->setDateCreated(new DateTime($data[$this->dateCreated])) |
|
62
|
|
|
->setDateModified(new DateTime($data[$this->dateModified])); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Returns a Policy entity identified by (unique) ID. |
|
67
|
|
|
* |
|
68
|
|
|
* @param int $identifier |
|
69
|
|
|
* |
|
70
|
|
|
* @return bool|PolicyEntity |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getPolicyById($identifier) |
|
73
|
|
|
{ |
|
74
|
|
|
$entity = false; |
|
75
|
|
|
$data = $this->getDataAdapter()->getData($identifier); |
|
76
|
|
|
|
|
77
|
|
|
if (!empty($data)) { |
|
78
|
|
|
$entity = $this->createEntity(); |
|
79
|
|
|
$this->populateEntity($entity, $data); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $entity; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|