1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Yproximite\Api\Model\Article; |
5
|
|
|
|
6
|
|
|
use Yproximite\Api\Model\ModelInterface; |
7
|
|
|
use Yproximite\Api\Model\Inheritance\InheritanceStatuses; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class Category |
11
|
|
|
*/ |
12
|
|
|
class Category implements ModelInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @var int |
16
|
|
|
*/ |
17
|
|
|
private $id; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var CategoryTranslation[] |
21
|
|
|
*/ |
22
|
|
|
private $translations; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var bool |
26
|
|
|
*/ |
27
|
|
|
private $enabled; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var int|null |
31
|
|
|
*/ |
32
|
|
|
private $dataParentId; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var int|null |
36
|
|
|
*/ |
37
|
|
|
private $parentRootId; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var \DateTime |
41
|
|
|
*/ |
42
|
|
|
private $createdAt; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var \DateTime |
46
|
|
|
*/ |
47
|
|
|
private $updatedAt; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
private $inheritanceStatus; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Category constructor. |
56
|
|
|
* |
57
|
|
|
* @param array $data |
58
|
|
|
*/ |
59
|
|
|
public function __construct(array $data) |
60
|
|
|
{ |
61
|
|
|
$translations = array_map(function (array $data) { |
62
|
|
|
return new CategoryTranslation($data); |
63
|
|
|
}, $data['translations']); |
64
|
|
|
|
65
|
|
|
$this->id = (int) $data['id']; |
66
|
|
|
$this->translations = $translations; |
67
|
|
|
$this->enabled = (bool) $data['enabled']; |
68
|
|
|
$this->dataParentId = !empty($data['dataParent']) ? (int) $data['dataParent'] : null; |
69
|
|
|
$this->parentRootId = (int) $data['parentRootId']; |
70
|
|
|
$this->createdAt = new \DateTime($data['createdAt']['date']); |
71
|
|
|
$this->updatedAt = new \DateTime($data['updatedAt']['date']); |
72
|
|
|
$this->inheritanceStatus = (string) $data['inheritance_status']; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return int |
77
|
|
|
*/ |
78
|
|
|
public function getId(): int |
79
|
|
|
{ |
80
|
|
|
return $this->id; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return CategoryTranslation[] |
85
|
|
|
*/ |
86
|
|
|
public function getTranslations(): array |
87
|
|
|
{ |
88
|
|
|
return $this->translations; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @return bool |
93
|
|
|
*/ |
94
|
|
|
public function isEnabled(): bool |
95
|
|
|
{ |
96
|
|
|
return $this->enabled; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return int|null |
101
|
|
|
*/ |
102
|
|
|
public function getDataParentId(): ?int |
103
|
|
|
{ |
104
|
|
|
return $this->dataParentId; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @return \DateTime |
109
|
|
|
*/ |
110
|
|
|
public function getCreatedAt(): \DateTime |
111
|
|
|
{ |
112
|
|
|
return $this->createdAt; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return \DateTime |
117
|
|
|
*/ |
118
|
|
|
public function getUpdatedAt(): \DateTime |
119
|
|
|
{ |
120
|
|
|
return $this->updatedAt; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @see InheritanceStatuses::getValues() |
125
|
|
|
* |
126
|
|
|
* @return string |
127
|
|
|
*/ |
128
|
|
|
public function getInheritanceStatus(): string |
129
|
|
|
{ |
130
|
|
|
return $this->inheritanceStatus; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return int|null |
135
|
|
|
*/ |
136
|
|
|
public function getParentRootId(): ?int |
137
|
|
|
{ |
138
|
|
|
return $this->parentRootId; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @param int|null $parentRootId |
143
|
|
|
*/ |
144
|
|
|
public function setParentRootId($parentRootId) |
145
|
|
|
{ |
146
|
|
|
$this->parentRootId = $parentRootId; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|