Passed
Push — master ( ea0e05...21d25a )
by Julito
08:49
created

CForumPost::getThread()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\Column(name="post_parent_id", type="integer", nullable=true)
85
     */
86
    protected ?int $postParentId = null;
87
88
    /**
89
     * @ORM\Column(name="visible", type="boolean", nullable=false)
90
     */
91
    protected bool $visible;
92
93
    /**
94
     * @ORM\Column(name="status", type="integer", nullable=true)
95
     */
96
    protected ?int $status = null;
97
98
    /**
99
     * @var Collection|CForumAttachment[]
100
     *
101
     * @ORM\OneToMany(
102
     *     targetEntity="Chamilo\CourseBundle\Entity\CForumAttachment",
103
     *     mappedBy="post", cascade={"persist", "remove"}, orphanRemoval=true
104
     * )
105
     */
106
    protected Collection $attachments;
107
108
    public function __construct()
109
    {
110
        $this->visible = false;
111
        $this->postParentId = null;
112
        $this->attachments = new ArrayCollection();
113
    }
114
115
    public function __toString(): string
116
    {
117
        return (string) $this->getPostTitle();
118
    }
119
120
    /**
121
     * Set postTitle.
122
     *
123
     * @return CForumPost
124
     */
125
    public function setPostTitle(string $postTitle)
126
    {
127
        $this->postTitle = $postTitle;
128
129
        return $this;
130
    }
131
132
    /**
133
     * Get postTitle.
134
     *
135
     * @return string
136
     */
137
    public function getPostTitle()
138
    {
139
        return $this->postTitle;
140
    }
141
142
    public function setPostText(string $postText): self
143
    {
144
        $this->postText = $postText;
145
146
        return $this;
147
    }
148
149
    public function getPostText(): ?string
150
    {
151
        return $this->postText;
152
    }
153
154
    public function setThread(CForumThread $thread = null): self
155
    {
156
        $this->thread = $thread;
157
158
        return $this;
159
    }
160
161
    /**
162
     * Get thread.
163
     *
164
     * @return null|CForumThread
165
     */
166
    public function getThread()
167
    {
168
        return $this->thread;
169
    }
170
171
    /**
172
     * Set postDate.
173
     *
174
     * @return CForumPost
175
     */
176
    public function setPostDate(DateTime $postDate)
177
    {
178
        $this->postDate = $postDate;
179
180
        return $this;
181
    }
182
183
    /**
184
     * Get postDate.
185
     *
186
     * @return DateTime
187
     */
188
    public function getPostDate()
189
    {
190
        return $this->postDate;
191
    }
192
193
    /**
194
     * Set postNotification.
195
     *
196
     * @return CForumPost
197
     */
198
    public function setPostNotification(bool $postNotification)
199
    {
200
        $this->postNotification = $postNotification;
201
202
        return $this;
203
    }
204
205
    /**
206
     * Get postNotification.
207
     *
208
     * @return bool
209
     */
210
    public function getPostNotification()
211
    {
212
        return $this->postNotification;
213
    }
214
215
    /**
216
     * Set postParentId.
217
     *
218
     * @return CForumPost
219
     */
220
    public function setPostParentId(int $postParentId)
221
    {
222
        $this->postParentId = $postParentId;
223
224
        return $this;
225
    }
226
227
    /**
228
     * Get postParentId.
229
     *
230
     * @return int
231
     */
232
    public function getPostParentId()
233
    {
234
        return $this->postParentId;
235
    }
236
237
    /**
238
     * Set visible.
239
     *
240
     * @return CForumPost
241
     */
242
    public function setVisible(bool $visible)
243
    {
244
        $this->visible = $visible;
245
246
        return $this;
247
    }
248
249
    /**
250
     * Get visible.
251
     *
252
     * @return bool
253
     */
254
    public function getVisible()
255
    {
256
        return $this->visible;
257
    }
258
259
    /**
260
     * @return int
261
     */
262
    public function getStatus()
263
    {
264
        return $this->status;
265
    }
266
267
    /**
268
     * @return CForumPost
269
     */
270
    public function setStatus(int $status)
271
    {
272
        $this->status = $status;
273
274
        return $this;
275
    }
276
277
    /**
278
     * Get iid.
279
     *
280
     * @return int
281
     */
282
    public function getIid()
283
    {
284
        return $this->iid;
285
    }
286
287
    public function getAttachments(): Collection
288
    {
289
        return $this->attachments;
290
    }
291
292
    public function removeAttachment(CForumAttachment $attachment): void
293
    {
294
        $this->attachments->removeElement($attachment);
295
    }
296
297
    public function getForum(): ?CForumForum
298
    {
299
        return $this->forum;
300
    }
301
302
    public function setForum(?CForumForum $forum): self
303
    {
304
        $this->forum = $forum;
305
306
        return $this;
307
    }
308
309
    /**
310
     * @return User
311
     */
312
    public function getUser()
313
    {
314
        return $this->user;
315
    }
316
317
    public function setUser(User $user): self
318
    {
319
        $this->user = $user;
320
321
        return $this;
322
    }
323
324
    public function getResourceIdentifier(): int
325
    {
326
        return $this->getIid();
327
    }
328
329
    public function getResourceName(): string
330
    {
331
        return $this->getPostTitle();
332
    }
333
334
    public function setResourceName(string $name): self
335
    {
336
        return $this->setPostTitle($name);
337
    }
338
}
339