|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
|
6
|
|
|
|
|
7
|
|
|
namespace Chamilo\CourseBundle\Entity; |
|
8
|
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Entity\AbstractResource; |
|
10
|
|
|
use Chamilo\CoreBundle\Entity\ResourceInterface; |
|
11
|
|
|
use Chamilo\CoreBundle\Entity\User; |
|
12
|
|
|
use Chamilo\CourseBundle\Repository\CForumThreadRepository; |
|
13
|
|
|
use DateTime; |
|
14
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
15
|
|
|
use Doctrine\Common\Collections\Collection; |
|
16
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
17
|
|
|
use Stringable; |
|
18
|
|
|
use Symfony\Component\Uid\Uuid; |
|
19
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* CForumThread. |
|
23
|
|
|
*/ |
|
24
|
|
|
#[ORM\Table(name: 'c_forum_thread')] |
|
25
|
|
|
#[ORM\Entity(repositoryClass: CForumThreadRepository::class)] |
|
26
|
|
|
class CForumThread extends AbstractResource implements ResourceInterface, Stringable |
|
27
|
|
|
{ |
|
28
|
|
|
#[ORM\Column(name: 'iid', type: 'integer')] |
|
29
|
|
|
#[ORM\Id] |
|
30
|
|
|
#[ORM\GeneratedValue] |
|
31
|
|
|
protected ?int $iid = null; |
|
32
|
|
|
|
|
33
|
|
|
#[Assert\NotBlank] |
|
34
|
|
|
#[ORM\Column(name: 'title', type: 'string', length: 255, nullable: false)] |
|
35
|
|
|
protected string $title; |
|
36
|
|
|
|
|
37
|
|
|
#[ORM\ManyToOne(targetEntity: CForum::class, inversedBy: 'threads')] |
|
38
|
|
|
#[ORM\JoinColumn(name: 'forum_id', referencedColumnName: 'iid', nullable: true, onDelete: 'CASCADE')] |
|
39
|
|
|
protected ?CForum $forum = null; |
|
40
|
|
|
|
|
41
|
|
|
#[ORM\ManyToOne(targetEntity: User::class)] |
|
42
|
|
|
#[ORM\JoinColumn(name: 'thread_poster_id', referencedColumnName: 'id')] |
|
43
|
|
|
protected User $user; |
|
44
|
|
|
|
|
45
|
|
|
#[ORM\ManyToOne(targetEntity: CForumPost::class, cascade: ['persist', 'remove'])] |
|
46
|
|
|
#[ORM\JoinColumn(name: 'thread_last_post', referencedColumnName: 'iid', onDelete: 'SET NULL')] |
|
47
|
|
|
protected ?CForumPost $threadLastPost = null; |
|
48
|
|
|
|
|
49
|
|
|
#[ORM\ManyToOne(targetEntity: CLpItem::class)] |
|
50
|
|
|
#[ORM\JoinColumn(name: 'lp_item_id', referencedColumnName: 'iid', onDelete: 'CASCADE')] |
|
51
|
|
|
protected ?CLpItem $item = null; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var Collection<int, CForumPost> |
|
55
|
|
|
*/ |
|
56
|
|
|
#[ORM\OneToMany(mappedBy: 'thread', targetEntity: CForumPost::class, cascade: ['persist', 'remove'], orphanRemoval: true)] |
|
57
|
|
|
protected Collection $posts; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var Collection<int, CForumThreadQualify> |
|
61
|
|
|
*/ |
|
62
|
|
|
#[ORM\OneToMany(mappedBy: 'thread', targetEntity: CForumThreadQualify::class, cascade: ['persist', 'remove'])] |
|
63
|
|
|
protected Collection $qualifications; |
|
64
|
|
|
|
|
65
|
|
|
#[Assert\NotBlank] |
|
66
|
|
|
#[ORM\Column(name: 'thread_date', type: 'datetime', nullable: false)] |
|
67
|
|
|
protected DateTime $threadDate; |
|
68
|
|
|
|
|
69
|
|
|
#[Assert\NotBlank] |
|
70
|
|
|
#[ORM\Column(name: 'thread_replies', type: 'integer', nullable: false, options: ['unsigned' => true, 'default' => 0])] |
|
71
|
|
|
protected int $threadReplies; |
|
72
|
|
|
|
|
73
|
|
|
#[Assert\NotBlank] |
|
74
|
|
|
#[ORM\Column(name: 'thread_views', type: 'integer', nullable: false, options: ['unsigned' => true, 'default' => 0])] |
|
75
|
|
|
protected int $threadViews; |
|
76
|
|
|
|
|
77
|
|
|
#[Assert\NotNull] |
|
78
|
|
|
#[ORM\Column(name: 'thread_sticky', type: 'boolean', nullable: false)] |
|
79
|
|
|
protected bool $threadSticky; |
|
80
|
|
|
|
|
81
|
|
|
#[Assert\NotBlank] |
|
82
|
|
|
#[ORM\Column(name: 'locked', type: 'integer', nullable: false)] |
|
83
|
|
|
protected int $locked; |
|
84
|
|
|
|
|
85
|
|
|
#[ORM\Column(name: 'thread_title_qualify', type: 'string', length: 255, nullable: true)] |
|
86
|
|
|
protected ?string $threadTitleQualify = null; |
|
87
|
|
|
|
|
88
|
|
|
#[ORM\Column(name: 'thread_qualify_max', type: 'float', precision: 6, scale: 2, nullable: false)] |
|
89
|
|
|
protected float $threadQualifyMax; |
|
90
|
|
|
|
|
91
|
|
|
#[ORM\Column(name: 'thread_close_date', type: 'datetime', nullable: true)] |
|
92
|
|
|
protected ?DateTime $threadCloseDate = null; |
|
93
|
|
|
|
|
94
|
|
|
#[ORM\Column(name: 'thread_weight', type: 'float', precision: 6, scale: 2, nullable: false)] |
|
95
|
|
|
protected float $threadWeight; |
|
96
|
|
|
|
|
97
|
|
|
#[ORM\Column(name: 'thread_peer_qualify', type: 'boolean')] |
|
98
|
|
|
protected bool $threadPeerQualify; |
|
99
|
|
|
|
|
100
|
|
|
public function __construct() |
|
101
|
|
|
{ |
|
102
|
|
|
$this->posts = new ArrayCollection(); |
|
103
|
|
|
$this->qualifications = new ArrayCollection(); |
|
104
|
|
|
$this->threadDate = new DateTime(); |
|
105
|
|
|
$this->threadPeerQualify = false; |
|
106
|
|
|
$this->threadReplies = 0; |
|
107
|
|
|
$this->threadViews = 0; |
|
108
|
|
|
$this->locked = 0; |
|
109
|
|
|
$this->threadQualifyMax = 0; |
|
110
|
|
|
$this->threadWeight = 0; |
|
111
|
|
|
$this->threadSticky = false; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function __toString(): string |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->getTitle(); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
public function isThreadPeerQualify(): bool |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->threadPeerQualify; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
public function setThreadPeerQualify(bool $threadPeerQualify): self |
|
125
|
|
|
{ |
|
126
|
|
|
$this->threadPeerQualify = $threadPeerQualify; |
|
127
|
|
|
|
|
128
|
|
|
return $this; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function setTitle(string $title): self |
|
132
|
|
|
{ |
|
133
|
|
|
$this->title = $title; |
|
134
|
|
|
|
|
135
|
|
|
return $this; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function getTitle(): string |
|
139
|
|
|
{ |
|
140
|
|
|
return $this->title; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function setForum(CForum $forum = null): self |
|
144
|
|
|
{ |
|
145
|
|
|
if (null !== $forum) { |
|
146
|
|
|
$forum->getThreads()->add($this); |
|
147
|
|
|
} |
|
148
|
|
|
$this->forum = $forum; |
|
149
|
|
|
|
|
150
|
|
|
return $this; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public function getForum(): ?CForum |
|
154
|
|
|
{ |
|
155
|
|
|
return $this->forum; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function setThreadReplies(int $threadReplies): self |
|
159
|
|
|
{ |
|
160
|
|
|
$this->threadReplies = $threadReplies; |
|
161
|
|
|
|
|
162
|
|
|
return $this; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
public function getThreadReplies(): int |
|
166
|
|
|
{ |
|
167
|
|
|
return $this->threadReplies; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
public function setThreadViews(int $threadViews): self |
|
171
|
|
|
{ |
|
172
|
|
|
$this->threadViews = $threadViews; |
|
173
|
|
|
|
|
174
|
|
|
return $this; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
public function getThreadViews(): int |
|
178
|
|
|
{ |
|
179
|
|
|
return $this->threadViews; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
public function setThreadDate(DateTime $threadDate): self |
|
183
|
|
|
{ |
|
184
|
|
|
$this->threadDate = $threadDate; |
|
185
|
|
|
|
|
186
|
|
|
return $this; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
public function getThreadDate(): DateTime |
|
190
|
|
|
{ |
|
191
|
|
|
return $this->threadDate; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
public function setThreadSticky(bool $threadSticky): self |
|
195
|
|
|
{ |
|
196
|
|
|
$this->threadSticky = $threadSticky; |
|
197
|
|
|
|
|
198
|
|
|
return $this; |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
public function getThreadSticky(): bool |
|
202
|
|
|
{ |
|
203
|
|
|
return $this->threadSticky; |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
public function setLocked(int $locked): self |
|
207
|
|
|
{ |
|
208
|
|
|
$this->locked = $locked; |
|
209
|
|
|
|
|
210
|
|
|
return $this; |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
public function getLocked(): int |
|
214
|
|
|
{ |
|
215
|
|
|
return $this->locked; |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
public function setThreadTitleQualify(string $threadTitleQualify): self |
|
219
|
|
|
{ |
|
220
|
|
|
$this->threadTitleQualify = $threadTitleQualify; |
|
221
|
|
|
|
|
222
|
|
|
return $this; |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
public function getThreadTitleQualify(): ?string |
|
226
|
|
|
{ |
|
227
|
|
|
return $this->threadTitleQualify; |
|
228
|
|
|
} |
|
229
|
|
|
|
|
230
|
|
|
public function setThreadQualifyMax(float $threadQualifyMax): self |
|
231
|
|
|
{ |
|
232
|
|
|
$this->threadQualifyMax = $threadQualifyMax; |
|
233
|
|
|
|
|
234
|
|
|
return $this; |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
public function getThreadQualifyMax(): float |
|
238
|
|
|
{ |
|
239
|
|
|
return $this->threadQualifyMax; |
|
240
|
|
|
} |
|
241
|
|
|
|
|
242
|
|
|
public function setThreadCloseDate(DateTime $threadCloseDate): self |
|
243
|
|
|
{ |
|
244
|
|
|
$this->threadCloseDate = $threadCloseDate; |
|
245
|
|
|
|
|
246
|
|
|
return $this; |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
public function getThreadCloseDate(): ?DateTime |
|
250
|
|
|
{ |
|
251
|
|
|
return $this->threadCloseDate; |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
public function setThreadWeight(float $threadWeight): self |
|
255
|
|
|
{ |
|
256
|
|
|
$this->threadWeight = $threadWeight; |
|
257
|
|
|
|
|
258
|
|
|
return $this; |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
public function getThreadWeight(): float |
|
262
|
|
|
{ |
|
263
|
|
|
return $this->threadWeight; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
public function getIid(): ?int |
|
267
|
|
|
{ |
|
268
|
|
|
return $this->iid; |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
public function getUser(): User |
|
272
|
|
|
{ |
|
273
|
|
|
return $this->user; |
|
274
|
|
|
} |
|
275
|
|
|
|
|
276
|
|
|
public function setUser(User $user): self |
|
277
|
|
|
{ |
|
278
|
|
|
$this->user = $user; |
|
279
|
|
|
|
|
280
|
|
|
return $this; |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
/** |
|
284
|
|
|
* @return Collection<int, CForumPost> |
|
285
|
|
|
*/ |
|
286
|
|
|
public function getPosts(): Collection |
|
287
|
|
|
{ |
|
288
|
|
|
return $this->posts; |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
public function getThreadLastPost(): ?CForumPost |
|
292
|
|
|
{ |
|
293
|
|
|
return $this->threadLastPost; |
|
294
|
|
|
} |
|
295
|
|
|
|
|
296
|
|
|
public function setThreadLastPost(CForumPost $threadLastPost): self |
|
297
|
|
|
{ |
|
298
|
|
|
$this->threadLastPost = $threadLastPost; |
|
299
|
|
|
|
|
300
|
|
|
return $this; |
|
301
|
|
|
} |
|
302
|
|
|
|
|
303
|
|
|
/** |
|
304
|
|
|
* @return Collection<int, CForumThreadQualify> |
|
305
|
|
|
*/ |
|
306
|
|
|
public function getQualifications(): Collection |
|
307
|
|
|
{ |
|
308
|
|
|
return $this->qualifications; |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
public function setQualifications(Collection $qualifications): self |
|
312
|
|
|
{ |
|
313
|
|
|
$this->qualifications = $qualifications; |
|
314
|
|
|
|
|
315
|
|
|
return $this; |
|
316
|
|
|
} |
|
317
|
|
|
|
|
318
|
|
|
public function getItem(): ?CLpItem |
|
319
|
|
|
{ |
|
320
|
|
|
return $this->item; |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
public function setItem(?CLpItem $item): self |
|
324
|
|
|
{ |
|
325
|
|
|
$this->item = $item; |
|
326
|
|
|
|
|
327
|
|
|
return $this; |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
public function getResourceIdentifier(): int|Uuid |
|
331
|
|
|
{ |
|
332
|
|
|
return $this->getIid(); |
|
|
|
|
|
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
public function getResourceName(): string |
|
336
|
|
|
{ |
|
337
|
|
|
return $this->getTitle(); |
|
338
|
|
|
} |
|
339
|
|
|
|
|
340
|
|
|
public function setResourceName(string $name): self |
|
341
|
|
|
{ |
|
342
|
|
|
return $this->setTitle($name); |
|
343
|
|
|
} |
|
344
|
|
|
} |
|
345
|
|
|
|