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\Framework\Helper\DateHelper; |
9
|
|
|
use DateTime; |
10
|
|
|
|
11
|
|
|
class ContentListItem implements IStringerEntity |
12
|
|
|
{ |
13
|
|
|
/** @var string */ |
14
|
|
|
protected $id; |
15
|
|
|
|
16
|
|
|
/** @var string */ |
17
|
|
|
protected $listId; |
18
|
|
|
|
19
|
|
|
/** @var string */ |
20
|
|
|
protected $name; |
21
|
|
|
|
22
|
|
|
/** @var string */ |
23
|
|
|
protected $nameHref; |
24
|
|
|
|
25
|
|
|
/** @var string */ |
26
|
|
|
protected $body; |
27
|
|
|
|
28
|
|
|
/** @var string */ |
29
|
|
|
protected $bodyHref; |
30
|
|
|
|
31
|
|
|
/** @var string */ |
32
|
|
|
protected $imgSrc; |
33
|
|
|
|
34
|
|
|
/** @var string */ |
35
|
|
|
protected $imgHref; |
36
|
|
|
|
37
|
|
|
/** @var string */ |
38
|
|
|
protected $imgAlt; |
39
|
|
|
|
40
|
|
|
/** @var DateTime|null */ |
41
|
|
|
protected $deletedAt; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* ContentListItem constructor. |
45
|
|
|
* |
46
|
|
|
* @param string $id |
47
|
|
|
* @param string $listId |
48
|
|
|
* @param string $name |
49
|
|
|
* @param string $nameHref |
50
|
|
|
* @param string $body |
51
|
|
|
* @param string $bodyHref |
52
|
|
|
* @param string $imgSrc |
53
|
|
|
* @param string $imgHref |
54
|
|
|
* @param string $imgAlt |
55
|
|
|
* @param DateTime|null $deletedAt |
56
|
|
|
*/ |
57
|
|
|
public function __construct( |
58
|
|
|
string $id, |
59
|
|
|
string $listId, |
60
|
|
|
string $name, |
61
|
|
|
string $nameHref, |
62
|
|
|
string $body, |
63
|
|
|
string $bodyHref, |
64
|
|
|
string $imgSrc, |
65
|
|
|
string $imgHref, |
66
|
|
|
string $imgAlt, |
67
|
|
|
?DateTime $deletedAt = null |
68
|
|
|
) { |
69
|
|
|
$this->id = $id; |
70
|
|
|
$this->listId = $listId; |
71
|
|
|
$this->name = $name; |
72
|
|
|
$this->nameHref = $nameHref; |
73
|
|
|
$this->body = $body; |
74
|
|
|
$this->bodyHref = $bodyHref; |
75
|
|
|
$this->imgSrc = $imgSrc; |
76
|
|
|
$this->imgHref = $imgHref; |
77
|
|
|
$this->imgAlt = $imgAlt; |
78
|
|
|
$this->deletedAt = $deletedAt; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
|
|
public function getId() |
85
|
|
|
{ |
86
|
|
|
return $this->id; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param string $id |
91
|
|
|
*/ |
92
|
|
|
public function setId($id) |
93
|
|
|
{ |
94
|
|
|
$this->id = $id; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return string |
99
|
|
|
*/ |
100
|
|
|
public function getListId(): string |
101
|
|
|
{ |
102
|
|
|
return $this->listId; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param string $listId |
107
|
|
|
* |
108
|
|
|
* @return $this |
109
|
|
|
*/ |
110
|
|
|
public function setListId(string $listId): ContentListItem |
111
|
|
|
{ |
112
|
|
|
$this->listId = $listId; |
113
|
|
|
|
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @return string |
119
|
|
|
*/ |
120
|
|
|
public function getName(): string |
121
|
|
|
{ |
122
|
|
|
return $this->name; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param string $name |
127
|
|
|
* |
128
|
|
|
* @return $this |
129
|
|
|
*/ |
130
|
|
|
public function setName(string $name): ContentListItem |
131
|
|
|
{ |
132
|
|
|
$this->name = $name; |
133
|
|
|
|
134
|
|
|
return $this; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @return string |
139
|
|
|
*/ |
140
|
|
|
public function getNameHref(): string |
141
|
|
|
{ |
142
|
|
|
return $this->nameHref; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @param string $nameHref |
147
|
|
|
* |
148
|
|
|
* @return $this |
149
|
|
|
*/ |
150
|
|
|
public function setNameHref(string $nameHref): ContentListItem |
151
|
|
|
{ |
152
|
|
|
$this->nameHref = $nameHref; |
153
|
|
|
|
154
|
|
|
return $this; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @return string |
159
|
|
|
*/ |
160
|
|
|
public function getBody(): string |
161
|
|
|
{ |
162
|
|
|
return $this->body; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @param string $body |
167
|
|
|
* |
168
|
|
|
* @return $this |
169
|
|
|
*/ |
170
|
|
|
public function setBody(string $body): ContentListItem |
171
|
|
|
{ |
172
|
|
|
$this->body = $body; |
173
|
|
|
|
174
|
|
|
return $this; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @return string |
179
|
|
|
*/ |
180
|
|
|
public function getBodyHref(): string |
181
|
|
|
{ |
182
|
|
|
return $this->bodyHref; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @param string $bodyHref |
187
|
|
|
* |
188
|
|
|
* @return $this |
189
|
|
|
*/ |
190
|
|
|
public function setBodyHref(string $bodyHref): ContentListItem |
191
|
|
|
{ |
192
|
|
|
$this->bodyHref = $bodyHref; |
193
|
|
|
|
194
|
|
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @return string |
199
|
|
|
*/ |
200
|
|
|
public function getImgSrc(): string |
201
|
|
|
{ |
202
|
|
|
return $this->imgSrc; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* @param string $imgSrc |
207
|
|
|
* |
208
|
|
|
* @return $this |
209
|
|
|
*/ |
210
|
|
|
public function setImgSrc(string $imgSrc): ContentListItem |
211
|
|
|
{ |
212
|
|
|
$this->imgSrc = $imgSrc; |
213
|
|
|
|
214
|
|
|
return $this; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @return string |
219
|
|
|
*/ |
220
|
|
|
public function getImgHref(): string |
221
|
|
|
{ |
222
|
|
|
return $this->imgHref; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @param string $imgHref |
227
|
|
|
* |
228
|
|
|
* @return $this |
229
|
|
|
*/ |
230
|
|
|
public function setImgHref(string $imgHref): ContentListItem |
231
|
|
|
{ |
232
|
|
|
$this->imgHref = $imgHref; |
233
|
|
|
|
234
|
|
|
return $this; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @return string |
239
|
|
|
*/ |
240
|
|
|
public function getImgAlt(): string |
241
|
|
|
{ |
242
|
|
|
return $this->imgAlt; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @param string $imgAlt |
247
|
|
|
* |
248
|
|
|
* @return $this |
249
|
|
|
*/ |
250
|
|
|
public function setImgAlt(string $imgAlt): ContentListItem |
251
|
|
|
{ |
252
|
|
|
$this->imgAlt = $imgAlt; |
253
|
|
|
|
254
|
|
|
return $this; |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* @return DateTime|null |
259
|
|
|
*/ |
260
|
|
|
public function getDeletedAt(): ?DateTime |
261
|
|
|
{ |
262
|
|
|
return $this->deletedAt; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* @param DateTime|null $deletedAt |
267
|
|
|
* |
268
|
|
|
* @return $this |
269
|
|
|
*/ |
270
|
|
|
public function setDeletedAt(?DateTime $deletedAt): ContentListItem |
271
|
|
|
{ |
272
|
|
|
$this->deletedAt = $deletedAt; |
273
|
|
|
|
274
|
|
|
return $this; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* @return string |
279
|
|
|
*/ |
280
|
|
|
public function __toString(): string |
281
|
|
|
{ |
282
|
|
|
return $this->getName(); |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
/** |
286
|
|
|
* @return string |
287
|
|
|
*/ |
288
|
|
|
public function toJSON(): string |
289
|
|
|
{ |
290
|
|
|
$data = [ |
291
|
|
|
'id' => $this->getId(), |
292
|
|
|
'list_id' => $this->getListId(), |
293
|
|
|
'name' => $this->getName(), |
294
|
|
|
'name_href' => $this->getNameHref(), |
295
|
|
|
'body' => $this->getBody(), |
296
|
|
|
'body_href' => $this->getBodyHref(), |
297
|
|
|
'img_src' => $this->getImgSrc(), |
298
|
|
|
'img_href' => $this->getImgHref(), |
299
|
|
|
'img_alt' => $this->getImgAlt(), |
300
|
|
|
]; |
301
|
|
|
|
302
|
|
|
if ($this->getDeletedAt()) { |
303
|
|
|
$data['deleted_at'] = DateHelper::formatDateTime($this->getDeletedAt()); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
return json_encode($data); |
307
|
|
|
} |
308
|
|
|
} |
309
|
|
|
|