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\Site\SiteRoute; |
8
|
|
|
use Yproximite\Api\Model\Inheritance\InheritanceStatuses; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class Article |
12
|
|
|
*/ |
13
|
|
|
class Article implements ModelInterface |
14
|
|
|
{ |
15
|
|
|
const STATUS_DRAFT = 'draft'; |
16
|
|
|
const STATUS_PUBLISHED = 'published'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var int |
20
|
|
|
*/ |
21
|
|
|
private $id; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var ArticleTranslation[] |
25
|
|
|
*/ |
26
|
|
|
private $translations; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var Category[] |
30
|
|
|
*/ |
31
|
|
|
private $categories; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var ArticleMedia[] |
35
|
|
|
*/ |
36
|
|
|
private $medias; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var int |
40
|
|
|
*/ |
41
|
|
|
private $mediaLimit; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string|null |
45
|
|
|
*/ |
46
|
|
|
private $status; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var bool |
50
|
|
|
*/ |
51
|
|
|
private $displayPrintButton; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var bool |
55
|
|
|
*/ |
56
|
|
|
private $displayPrintAddress; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var bool |
60
|
|
|
*/ |
61
|
|
|
private $withReturnButton; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var bool |
65
|
|
|
*/ |
66
|
|
|
private $showCreationDate; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var bool |
70
|
|
|
*/ |
71
|
|
|
private $showImageCaption; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @var bool |
75
|
|
|
*/ |
76
|
|
|
private $autoPlaySlider; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @var SiteRoute[] |
80
|
|
|
*/ |
81
|
|
|
private $routes; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @var bool |
85
|
|
|
*/ |
86
|
|
|
private $shareOnFacebook; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @var int |
90
|
|
|
*/ |
91
|
|
|
private $displayOrder; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @var int|null |
95
|
|
|
*/ |
96
|
|
|
private $dataParentId; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @var \DateTime |
100
|
|
|
*/ |
101
|
|
|
private $createdAt; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @var \DateTime |
105
|
|
|
*/ |
106
|
|
|
private $updatedAt; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @var string |
110
|
|
|
*/ |
111
|
|
|
private $inheritanceStatus; |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @return string[] |
115
|
|
|
*/ |
116
|
|
|
public static function getStatuses(): array |
117
|
|
|
{ |
118
|
|
|
return [ |
119
|
|
|
self::STATUS_DRAFT, |
120
|
|
|
self::STATUS_PUBLISHED, |
121
|
|
|
]; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* Article constructor. |
126
|
|
|
* |
127
|
|
|
* @param array $data |
128
|
|
|
*/ |
129
|
|
|
public function __construct(array $data) |
130
|
|
|
{ |
131
|
|
|
$translations = array_map(function (array $data) { |
132
|
|
|
return new ArticleTranslation($data); |
133
|
|
|
}, $data['translations']); |
134
|
|
|
|
135
|
|
|
$categories = array_map(function (array $data) { |
136
|
|
|
return new Category($data); |
137
|
|
|
}, $data['categories']); |
138
|
|
|
|
139
|
|
|
$medias = array_map(function (array $data) { |
140
|
|
|
return new ArticleMedia($data); |
141
|
|
|
}, $data['medias']); |
142
|
|
|
|
143
|
|
|
$routes = array_map(function (string $path, string $locale) { |
144
|
|
|
return new SiteRoute(compact('path', 'locale')); |
145
|
|
|
}, array_values($data['routes']), array_keys($data['routes'])); |
146
|
|
|
|
147
|
|
|
$this->id = (int) $data['id']; |
148
|
|
|
$this->translations = $translations; |
149
|
|
|
$this->categories = $categories; |
150
|
|
|
$this->medias = $medias; |
151
|
|
|
$this->mediaLimit = (int) $data['media_limit']; |
152
|
|
|
$this->status = (string) $data['status']; |
153
|
|
|
$this->displayPrintButton = (bool) $data['display_print_button']; |
154
|
|
|
$this->displayPrintAddress = (bool) $data['display_print_address']; |
155
|
|
|
$this->withReturnButton = (bool) $data['with_return_button']; |
156
|
|
|
$this->showCreationDate = (bool) $data['show_creation_date']; |
157
|
|
|
$this->showImageCaption = (bool) $data['show_image_caption']; |
158
|
|
|
$this->autoPlaySlider = (bool) $data['auto_play_slider']; |
159
|
|
|
$this->routes = $routes; |
160
|
|
|
$this->shareOnFacebook = (bool) $data['share_on_facebook']; |
161
|
|
|
$this->displayOrder = (int) $data['display_order']; |
162
|
|
|
$this->dataParentId = !empty($data['dataParent']) ? (int) $data['dataParent'] : null; |
163
|
|
|
$this->createdAt = new \DateTime($data['createdAt']['date']); |
164
|
|
|
$this->updatedAt = new \DateTime($data['updatedAt']['date']); |
165
|
|
|
$this->inheritanceStatus = (string) $data['inheritance_status']; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @return int |
170
|
|
|
*/ |
171
|
|
|
public function getId(): int |
172
|
|
|
{ |
173
|
|
|
return $this->id; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @return ArticleTranslation[] |
178
|
|
|
*/ |
179
|
|
|
public function getTranslations(): array |
180
|
|
|
{ |
181
|
|
|
return $this->translations; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @return Category[] |
186
|
|
|
*/ |
187
|
|
|
public function getCategories(): array |
188
|
|
|
{ |
189
|
|
|
return $this->categories; |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @return ArticleMedia[] |
194
|
|
|
*/ |
195
|
|
|
public function getMedias(): array |
196
|
|
|
{ |
197
|
|
|
return $this->medias; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @return int |
202
|
|
|
*/ |
203
|
|
|
public function getMediaLimit(): int |
204
|
|
|
{ |
205
|
|
|
return $this->mediaLimit; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* @see Article::getStatuses() |
210
|
|
|
* |
211
|
|
|
* @return null|string |
212
|
|
|
*/ |
213
|
|
|
public function getStatus() |
214
|
|
|
{ |
215
|
|
|
return $this->status; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @return bool |
220
|
|
|
*/ |
221
|
|
|
public function isDisplayPrintButton(): bool |
222
|
|
|
{ |
223
|
|
|
return $this->displayPrintButton; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @return bool |
228
|
|
|
*/ |
229
|
|
|
public function isDisplayPrintAddress(): bool |
230
|
|
|
{ |
231
|
|
|
return $this->displayPrintAddress; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* @return bool |
236
|
|
|
*/ |
237
|
|
|
public function isWithReturnButton(): bool |
238
|
|
|
{ |
239
|
|
|
return $this->withReturnButton; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @return bool |
244
|
|
|
*/ |
245
|
|
|
public function isShowCreationDate(): bool |
246
|
|
|
{ |
247
|
|
|
return $this->showCreationDate; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @return bool |
252
|
|
|
*/ |
253
|
|
|
public function isShowImageCaption(): bool |
254
|
|
|
{ |
255
|
|
|
return $this->showImageCaption; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @return bool |
260
|
|
|
*/ |
261
|
|
|
public function isAutoPlaySlider(): bool |
262
|
|
|
{ |
263
|
|
|
return $this->autoPlaySlider; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @return SiteRoute[] |
268
|
|
|
*/ |
269
|
|
|
public function getRoutes(): array |
270
|
|
|
{ |
271
|
|
|
return $this->routes; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @return bool |
276
|
|
|
*/ |
277
|
|
|
public function isShareOnFacebook(): bool |
278
|
|
|
{ |
279
|
|
|
return $this->shareOnFacebook; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* @return int |
284
|
|
|
*/ |
285
|
|
|
public function getDisplayOrder(): int |
286
|
|
|
{ |
287
|
|
|
return $this->displayOrder; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @return int|null |
292
|
|
|
*/ |
293
|
|
|
public function getDataParentId() |
294
|
|
|
{ |
295
|
|
|
return $this->dataParentId; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @return \DateTime |
300
|
|
|
*/ |
301
|
|
|
public function getCreatedAt(): \DateTime |
302
|
|
|
{ |
303
|
|
|
return $this->createdAt; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* @return \DateTime |
308
|
|
|
*/ |
309
|
|
|
public function getUpdatedAt(): \DateTime |
310
|
|
|
{ |
311
|
|
|
return $this->updatedAt; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* @see InheritanceStatuses::getValues() |
316
|
|
|
* |
317
|
|
|
* @return string |
318
|
|
|
*/ |
319
|
|
|
public function getInheritanceStatus(): string |
320
|
|
|
{ |
321
|
|
|
return $this->inheritanceStatus; |
322
|
|
|
} |
323
|
|
|
} |
324
|
|
|
|