|
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 DateTime; |
|
13
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
14
|
|
|
use Doctrine\Common\Collections\Collection; |
|
15
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
16
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* CForumPost. |
|
20
|
|
|
* |
|
21
|
|
|
* @ORM\Table( |
|
22
|
|
|
* name="c_forum_post", |
|
23
|
|
|
* indexes={ |
|
24
|
|
|
* @ORM\Index(name="forum_id", columns={"forum_id"}), |
|
25
|
|
|
* @ORM\Index(name="idx_forum_post_thread_id", columns={"thread_id"}), |
|
26
|
|
|
* @ORM\Index(name="idx_forum_post_visible", columns={"visible"}), |
|
27
|
|
|
* } |
|
28
|
|
|
* ) |
|
29
|
|
|
* @ORM\Entity |
|
30
|
|
|
*/ |
|
31
|
|
|
class CForumPost extends AbstractResource implements ResourceInterface |
|
32
|
|
|
{ |
|
33
|
|
|
public const STATUS_VALIDATED = 1; |
|
34
|
|
|
public const STATUS_WAITING_MODERATION = 2; |
|
35
|
|
|
public const STATUS_REJECTED = 3; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @ORM\Column(name="iid", type="integer") |
|
39
|
|
|
* @ORM\Id |
|
40
|
|
|
* @ORM\GeneratedValue |
|
41
|
|
|
*/ |
|
42
|
|
|
protected int $iid; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @Assert\NotBlank() |
|
46
|
|
|
* @ORM\Column(name="post_title", type="string", length=250, nullable=false) |
|
47
|
|
|
*/ |
|
48
|
|
|
protected string $postTitle; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @ORM\Column(name="post_text", type="text", nullable=true) |
|
52
|
|
|
*/ |
|
53
|
|
|
protected ?string $postText = null; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CForumThread", inversedBy="posts") |
|
57
|
|
|
* @ORM\JoinColumn(name="thread_id", referencedColumnName="iid", nullable=true, onDelete="SET NULL") |
|
58
|
|
|
*/ |
|
59
|
|
|
protected ?CForumThread $thread = null; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CForumForum", inversedBy="posts") |
|
63
|
|
|
* @ORM\JoinColumn(name="forum_id", referencedColumnName="iid", nullable=true, onDelete="SET NULL") |
|
64
|
|
|
*/ |
|
65
|
|
|
protected ?CForumForum $forum = null; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User") |
|
69
|
|
|
* @ORM\JoinColumn(name="poster_id", referencedColumnName="id") |
|
70
|
|
|
*/ |
|
71
|
|
|
protected ?User $user = null; |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @ORM\Column(name="post_date", type="datetime", nullable=false) |
|
75
|
|
|
*/ |
|
76
|
|
|
protected DateTime $postDate; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @ORM\Column(name="post_notification", type="boolean", nullable=true) |
|
80
|
|
|
*/ |
|
81
|
|
|
protected ?bool $postNotification = null; |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CForumPost") |
|
85
|
|
|
* @ORM\JoinColumn(name="post_parent_id", referencedColumnName="iid") |
|
86
|
|
|
*/ |
|
87
|
|
|
protected ?CForumPost $postParent = null; |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @var Collection|CForumPost[] |
|
91
|
|
|
* @ORM\OneToMany(targetEntity="CForumPost", mappedBy="postParent") |
|
92
|
|
|
*/ |
|
93
|
|
|
protected Collection $children; |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @ORM\Column(name="visible", type="boolean", nullable=false) |
|
97
|
|
|
*/ |
|
98
|
|
|
protected bool $visible; |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @ORM\Column(name="status", type="integer", nullable=true) |
|
102
|
|
|
*/ |
|
103
|
|
|
protected ?int $status = null; |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @var Collection|CForumAttachment[] |
|
107
|
|
|
* |
|
108
|
|
|
* @ORM\OneToMany( |
|
109
|
|
|
* targetEntity="Chamilo\CourseBundle\Entity\CForumAttachment", |
|
110
|
|
|
* mappedBy="post", cascade={"persist", "remove"}, orphanRemoval=true |
|
111
|
|
|
* ) |
|
112
|
|
|
*/ |
|
113
|
|
|
protected Collection $attachments; |
|
114
|
|
|
|
|
115
|
|
|
public function __construct() |
|
116
|
|
|
{ |
|
117
|
|
|
$this->visible = false; |
|
118
|
|
|
$this->attachments = new ArrayCollection(); |
|
119
|
|
|
$this->children = new ArrayCollection(); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function __toString(): string |
|
123
|
|
|
{ |
|
124
|
|
|
return (string) $this->getPostTitle(); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public function setPostTitle(string $postTitle): self |
|
128
|
|
|
{ |
|
129
|
|
|
$this->postTitle = $postTitle; |
|
130
|
|
|
|
|
131
|
|
|
return $this; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* Get postTitle. |
|
136
|
|
|
* |
|
137
|
|
|
* @return string |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getPostTitle() |
|
140
|
|
|
{ |
|
141
|
|
|
return $this->postTitle; |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function setPostText(string $postText): self |
|
145
|
|
|
{ |
|
146
|
|
|
$this->postText = $postText; |
|
147
|
|
|
|
|
148
|
|
|
return $this; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
public function getPostText(): ?string |
|
152
|
|
|
{ |
|
153
|
|
|
return $this->postText; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
public function setThread(CForumThread $thread = null): self |
|
157
|
|
|
{ |
|
158
|
|
|
$this->thread = $thread; |
|
159
|
|
|
|
|
160
|
|
|
return $this; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
public function getThread(): CForumThread |
|
164
|
|
|
{ |
|
165
|
|
|
return $this->thread; |
|
|
|
|
|
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
public function setPostDate(DateTime $postDate): self |
|
169
|
|
|
{ |
|
170
|
|
|
$this->postDate = $postDate; |
|
171
|
|
|
|
|
172
|
|
|
return $this; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
/** |
|
176
|
|
|
* Get postDate. |
|
177
|
|
|
* |
|
178
|
|
|
* @return DateTime |
|
179
|
|
|
*/ |
|
180
|
|
|
public function getPostDate() |
|
181
|
|
|
{ |
|
182
|
|
|
return $this->postDate; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
public function setPostNotification(bool $postNotification): self |
|
186
|
|
|
{ |
|
187
|
|
|
$this->postNotification = $postNotification; |
|
188
|
|
|
|
|
189
|
|
|
return $this; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* Get postNotification. |
|
194
|
|
|
* |
|
195
|
|
|
* @return bool |
|
196
|
|
|
*/ |
|
197
|
|
|
public function getPostNotification() |
|
198
|
|
|
{ |
|
199
|
|
|
return $this->postNotification; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
public function setVisible(bool $visible): self |
|
203
|
|
|
{ |
|
204
|
|
|
$this->visible = $visible; |
|
205
|
|
|
|
|
206
|
|
|
return $this; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* Get visible. |
|
211
|
|
|
* |
|
212
|
|
|
* @return bool |
|
213
|
|
|
*/ |
|
214
|
|
|
public function getVisible() |
|
215
|
|
|
{ |
|
216
|
|
|
return $this->visible; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @return int |
|
221
|
|
|
*/ |
|
222
|
|
|
public function getStatus() |
|
223
|
|
|
{ |
|
224
|
|
|
return $this->status; |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
public function setStatus(int $status): self |
|
228
|
|
|
{ |
|
229
|
|
|
$this->status = $status; |
|
230
|
|
|
|
|
231
|
|
|
return $this; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* Get iid. |
|
236
|
|
|
* |
|
237
|
|
|
* @return int |
|
238
|
|
|
*/ |
|
239
|
|
|
public function getIid() |
|
240
|
|
|
{ |
|
241
|
|
|
return $this->iid; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
public function getAttachments(): Collection |
|
245
|
|
|
{ |
|
246
|
|
|
return $this->attachments; |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
public function removeAttachment(CForumAttachment $attachment): void |
|
250
|
|
|
{ |
|
251
|
|
|
$this->attachments->removeElement($attachment); |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
public function getForum(): ?CForumForum |
|
255
|
|
|
{ |
|
256
|
|
|
return $this->forum; |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
public function setForum(?CForumForum $forum): self |
|
260
|
|
|
{ |
|
261
|
|
|
$this->forum = $forum; |
|
262
|
|
|
|
|
263
|
|
|
return $this; |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* @return User |
|
268
|
|
|
*/ |
|
269
|
|
|
public function getUser() |
|
270
|
|
|
{ |
|
271
|
|
|
return $this->user; |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
public function setUser(User $user): self |
|
275
|
|
|
{ |
|
276
|
|
|
$this->user = $user; |
|
277
|
|
|
|
|
278
|
|
|
return $this; |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
public function getPostParent(): ?self |
|
282
|
|
|
{ |
|
283
|
|
|
return $this->postParent; |
|
284
|
|
|
} |
|
285
|
|
|
|
|
286
|
|
|
public function setPostParent(?self $postParent): self |
|
287
|
|
|
{ |
|
288
|
|
|
$this->postParent = $postParent; |
|
289
|
|
|
|
|
290
|
|
|
return $this; |
|
291
|
|
|
} |
|
292
|
|
|
|
|
293
|
|
|
/** |
|
294
|
|
|
* @return CForumPost[]|Collection |
|
295
|
|
|
*/ |
|
296
|
|
|
public function getChildren() |
|
297
|
|
|
{ |
|
298
|
|
|
return $this->children; |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
/** |
|
302
|
|
|
* @param CForumPost[]|Collection $children |
|
303
|
|
|
*/ |
|
304
|
|
|
public function setChildren(Collection $children): self |
|
305
|
|
|
{ |
|
306
|
|
|
$this->children = $children; |
|
307
|
|
|
|
|
308
|
|
|
return $this; |
|
309
|
|
|
} |
|
310
|
|
|
|
|
311
|
|
|
public function getResourceIdentifier(): int |
|
312
|
|
|
{ |
|
313
|
|
|
return $this->getIid(); |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
public function getResourceName(): string |
|
317
|
|
|
{ |
|
318
|
|
|
return $this->getPostTitle(); |
|
319
|
|
|
} |
|
320
|
|
|
|
|
321
|
|
|
public function setResourceName(string $name): self |
|
322
|
|
|
{ |
|
323
|
|
|
return $this->setPostTitle($name); |
|
324
|
|
|
} |
|
325
|
|
|
} |
|
326
|
|
|
|