| @@ 22-121 (lines=100) @@ | ||
| 19 | /** |
|
| 20 | * Class ResourceStorage. |
|
| 21 | */ |
|
| 22 | class ResourceStorage extends AbstractDataStorage |
|
| 23 | { |
|
| 24 | /** @var string */ |
|
| 25 | protected $dataGroup = 'webhemi_am_resource'; |
|
| 26 | /** @var string */ |
|
| 27 | protected $idKey = 'id_am_resource'; |
|
| 28 | /** @var string */ |
|
| 29 | private $name = 'name'; |
|
| 30 | /** @var string */ |
|
| 31 | private $title = 'title'; |
|
| 32 | /** @var string */ |
|
| 33 | private $description = 'description'; |
|
| 34 | /** @var string */ |
|
| 35 | private $isReadOnly = 'is_read_only'; |
|
| 36 | /** @var string */ |
|
| 37 | private $dateCreated = 'date_created'; |
|
| 38 | /** @var string */ |
|
| 39 | private $dateModified = 'date_modified'; |
|
| 40 | ||
| 41 | /** |
|
| 42 | * Populates an entity with storage data. |
|
| 43 | * |
|
| 44 | * @param DataEntityInterface $entity |
|
| 45 | * @param array $data |
|
| 46 | */ |
|
| 47 | protected function populateEntity(DataEntityInterface &$entity, array $data) |
|
| 48 | { |
|
| 49 | /* @var ResourceEntity $entity */ |
|
| 50 | $entity->setResourceId($data[$this->idKey]) |
|
| 51 | ->setName($data[$this->name]) |
|
| 52 | ->setTitle($data[$this->title]) |
|
| 53 | ->setDescription($data[$this->description]) |
|
| 54 | ->setReadOnly($data[$this->isReadOnly]) |
|
| 55 | ->setDateCreated(new DateTime($data[$this->dateCreated])) |
|
| 56 | ->setDateModified(new DateTime($data[$this->dateModified])); |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * Get data from an entity. |
|
| 61 | * |
|
| 62 | * @param DataEntityInterface $entity |
|
| 63 | * @return array |
|
| 64 | */ |
|
| 65 | protected function getEntityData(DataEntityInterface $entity) |
|
| 66 | { |
|
| 67 | /** @var ResourceEntity $entity */ |
|
| 68 | $dateCreated = $entity->getDateCreated(); |
|
| 69 | $dateModified = $entity->getDateModified(); |
|
| 70 | ||
| 71 | return [ |
|
| 72 | $this->idKey => $entity->getKeyData(), |
|
| 73 | $this->name => $entity->getName(), |
|
| 74 | $this->title => $entity->getTitle(), |
|
| 75 | $this->description => $entity->getDescription(), |
|
| 76 | $this->isReadOnly => (int)$entity->getReadOnly(), |
|
| 77 | $this->dateCreated => $dateCreated instanceof DateTime ? $dateCreated->format('Y-m-d H:i:s') : null, |
|
| 78 | $this->dateModified => $dateModified instanceof DateTime ? $dateModified->format('Y-m-d H:i:s') : null |
|
| 79 | ]; |
|
| 80 | } |
|
| 81 | ||
| 82 | /** |
|
| 83 | * Returns a Resource entity identified by (unique) ID. |
|
| 84 | * |
|
| 85 | * @param int $identifier |
|
| 86 | * |
|
| 87 | * @return bool|ResourceEntity |
|
| 88 | */ |
|
| 89 | public function getResourceById($identifier) |
|
| 90 | { |
|
| 91 | $entity = false; |
|
| 92 | $data = $this->getDataAdapter()->getData($identifier); |
|
| 93 | ||
| 94 | if (!empty($data)) { |
|
| 95 | $entity = $this->createEntity(); |
|
| 96 | $this->populateEntity($entity, $data); |
|
| 97 | } |
|
| 98 | ||
| 99 | return $entity; |
|
| 100 | } |
|
| 101 | ||
| 102 | /** |
|
| 103 | * Returns an Resource entity by name. |
|
| 104 | * |
|
| 105 | * @param string $name |
|
| 106 | * |
|
| 107 | * @return bool|ResourceEntity |
|
| 108 | */ |
|
| 109 | public function getResourceByName($name) |
|
| 110 | { |
|
| 111 | $entity = false; |
|
| 112 | $dataList = $this->getDataAdapter()->getDataSet([$this->name => $name], 1); |
|
| 113 | ||
| 114 | if (!empty($dataList)) { |
|
| 115 | $entity = $this->createEntity(); |
|
| 116 | $this->populateEntity($entity, $dataList[0]); |
|
| 117 | } |
|
| 118 | ||
| 119 | return $entity; |
|
| 120 | } |
|
| 121 | } |
|
| 122 | ||
| @@ 21-120 (lines=100) @@ | ||
| 18 | /** |
|
| 19 | * Class ApplicationStorage. |
|
| 20 | */ |
|
| 21 | class ApplicationStorage extends AbstractDataStorage |
|
| 22 | { |
|
| 23 | /** @var string */ |
|
| 24 | protected $dataGroup = 'webhemi_application'; |
|
| 25 | /** @var string */ |
|
| 26 | protected $idKey = 'id_application'; |
|
| 27 | /** @var string */ |
|
| 28 | private $name = 'name'; |
|
| 29 | /** @var string */ |
|
| 30 | private $title = 'title'; |
|
| 31 | /** @var string */ |
|
| 32 | private $description = 'description'; |
|
| 33 | /** @var string */ |
|
| 34 | private $isReadOnly = 'is_read_only'; |
|
| 35 | /** @var string */ |
|
| 36 | private $dateCreated = 'date_created'; |
|
| 37 | /** @var string */ |
|
| 38 | private $dateModified = 'date_modified'; |
|
| 39 | ||
| 40 | /** |
|
| 41 | * Populates an entity with storage data. |
|
| 42 | * |
|
| 43 | * @param DataEntityInterface $entity |
|
| 44 | * @param array $data |
|
| 45 | */ |
|
| 46 | protected function populateEntity(DataEntityInterface &$entity, array $data) |
|
| 47 | { |
|
| 48 | /* @var ApplicationEntity $entity */ |
|
| 49 | $entity->setApplicationId($data[$this->idKey]) |
|
| 50 | ->setName($data[$this->name]) |
|
| 51 | ->setTitle($data[$this->title]) |
|
| 52 | ->setDescription($data[$this->description]) |
|
| 53 | ->setReadOnly($data[$this->isReadOnly]) |
|
| 54 | ->setDateCreated(new DateTime($data[$this->dateCreated])) |
|
| 55 | ->setDateModified(new DateTime($data[$this->dateModified])); |
|
| 56 | } |
|
| 57 | ||
| 58 | /** |
|
| 59 | * Get data from an entity. |
|
| 60 | * |
|
| 61 | * @param DataEntityInterface $entity |
|
| 62 | * @return array |
|
| 63 | */ |
|
| 64 | protected function getEntityData(DataEntityInterface $entity) |
|
| 65 | { |
|
| 66 | /** @var ApplicationEntity $entity */ |
|
| 67 | $dateCreated = $entity->getDateCreated(); |
|
| 68 | $dateModified = $entity->getDateModified(); |
|
| 69 | ||
| 70 | return [ |
|
| 71 | $this->idKey => $entity->getKeyData(), |
|
| 72 | $this->name => $entity->getName(), |
|
| 73 | $this->title => $entity->getTitle(), |
|
| 74 | $this->description => $entity->getDescription(), |
|
| 75 | $this->isReadOnly => (int)$entity->getReadOnly(), |
|
| 76 | $this->dateCreated => $dateCreated instanceof DateTime ? $dateCreated->format('Y-m-d H:i:s') : null, |
|
| 77 | $this->dateModified => $dateModified instanceof DateTime ? $dateModified->format('Y-m-d H:i:s') : null |
|
| 78 | ]; |
|
| 79 | } |
|
| 80 | ||
| 81 | /** |
|
| 82 | * Returns a Application entity identified by (unique) ID. |
|
| 83 | * |
|
| 84 | * @param int $identifier |
|
| 85 | * |
|
| 86 | * @return bool|ApplicationEntity |
|
| 87 | */ |
|
| 88 | public function getApplicationById($identifier) |
|
| 89 | { |
|
| 90 | $entity = false; |
|
| 91 | $data = $this->getDataAdapter()->getData($identifier); |
|
| 92 | ||
| 93 | if (!empty($data)) { |
|
| 94 | $entity = $this->createEntity(); |
|
| 95 | $this->populateEntity($entity, $data); |
|
| 96 | } |
|
| 97 | ||
| 98 | return $entity; |
|
| 99 | } |
|
| 100 | ||
| 101 | /** |
|
| 102 | * Returns an Application entity by name. |
|
| 103 | * |
|
| 104 | * @param string $name |
|
| 105 | * |
|
| 106 | * @return bool|ApplicationEntity |
|
| 107 | */ |
|
| 108 | public function getApplicationByName($name) |
|
| 109 | { |
|
| 110 | $entity = false; |
|
| 111 | $dataList = $this->getDataAdapter()->getDataSet([$this->name => $name], 1); |
|
| 112 | ||
| 113 | if (!empty($dataList)) { |
|
| 114 | $entity = $this->createEntity(); |
|
| 115 | $this->populateEntity($entity, $dataList[0]); |
|
| 116 | } |
|
| 117 | ||
| 118 | return $entity; |
|
| 119 | } |
|
| 120 | } |
|
| 121 | ||
| @@ 22-121 (lines=100) @@ | ||
| 19 | /** |
|
| 20 | * Class UserGroupStorage. |
|
| 21 | */ |
|
| 22 | class UserGroupStorage extends AbstractDataStorage |
|
| 23 | { |
|
| 24 | /** @var string */ |
|
| 25 | protected $dataGroup = 'webhemi_user_group'; |
|
| 26 | /** @var string */ |
|
| 27 | protected $idKey = 'id_user_group'; |
|
| 28 | /** @var string */ |
|
| 29 | private $name = 'name'; |
|
| 30 | /** @var string */ |
|
| 31 | private $title = 'title'; |
|
| 32 | /** @var string */ |
|
| 33 | private $description = 'description'; |
|
| 34 | /** @var string */ |
|
| 35 | private $isReadOnly = 'is_read_only'; |
|
| 36 | /** @var string */ |
|
| 37 | private $dateCreated = 'date_created'; |
|
| 38 | /** @var string */ |
|
| 39 | private $dateModified = 'date_modified'; |
|
| 40 | ||
| 41 | /** |
|
| 42 | * Populates an entity with storage data. |
|
| 43 | * |
|
| 44 | * @param DataEntityInterface $entity |
|
| 45 | * @param array $data |
|
| 46 | */ |
|
| 47 | protected function populateEntity(DataEntityInterface &$entity, array $data) |
|
| 48 | { |
|
| 49 | /* @var UserGroupEntity $entity */ |
|
| 50 | $entity->setUserGroupId($data[$this->idKey]) |
|
| 51 | ->setName($data[$this->name]) |
|
| 52 | ->setTitle($data[$this->title]) |
|
| 53 | ->setDescription($data[$this->description]) |
|
| 54 | ->setReadOnly($data[$this->isReadOnly]) |
|
| 55 | ->setDateCreated(new DateTime($data[$this->dateCreated])) |
|
| 56 | ->setDateModified(new DateTime($data[$this->dateModified])); |
|
| 57 | } |
|
| 58 | ||
| 59 | /** |
|
| 60 | * Get data from an entity. |
|
| 61 | * |
|
| 62 | * @param DataEntityInterface $entity |
|
| 63 | * @return array |
|
| 64 | */ |
|
| 65 | protected function getEntityData(DataEntityInterface $entity) |
|
| 66 | { |
|
| 67 | /** @var UserGroupEntity $entity */ |
|
| 68 | $dateCreated = $entity->getDateCreated(); |
|
| 69 | $dateModified = $entity->getDateModified(); |
|
| 70 | ||
| 71 | return [ |
|
| 72 | $this->idKey => $entity->getKeyData(), |
|
| 73 | $this->name => $entity->getName(), |
|
| 74 | $this->title => $entity->getTitle(), |
|
| 75 | $this->description => $entity->getDescription(), |
|
| 76 | $this->isReadOnly => (int)$entity->getReadOnly(), |
|
| 77 | $this->dateCreated => $dateCreated instanceof DateTime ? $dateCreated->format('Y-m-d H:i:s') : null, |
|
| 78 | $this->dateModified => $dateModified instanceof DateTime ? $dateModified->format('Y-m-d H:i:s') : null |
|
| 79 | ]; |
|
| 80 | } |
|
| 81 | ||
| 82 | /** |
|
| 83 | * Returns a User Group entity identified by (unique) ID. |
|
| 84 | * |
|
| 85 | * @param int $identifier |
|
| 86 | * |
|
| 87 | * @return bool|UserGroupEntity |
|
| 88 | */ |
|
| 89 | public function getUserGroupById($identifier) |
|
| 90 | { |
|
| 91 | $entity = false; |
|
| 92 | $data = $this->getDataAdapter()->getData($identifier); |
|
| 93 | ||
| 94 | if (!empty($data)) { |
|
| 95 | $entity = $this->createEntity(); |
|
| 96 | $this->populateEntity($entity, $data); |
|
| 97 | } |
|
| 98 | ||
| 99 | return $entity; |
|
| 100 | } |
|
| 101 | ||
| 102 | /** |
|
| 103 | * Returns a User Group entity by name. |
|
| 104 | * |
|
| 105 | * @param string $name |
|
| 106 | * |
|
| 107 | * @return bool|UserGroupEntity |
|
| 108 | */ |
|
| 109 | public function getUserGroupByName($name) |
|
| 110 | { |
|
| 111 | $entity = false; |
|
| 112 | $dataList = $this->getDataAdapter()->getDataSet([$this->name => $name], 1); |
|
| 113 | ||
| 114 | if (!empty($dataList)) { |
|
| 115 | $entity = $this->createEntity(); |
|
| 116 | $this->populateEntity($entity, $dataList[0]); |
|
| 117 | } |
|
| 118 | ||
| 119 | return $entity; |
|
| 120 | } |
|
| 121 | } |
|
| 122 | ||