1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AbterPhp\Website\Domain\Entities; |
6
|
|
|
|
7
|
|
|
use AbterPhp\Framework\Domain\Entities\IStringerEntity; |
8
|
|
|
use AbterPhp\Website\Domain\Entities\ContentListItem as Item; |
9
|
|
|
use AbterPhp\Website\Domain\Entities\ContentListType as Type; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveParameterList) |
13
|
|
|
*/ |
14
|
|
|
class ContentList implements IStringerEntity |
15
|
|
|
{ |
16
|
|
|
/** @var string */ |
17
|
|
|
protected $id; |
18
|
|
|
|
19
|
|
|
/** @var string */ |
20
|
|
|
protected $name; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
protected $identifier; |
24
|
|
|
|
25
|
|
|
/** @var string */ |
26
|
|
|
protected $classes; |
27
|
|
|
|
28
|
|
|
/** @var bool */ |
29
|
|
|
protected $protected; |
30
|
|
|
|
31
|
|
|
/** @var bool */ |
32
|
|
|
protected $withImage; |
33
|
|
|
|
34
|
|
|
/** @var bool */ |
35
|
|
|
protected $withLinks; |
36
|
|
|
|
37
|
|
|
/** @var bool */ |
38
|
|
|
protected $withBody; |
39
|
|
|
|
40
|
|
|
/** @var bool */ |
41
|
|
|
protected $withHtml; |
42
|
|
|
|
43
|
|
|
/** @var Type */ |
44
|
|
|
protected $type; |
45
|
|
|
|
46
|
|
|
/** @var Item[]|null */ |
47
|
|
|
protected $items; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* ContentList constructor. |
51
|
|
|
* |
52
|
|
|
* @param string $id |
53
|
|
|
* @param string $name |
54
|
|
|
* @param string $identifier |
55
|
|
|
* @param string $classes |
56
|
|
|
* @param bool $protected |
57
|
|
|
* @param bool $withLinks |
58
|
|
|
* @param bool $withImage |
59
|
|
|
* @param bool $withBody |
60
|
|
|
* @param bool $withHtml |
61
|
|
|
* @param Type|null $type |
62
|
|
|
* @param Item[]|null $items |
63
|
|
|
*/ |
64
|
|
|
public function __construct( |
65
|
|
|
string $id, |
66
|
|
|
string $name, |
67
|
|
|
string $identifier, |
68
|
|
|
string $classes, |
69
|
|
|
bool $protected, |
70
|
|
|
bool $withLinks, |
71
|
|
|
bool $withImage, |
72
|
|
|
bool $withBody, |
73
|
|
|
bool $withHtml, |
74
|
|
|
?Type $type = null, |
75
|
|
|
array $items = null |
76
|
|
|
) { |
77
|
|
|
$this->id = $id; |
78
|
|
|
$this->name = $name; |
79
|
|
|
$this->identifier = $identifier; |
80
|
|
|
$this->classes = $classes; |
81
|
|
|
$this->protected = $protected; |
82
|
|
|
$this->withLinks = $withLinks; |
83
|
|
|
$this->withImage = $withImage; |
84
|
|
|
$this->withBody = $withBody; |
85
|
|
|
$this->withHtml = $withHtml; |
86
|
|
|
$this->type = $type ?: new Type('', '', ''); |
87
|
|
|
$this->items = $items; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return string |
92
|
|
|
*/ |
93
|
|
|
public function getId() |
94
|
|
|
{ |
95
|
|
|
return $this->id; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param string $id |
100
|
|
|
*/ |
101
|
|
|
public function setId($id) |
102
|
|
|
{ |
103
|
|
|
$this->id = $id; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
|
|
public function getIdentifier(): string |
110
|
|
|
{ |
111
|
|
|
return $this->identifier; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param string $identifier |
116
|
|
|
* |
117
|
|
|
* @return $this |
118
|
|
|
*/ |
119
|
|
|
public function setIdentifier(string $identifier): ContentList |
120
|
|
|
{ |
121
|
|
|
$this->identifier = $identifier; |
122
|
|
|
|
123
|
|
|
return $this; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return string |
128
|
|
|
*/ |
129
|
|
|
public function getClasses(): string |
130
|
|
|
{ |
131
|
|
|
return $this->classes; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param string $classes |
136
|
|
|
* |
137
|
|
|
* @return $this |
138
|
|
|
*/ |
139
|
|
|
public function setClasses(string $classes): ContentList |
140
|
|
|
{ |
141
|
|
|
$this->classes = $classes; |
142
|
|
|
|
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return string |
148
|
|
|
*/ |
149
|
|
|
public function getName(): string |
150
|
|
|
{ |
151
|
|
|
return $this->name; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param string $name |
156
|
|
|
* |
157
|
|
|
* @return $this |
158
|
|
|
*/ |
159
|
|
|
public function setName(string $name): ContentList |
160
|
|
|
{ |
161
|
|
|
$this->name = $name; |
162
|
|
|
|
163
|
|
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return bool |
168
|
|
|
*/ |
169
|
|
|
public function isProtected(): bool |
170
|
|
|
{ |
171
|
|
|
return $this->protected; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @param bool $protected |
176
|
|
|
* |
177
|
|
|
* @return $this |
178
|
|
|
*/ |
179
|
|
|
public function setProtected(bool $protected): ContentList |
180
|
|
|
{ |
181
|
|
|
$this->protected = $protected; |
182
|
|
|
|
183
|
|
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @return bool |
188
|
|
|
*/ |
189
|
|
|
public function isWithImage(): bool |
190
|
|
|
{ |
191
|
|
|
return $this->withImage; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @param bool $withImage |
196
|
|
|
* |
197
|
|
|
* @return $this |
198
|
|
|
*/ |
199
|
|
|
public function setWithImage(bool $withImage): ContentList |
200
|
|
|
{ |
201
|
|
|
$this->withImage = $withImage; |
202
|
|
|
|
203
|
|
|
return $this; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return bool |
208
|
|
|
*/ |
209
|
|
|
public function isWithLinks(): bool |
210
|
|
|
{ |
211
|
|
|
return $this->withLinks; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @param bool $withLinks |
216
|
|
|
* |
217
|
|
|
* @return $this |
218
|
|
|
*/ |
219
|
|
|
public function setWithLinks(bool $withLinks): ContentList |
220
|
|
|
{ |
221
|
|
|
$this->withLinks = $withLinks; |
222
|
|
|
|
223
|
|
|
return $this; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @return bool |
228
|
|
|
*/ |
229
|
|
|
public function isWithBody(): bool |
230
|
|
|
{ |
231
|
|
|
return $this->withBody; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* @param bool $withBody |
236
|
|
|
* |
237
|
|
|
* @return $this |
238
|
|
|
*/ |
239
|
|
|
public function setWithBody(bool $withBody): ContentList |
240
|
|
|
{ |
241
|
|
|
$this->withBody = $withBody; |
242
|
|
|
|
243
|
|
|
return $this; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @return bool |
248
|
|
|
*/ |
249
|
|
|
public function isWithHtml(): bool |
250
|
|
|
{ |
251
|
|
|
return $this->withHtml; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* @param bool $withHtml |
256
|
|
|
* |
257
|
|
|
* @return $this |
258
|
|
|
*/ |
259
|
|
|
public function setWithHtml(bool $withHtml): ContentList |
260
|
|
|
{ |
261
|
|
|
$this->withHtml = $withHtml; |
262
|
|
|
|
263
|
|
|
return $this; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @return Type |
268
|
|
|
*/ |
269
|
|
|
public function getType(): Type |
270
|
|
|
{ |
271
|
|
|
return $this->type; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @param Type $type |
276
|
|
|
* |
277
|
|
|
* @return $this |
278
|
|
|
*/ |
279
|
|
|
public function setType(Type $type): ContentList |
280
|
|
|
{ |
281
|
|
|
$this->type = $type; |
282
|
|
|
|
283
|
|
|
return $this; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* @return Item[]|null |
288
|
|
|
*/ |
289
|
|
|
public function getItems(): ?array |
290
|
|
|
{ |
291
|
|
|
return $this->items; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* @param Item[]|null $items |
296
|
|
|
* |
297
|
|
|
* @return $this |
298
|
|
|
*/ |
299
|
|
|
public function setItems(?array $items = null): ContentList |
300
|
|
|
{ |
301
|
|
|
$this->items = $items; |
302
|
|
|
|
303
|
|
|
return $this; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* @param Item $item |
308
|
|
|
* |
309
|
|
|
* @return ContentList |
310
|
|
|
*/ |
311
|
|
|
public function addItem(Item $item): ContentList |
312
|
|
|
{ |
313
|
|
|
$this->items[] = $item; |
314
|
|
|
|
315
|
|
|
return $this; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @return string |
320
|
|
|
*/ |
321
|
|
|
public function __toString(): string |
322
|
|
|
{ |
323
|
|
|
return $this->getIdentifier(); |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* @return array|null |
328
|
|
|
*/ |
329
|
|
|
public function toData(): ?array |
330
|
|
|
{ |
331
|
|
|
$data = [ |
332
|
|
|
'id' => $this->getId(), |
333
|
|
|
'name' => $this->getName(), |
334
|
|
|
'identifier' => $this->getIdentifier(), |
335
|
|
|
'classes' => $this->getClasses(), |
336
|
|
|
'protected' => $this->isProtected(), |
337
|
|
|
'with_links' => $this->isWithLinks(), |
338
|
|
|
'with_image' => $this->isWithImage(), |
339
|
|
|
'with_body' => $this->isWithBody(), |
340
|
|
|
'with_html' => $this->isWithHtml(), |
341
|
|
|
]; |
342
|
|
|
|
343
|
|
|
if ($this->items !== null) { |
344
|
|
|
$items = []; |
345
|
|
|
foreach ($this->items as $item) { |
346
|
|
|
$items[] = $item->toData(); |
347
|
|
|
} |
348
|
|
|
$data['items'] = $items; |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
return $data; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* @return string |
356
|
|
|
*/ |
357
|
|
|
public function toJSON(): string |
358
|
|
|
{ |
359
|
|
|
return json_encode($this->toData()); |
360
|
|
|
} |
361
|
|
|
} |
362
|
|
|
|