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_boards") |
13
|
|
|
*/ |
14
|
|
|
class Board |
15
|
|
|
{ |
16
|
|
|
public const TYPE_BOARD = 1; |
17
|
|
|
public const TYPE_CATEGORY = 2; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var int |
21
|
|
|
* @ORM\Id |
22
|
|
|
* @ORM\GeneratedValue |
23
|
|
|
* @ORM\Column(type="integer") |
24
|
|
|
*/ |
25
|
|
|
protected $id; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var Forum |
29
|
|
|
* @ORM\ManyToOne(targetEntity="Forum", inversedBy="boards") |
30
|
|
|
* @ORM\JoinColumn(name="forum_id", referencedColumnName="id", nullable=false) |
31
|
|
|
*/ |
32
|
|
|
protected $forum; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var Board|null |
36
|
|
|
* @ORM\ManyToOne(targetEntity="Board", inversedBy="boards") |
37
|
|
|
* @ORM\JoinColumn(name="parent_board_id", referencedColumnName="id") |
38
|
|
|
*/ |
39
|
|
|
protected $parent_board; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
* @ORM\Column(type="string") |
44
|
|
|
*/ |
45
|
|
|
protected $title; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string|null |
49
|
|
|
* @ORM\Column(type="string", nullable=true) |
50
|
|
|
*/ |
51
|
|
|
protected $description; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @var int |
55
|
|
|
* @ORM\Column(type="smallint") |
56
|
|
|
*/ |
57
|
|
|
protected $type; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var User|null |
61
|
|
|
* @ORM\ManyToOne(targetEntity="\App\Entity\User") |
62
|
|
|
* @ORM\JoinColumn(name="last_post_user_id", referencedColumnName="id") |
63
|
|
|
*/ |
64
|
|
|
protected $last_post_user; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @var DateTime|null |
68
|
|
|
* @ORM\Column(type="datetime", nullable=true) |
69
|
|
|
*/ |
70
|
|
|
protected $last_post_time; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var int |
74
|
|
|
* @ORM\Column(type="integer", options={"default": 0}) |
75
|
|
|
*/ |
76
|
|
|
protected $thread_count = 0; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @var int |
80
|
|
|
* @ORM\Column(type="integer", options={"default": 0}) |
81
|
|
|
*/ |
82
|
|
|
protected $post_count = 0; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var Collection |
86
|
|
|
* @ORM\OneToMany(targetEntity="Board", mappedBy="parent_board", cascade={"persist", "remove"}, orphanRemoval=true) |
87
|
|
|
*/ |
88
|
|
|
protected $boards; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @var Collection |
92
|
|
|
* @ORM\OneToMany(targetEntity="Thread", mappedBy="board", cascade={"persist", "remove"}, orphanRemoval=true) |
93
|
|
|
*/ |
94
|
|
|
protected $threads; |
95
|
|
|
|
96
|
|
|
public function __construct() |
97
|
|
|
{ |
98
|
|
|
$this->boards = new ArrayCollection(); |
99
|
|
|
$this->threads = new ArrayCollection(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return int The ID |
104
|
|
|
*/ |
105
|
|
|
public function getId(): int |
106
|
|
|
{ |
107
|
|
|
return $this->id; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @return Forum The forum |
112
|
|
|
*/ |
113
|
|
|
public function getForum(): Forum |
114
|
|
|
{ |
115
|
|
|
return $this->forum; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param Forum $forum The forum |
120
|
|
|
* |
121
|
|
|
* @return $this |
122
|
|
|
*/ |
123
|
|
|
public function setForum(Forum $forum): self |
124
|
|
|
{ |
125
|
|
|
$this->forum = $forum; |
126
|
|
|
|
127
|
|
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @return Board|null The parent board or null if already the top-most board |
132
|
|
|
*/ |
133
|
|
|
public function getParentBoard(): ?self |
134
|
|
|
{ |
135
|
|
|
return $this->parent_board; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @param Board|null $parent_board The parent board or null if already the top-most board |
140
|
|
|
* |
141
|
|
|
* @return $this |
142
|
|
|
*/ |
143
|
|
|
public function setParentBoard(self $parent_board = null): self |
144
|
|
|
{ |
145
|
|
|
$this->parent_board = $parent_board; |
146
|
|
|
|
147
|
|
|
return $this; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return string The title |
152
|
|
|
*/ |
153
|
|
|
public function getTitle(): string |
154
|
|
|
{ |
155
|
|
|
return $this->title; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param string $title The title |
160
|
|
|
* |
161
|
|
|
* @return $this |
162
|
|
|
*/ |
163
|
|
|
public function setTitle(string $title): self |
164
|
|
|
{ |
165
|
|
|
$this->title = $title; |
166
|
|
|
|
167
|
|
|
return $this; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @return string|null The description |
172
|
|
|
*/ |
173
|
|
|
public function getDescription(): ?string |
174
|
|
|
{ |
175
|
|
|
return $this->description; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @param string|null $description The description |
180
|
|
|
* |
181
|
|
|
* @return $this |
182
|
|
|
*/ |
183
|
|
|
public function setDescription(string $description = null): self |
184
|
|
|
{ |
185
|
|
|
$this->description = $description; |
186
|
|
|
|
187
|
|
|
return $this; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @return int The type |
192
|
|
|
*/ |
193
|
|
|
public function getType(): int |
194
|
|
|
{ |
195
|
|
|
return $this->type; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param int $type The type |
200
|
|
|
* |
201
|
|
|
* @return $this |
202
|
|
|
*/ |
203
|
|
|
public function setType(int $type): self |
204
|
|
|
{ |
205
|
|
|
$this->type = $type; |
206
|
|
|
|
207
|
|
|
return $this; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @return User|null The use who last posted |
212
|
|
|
*/ |
213
|
|
|
public function getLastPostUser(): ?User |
214
|
|
|
{ |
215
|
|
|
return $this->last_post_user; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @param User|null $last_post_user The user who last posted |
220
|
|
|
* |
221
|
|
|
* @return $this |
222
|
|
|
*/ |
223
|
|
|
public function setLastPostUser(User $last_post_user = null): self |
224
|
|
|
{ |
225
|
|
|
$this->last_post_user = $last_post_user; |
226
|
|
|
|
227
|
|
|
return $this; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @return DateTime|null The last time somebody posted |
232
|
|
|
*/ |
233
|
|
|
public function getLastPostTime(): ?DateTime |
234
|
|
|
{ |
235
|
|
|
return $this->last_post_time; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @param DateTime|null $last_post_time The last time somebody posted |
240
|
|
|
* |
241
|
|
|
* @return $this |
242
|
|
|
*/ |
243
|
|
|
public function setLastPostTime(DateTime $last_post_time = null): self |
244
|
|
|
{ |
245
|
|
|
$this->last_post_time = $last_post_time; |
246
|
|
|
|
247
|
|
|
return $this; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @return int The number of threads |
252
|
|
|
*/ |
253
|
|
|
public function getThreadCount(): int |
254
|
|
|
{ |
255
|
|
|
return $this->thread_count; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @param int $threads The number of threads |
260
|
|
|
* |
261
|
|
|
* @return $this |
262
|
|
|
*/ |
263
|
|
|
public function setThreadCount(int $threads): self |
264
|
|
|
{ |
265
|
|
|
$this->thread_count = $threads; |
266
|
|
|
|
267
|
|
|
return $this; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @return int The number of posts |
272
|
|
|
*/ |
273
|
|
|
public function getPostCount(): int |
274
|
|
|
{ |
275
|
|
|
return $this->post_count; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* @param int $posts The number of posts |
280
|
|
|
* |
281
|
|
|
* @return $this |
282
|
|
|
*/ |
283
|
|
|
public function setPostCount(int $posts): self |
284
|
|
|
{ |
285
|
|
|
$this->post_count = $posts; |
286
|
|
|
|
287
|
|
|
return $this; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* @return Thread[] The threads |
292
|
|
|
*/ |
293
|
|
|
public function getThreads(): array |
294
|
|
|
{ |
295
|
|
|
return $this->threads->toArray(); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* @param Thread $thread The thread |
300
|
|
|
* |
301
|
|
|
* @return $this |
302
|
|
|
*/ |
303
|
|
|
public function addThread(Thread $thread): self |
304
|
|
|
{ |
305
|
|
|
$this->threads->add($thread); |
306
|
|
|
$thread->setBoard($this); |
307
|
|
|
|
308
|
|
|
return $this; |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* @param Thread $thread The thread |
313
|
|
|
* |
314
|
|
|
* @return $this |
315
|
|
|
*/ |
316
|
|
|
public function removeThread(Thread $thread): self |
317
|
|
|
{ |
318
|
|
|
if ($this->threads->contains($thread)) { |
319
|
|
|
$this->threads->removeElement($thread); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
return $this; |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
/** |
326
|
|
|
* @return Board[] The boards |
327
|
|
|
*/ |
328
|
|
|
public function getBoards(): array |
329
|
|
|
{ |
330
|
|
|
return $this->boards->toArray(); |
331
|
|
|
} |
332
|
|
|
|
333
|
|
|
/** |
334
|
|
|
* @param Board $board The board |
335
|
|
|
* |
336
|
|
|
* @return $this |
337
|
|
|
*/ |
338
|
|
|
public function addBoard(self $board): self |
339
|
|
|
{ |
340
|
|
|
$this->boards->add($board); |
341
|
|
|
$board->setParentBoard($this); |
342
|
|
|
|
343
|
|
|
return $this; |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* @param Board $board The board |
348
|
|
|
* |
349
|
|
|
* @return $this |
350
|
|
|
*/ |
351
|
|
|
public function removeBoard(self $board): self |
352
|
|
|
{ |
353
|
|
|
if ($this->boards->contains($board)) { |
354
|
|
|
$this->boards->removeElement($board); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
return $this; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* @return array An array of all the properties of an object |
362
|
|
|
*/ |
363
|
|
|
public function toArray(): array |
364
|
|
|
{ |
365
|
|
|
return [ |
366
|
|
|
'id' => $this->id, |
367
|
|
|
'forum' => $this->forum, |
368
|
|
|
'parent_board' => $this->parent_board, |
369
|
|
|
'title' => $this->title, |
370
|
|
|
'description' => $this->description, |
371
|
|
|
'type' => $this->type, |
372
|
|
|
'last_post_user' => $this->last_post_user, |
373
|
|
|
'last_post_time' => $this->last_post_time, |
374
|
|
|
'threads' => $this->thread_count, |
375
|
|
|
'posts' => $this->post_count, |
376
|
|
|
]; |
377
|
|
|
} |
378
|
|
|
} |
379
|
|
|
|