|
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 list by the application identifier. |
|
101
|
|
|
* |
|
102
|
|
|
* @param int $applicationId |
|
103
|
|
|
* @return FilesystemCategoryEntity[] |
|
104
|
|
|
*/ |
|
105
|
|
|
public function getFilesystemCategorysByApplication(int $applicationId) : ? array |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->getDataEntitySet([$this->idApplication => $applicationId]); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|