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\Data\Storage\Filesystem; |
15
|
|
|
|
16
|
|
|
use WebHemi\DateTime; |
17
|
|
|
use WebHemi\Data\EntityInterface; |
18
|
|
|
use WebHemi\Data\Storage\AbstractStorage; |
19
|
|
|
use WebHemi\Data\Entity\Filesystem\FilesystemCategoryEntity; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class FilesystemCategoryStorage. |
23
|
|
|
*/ |
24
|
|
|
class FilesystemCategoryStorage extends AbstractStorage |
25
|
|
|
{ |
26
|
|
|
/** @var string */ |
27
|
|
|
protected $dataGroup = 'webhemi_filesystem_category'; |
28
|
|
|
/** @var string */ |
29
|
|
|
protected $idKey = 'id_filesystem_category'; |
30
|
|
|
/** @var string */ |
31
|
|
|
private $idApplication = 'fk_application'; |
32
|
|
|
/** @var string */ |
33
|
|
|
private $name = 'name'; |
34
|
|
|
/** @var string */ |
35
|
|
|
private $title = 'title'; |
36
|
|
|
/** @var string */ |
37
|
|
|
private $description = 'description'; |
38
|
|
|
/** @var string */ |
39
|
|
|
private $dateCreated = 'date_created'; |
40
|
|
|
/** @var string */ |
41
|
|
|
private $dateModified = 'date_modified'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Populates an entity with storage data. |
45
|
|
|
* |
46
|
|
|
* @param EntityInterface $dataEntity |
47
|
|
|
* @param array $data |
48
|
|
|
* @return void |
49
|
|
|
*/ |
50
|
|
|
protected function populateEntity(EntityInterface&$dataEntity, array $data) : void |
51
|
|
|
{ |
52
|
|
|
/* @var FilesystemCategoryEntity $dataEntity */ |
53
|
|
|
$dataEntity->setFilesystemCategoryId((int) $data[$this->idKey]) |
54
|
|
|
->setApplicationId((int) $data[$this->idApplication]) |
55
|
|
|
->setName($data[$this->name]) |
56
|
|
|
->setTitle($data[$this->title]) |
57
|
|
|
->setDescription($data[$this->description]) |
58
|
|
|
->setDateCreated(new DateTime($data[$this->dateCreated] ?? 'now')) |
59
|
|
|
->setDateModified(new DateTime($data[$this->dateModified] ?? 'now')); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get data from an entity. |
64
|
|
|
* |
65
|
|
|
* @param EntityInterface $dataEntity |
66
|
|
|
* @return array |
67
|
|
|
*/ |
68
|
|
|
protected function getEntityData(EntityInterface $dataEntity) : array |
69
|
|
|
{ |
70
|
|
|
/** @var FilesystemCategoryEntity $dataEntity */ |
71
|
|
|
$dateCreated = $dataEntity->getDateCreated(); |
72
|
|
|
$dateModified = $dataEntity->getDateModified(); |
73
|
|
|
|
74
|
|
|
return [ |
75
|
|
|
$this->idKey => (int) $dataEntity->getKeyData(), |
76
|
|
|
$this->idApplication => (int) $dataEntity->getApplicationId(), |
77
|
|
|
$this->title => $dataEntity->getTitle(), |
78
|
|
|
$this->name => $dataEntity->getName(), |
79
|
|
|
$this->description => $dataEntity->getDescription(), |
80
|
|
|
$this->dateCreated => $dateCreated instanceof DateTime ? $dateCreated->format('Y-m-d H:i:s') : null, |
81
|
|
|
$this->dateModified => $dateModified instanceof DateTime ? $dateModified->format('Y-m-d H:i:s') : null |
82
|
|
|
]; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Gets the filesystem category entity by the identifier. |
87
|
|
|
* |
88
|
|
|
* @param int $identifier |
89
|
|
|
* @return null|FilesystemCategoryEntity |
90
|
|
|
*/ |
91
|
|
|
public function getFilesystemCategoryById(int $identifier) : ? FilesystemCategoryEntity |
92
|
|
|
{ |
93
|
|
|
/** @var null|FilesystemCategoryEntity $dataEntity */ |
94
|
|
|
$dataEntity = $this->getDataEntity([$this->idKey => $identifier]); |
95
|
|
|
|
96
|
|
|
return $dataEntity; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Gets the filesystem category entity by the application identifier and name. |
101
|
|
|
* |
102
|
|
|
* @param int $applicationId |
103
|
|
|
* @param string $name |
104
|
|
|
* @return null|FilesystemCategoryEntity |
105
|
|
|
*/ |
106
|
|
|
public function getFilesystemCategoryByApplicationAndName( |
107
|
|
|
int $applicationId, |
108
|
|
|
string $name |
109
|
|
|
) : ? FilesystemCategoryEntity { |
110
|
|
|
/** @var null|FilesystemCategoryEntity $dataEntity */ |
111
|
|
|
$dataEntity = $this->getDataEntity( |
112
|
|
|
[ |
113
|
|
|
$this->idApplication => $applicationId, |
114
|
|
|
$this->name => $name |
115
|
|
|
] |
116
|
|
|
); |
117
|
|
|
|
118
|
|
|
return $dataEntity; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Gets the filesystem category entity list by the application identifier. |
123
|
|
|
* |
124
|
|
|
* @param int $applicationId |
125
|
|
|
* @return FilesystemCategoryEntity[] |
126
|
|
|
*/ |
127
|
|
|
public function getFilesystemCategoriesByApplication(int $applicationId) : ? array |
128
|
|
|
{ |
129
|
|
|
return $this->getDataEntitySet([$this->idApplication => $applicationId]); |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|