1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Entity; |
4
|
|
|
|
5
|
|
|
use DateTime; |
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use Doctrine\Common\Collections\Collection; |
8
|
|
|
use Doctrine\ORM\Mapping as ORM; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @ORM\Entity |
12
|
|
|
* @ORM\Table(name="forum_threads") |
13
|
|
|
*/ |
14
|
|
|
class Thread |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var int |
18
|
|
|
* @ORM\Id |
19
|
|
|
* @ORM\GeneratedValue |
20
|
|
|
* @ORM\Column(type="integer") |
21
|
|
|
*/ |
22
|
|
|
protected $id; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var User |
26
|
|
|
* @ORM\ManyToOne(targetEntity="\App\Entity\User") |
27
|
|
|
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false) |
28
|
|
|
*/ |
29
|
|
|
protected $user; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var Board |
33
|
|
|
* @ORM\ManyToOne(targetEntity="Board", inversedBy="threads") |
34
|
|
|
* @ORM\JoinColumn(name="board_id", referencedColumnName="id", nullable=false) |
35
|
|
|
*/ |
36
|
|
|
protected $board; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var string |
40
|
|
|
* @ORM\Column(type="string") |
41
|
|
|
*/ |
42
|
|
|
protected $topic; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var int |
46
|
|
|
* @ORM\Column(type="integer", options={"default": 0}) |
47
|
|
|
*/ |
48
|
|
|
protected $views = 0; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var int |
52
|
|
|
* @ORM\Column(type="integer", options={"default": 0}) |
53
|
|
|
*/ |
54
|
|
|
protected $replies = 0; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var bool |
58
|
|
|
* @ORM\Column(type="boolean", options={"default": false}) |
59
|
|
|
*/ |
60
|
|
|
protected $sticky = false; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var bool |
64
|
|
|
* @ORM\Column(type="boolean", options={"default": false}) |
65
|
|
|
*/ |
66
|
|
|
protected $closed = false; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var DateTime |
70
|
|
|
* @ORM\Column(type="datetime") |
71
|
|
|
*/ |
72
|
|
|
protected $created_on; |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @var User|null |
76
|
|
|
* @ORM\ManyToOne(targetEntity="\App\Entity\User") |
77
|
|
|
* @ORM\JoinColumn(name="last_post_user_id", referencedColumnName="id") |
78
|
|
|
*/ |
79
|
|
|
protected $last_post_user; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var DateTime|null |
83
|
|
|
* @ORM\Column(type="datetime", nullable=true) |
84
|
|
|
*/ |
85
|
|
|
protected $last_post_time; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @var Collection |
89
|
|
|
* @ORM\OneToMany(targetEntity="Post", mappedBy="thread", cascade={"persist", "remove"}, orphanRemoval=true) |
90
|
|
|
*/ |
91
|
|
|
protected $posts; |
92
|
|
|
|
93
|
|
|
public function __construct() |
94
|
|
|
{ |
95
|
|
|
$this->posts = new ArrayCollection(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return int The ID |
100
|
|
|
*/ |
101
|
|
|
public function getId(): int |
102
|
|
|
{ |
103
|
|
|
return $this->id; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return User The user |
108
|
|
|
*/ |
109
|
|
|
public function getUser(): User |
110
|
|
|
{ |
111
|
|
|
return $this->user; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param User $user The user |
116
|
|
|
* |
117
|
|
|
* @return $this |
118
|
|
|
*/ |
119
|
|
|
public function setUser(User $user): self |
120
|
|
|
{ |
121
|
|
|
$this->user = $user; |
122
|
|
|
|
123
|
|
|
return $this; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @return Board The board |
128
|
|
|
*/ |
129
|
|
|
public function getBoard(): Board |
130
|
|
|
{ |
131
|
|
|
return $this->board; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param Board $board The board |
136
|
|
|
* |
137
|
|
|
* @return $this |
138
|
|
|
*/ |
139
|
|
|
public function setBoard(Board $board): self |
140
|
|
|
{ |
141
|
|
|
$this->board = $board; |
142
|
|
|
|
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return string The topic |
148
|
|
|
*/ |
149
|
|
|
public function getTopic(): string |
150
|
|
|
{ |
151
|
|
|
return $this->topic; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param string $topic The topic |
156
|
|
|
* |
157
|
|
|
* @return $this |
158
|
|
|
*/ |
159
|
|
|
public function setTopic(string $topic): self |
160
|
|
|
{ |
161
|
|
|
$this->topic = $topic; |
162
|
|
|
|
163
|
|
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @return int The views |
168
|
|
|
*/ |
169
|
|
|
public function getViews(): int |
170
|
|
|
{ |
171
|
|
|
return $this->views; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @param int $views The views |
176
|
|
|
* |
177
|
|
|
* @return $this |
178
|
|
|
*/ |
179
|
|
|
public function setViews(int $views): self |
180
|
|
|
{ |
181
|
|
|
$this->views = $views; |
182
|
|
|
|
183
|
|
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @return int The replies |
188
|
|
|
*/ |
189
|
|
|
public function getReplies(): int |
190
|
|
|
{ |
191
|
|
|
return $this->replies; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @param int $replies The replies |
196
|
|
|
* |
197
|
|
|
* @return $this |
198
|
|
|
*/ |
199
|
|
|
public function setReplies(int $replies): self |
200
|
|
|
{ |
201
|
|
|
$this->replies = $replies; |
202
|
|
|
|
203
|
|
|
return $this; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @return bool Whether the thread is sticky |
208
|
|
|
*/ |
209
|
|
|
public function isSticky(): bool |
210
|
|
|
{ |
211
|
|
|
return $this->sticky; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @param bool $sticky Whether the thread is sticky |
216
|
|
|
* |
217
|
|
|
* @return $this |
218
|
|
|
*/ |
219
|
|
|
public function setSticky(bool $sticky): self |
220
|
|
|
{ |
221
|
|
|
$this->sticky = $sticky; |
222
|
|
|
|
223
|
|
|
return $this; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
/** |
227
|
|
|
* @return bool Whether the thread is closed |
228
|
|
|
*/ |
229
|
|
|
public function isClosed(): bool |
230
|
|
|
{ |
231
|
|
|
return $this->closed; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* @param bool $closed Whether the thread is closed |
236
|
|
|
* |
237
|
|
|
* @return $this |
238
|
|
|
*/ |
239
|
|
|
public function setClosed(bool $closed): self |
240
|
|
|
{ |
241
|
|
|
$this->closed = $closed; |
242
|
|
|
|
243
|
|
|
return $this; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @return DateTime The date when the thread was created |
248
|
|
|
*/ |
249
|
|
|
public function getCreatedOn(): DateTime |
250
|
|
|
{ |
251
|
|
|
return $this->created_on; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* @param DateTime $created_on The date when the thread was created |
256
|
|
|
* |
257
|
|
|
* @return $this |
258
|
|
|
*/ |
259
|
|
|
public function setCreatedOn(DateTime $created_on): self |
260
|
|
|
{ |
261
|
|
|
$this->created_on = $created_on; |
262
|
|
|
|
263
|
|
|
return $this; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* @return User|null The user of the last post |
268
|
|
|
*/ |
269
|
|
|
public function getLastPostUser(): ?User |
270
|
|
|
{ |
271
|
|
|
return $this->last_post_user; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* @param User|null $last_post_user The user of the last post |
276
|
|
|
* |
277
|
|
|
* @return $this |
278
|
|
|
*/ |
279
|
|
|
public function setLastPostUser(User $last_post_user = null): self |
280
|
|
|
{ |
281
|
|
|
$this->last_post_user = $last_post_user; |
282
|
|
|
|
283
|
|
|
return $this; |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
/** |
287
|
|
|
* @return DateTime|null The last time something was posted |
288
|
|
|
*/ |
289
|
|
|
public function getLastPostTime(): ?DateTime |
290
|
|
|
{ |
291
|
|
|
return $this->last_post_time; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* @param DateTime|null $last_post_time The last time something was posted |
296
|
|
|
* |
297
|
|
|
* @return $this |
298
|
|
|
*/ |
299
|
|
|
public function setLastPostTime(DateTime $last_post_time = null): self |
300
|
|
|
{ |
301
|
|
|
$this->last_post_time = $last_post_time; |
302
|
|
|
|
303
|
|
|
return $this; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* @return Post[] The posts |
308
|
|
|
*/ |
309
|
|
|
public function getPosts(): array |
310
|
|
|
{ |
311
|
|
|
return $this->posts->toArray(); |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* @param Post $post The post |
316
|
|
|
* |
317
|
|
|
* @return $this |
318
|
|
|
*/ |
319
|
|
|
public function addPost(Post $post): self |
320
|
|
|
{ |
321
|
|
|
$this->posts->add($post); |
322
|
|
|
$post->setThread($this); |
323
|
|
|
|
324
|
|
|
return $this; |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* @param Post $post The post |
329
|
|
|
* |
330
|
|
|
* @return $this |
331
|
|
|
*/ |
332
|
|
|
public function removePost(Post $post): self |
333
|
|
|
{ |
334
|
|
|
if ($this->posts->contains($post)) { |
335
|
|
|
$this->posts->removeElement($post); |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
return $this; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* @return array An array of all the properties of an object |
343
|
|
|
*/ |
344
|
|
|
public function toArray(): array |
345
|
|
|
{ |
346
|
|
|
return [ |
347
|
|
|
'id' => $this->id, |
348
|
|
|
'user' => $this->user, |
349
|
|
|
'board' => $this->board, |
350
|
|
|
'topic' => $this->topic, |
351
|
|
|
'views' => $this->views, |
352
|
|
|
'replies' => $this->replies, |
353
|
|
|
'sticky' => $this->sticky, |
354
|
|
|
'closed' => $this->closed, |
355
|
|
|
'created_on' => $this->created_on, |
356
|
|
|
'last_post_user' => $this->last_post_user, |
357
|
|
|
'last_post_time' => $this->last_post_time, |
358
|
|
|
]; |
359
|
|
|
} |
360
|
|
|
} |
361
|
|
|
|