Passed
Push — master ( ab8dec...906584 )
by Julito
09:36
created

Message::getAttachments()   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
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Entity;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\ORM\Mapping as ORM;
9
use Symfony\Component\Validator\Constraints as Assert;
10
11
/**
12
 * Message.
13
 *
14
 * @ORM\Table(name="message", indexes={
15
 *     @ORM\Index(name="idx_message_user_sender", columns={"user_sender_id"}),
16
 *     @ORM\Index(name="idx_message_user_receiver", columns={"user_receiver_id"}),
17
 *     @ORM\Index(name="idx_message_user_sender_user_receiver", columns={"user_sender_id", "user_receiver_id"}),
18
 *     @ORM\Index(name="idx_message_user_receiver_status", columns={"user_receiver_id", "msg_status"}),
19
 *     @ORM\Index(name="idx_message_receiver_status_send_date", columns={"user_receiver_id", "msg_status", "send_date"}),
20
 *     @ORM\Index(name="idx_message_group", columns={"group_id"}),
21
 *     @ORM\Index(name="idx_message_status", columns={"msg_status"})
22
 * })
23
 * @ORM\Entity(repositoryClass="Chamilo\CoreBundle\Repository\MessageRepository")
24
 */
25
class Message
26
{
27
    /**
28
     * @var int
29
     *
30
     * @ORM\Column(name="id", type="bigint")
31
     * @ORM\Id
32
     * @ORM\GeneratedValue()
33
     */
34
    protected $id;
35
36
    /**
37
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", inversedBy="sentMessages")
38
     * @ORM\JoinColumn(name="user_sender_id", referencedColumnName="id", nullable=false)
39
     */
40
    protected User $userSender;
41
42
    /**
43
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", inversedBy="receivedMessages")
44
     * @ORM\JoinColumn(name="user_receiver_id", referencedColumnName="id", nullable=true)
45
     */
46
    protected User $userReceiver;
47
48
    /**
49
     * @ORM\Column(name="msg_status", type="smallint", nullable=false)
50
     */
51
    protected int $msgStatus;
52
53
    /**
54
     * @ORM\Column(name="send_date", type="datetime", nullable=false)
55
     */
56
    protected \DateTime $sendDate;
57
58
    /**
59
     * @Assert\NotBlank
60
     * @ORM\Column(name="title", type="string", length=255, nullable=false)
61
     */
62
    protected string $title;
63
64
    /**
65
     * @Assert\NotBlank
66
     *
67
     * @ORM\Column(name="content", type="text", nullable=false)
68
     */
69
    protected string $content;
70
71
    /**
72
     * @var int
73
     *
74
     * @ORM\Column(name="group_id", type="integer", nullable=false)
75
     */
76
    protected $groupId;
77
78
    /**
79
     * @var ArrayCollection|Message[]
80
     * @ORM\OneToMany(targetEntity="Message", mappedBy="parent")
81
     */
82
    protected $children;
83
84
    /**
85
     * @ORM\ManyToOne(targetEntity="Message", inversedBy="children")
86
     * @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
87
     */
88
    protected ?Message $parent;
89
90
    /**
91
     * @var \DateTime
92
     *
93
     * @ORM\Column(name="update_date", type="datetime", nullable=true)
94
     */
95
    protected $updateDate;
96
97
    /**
98
     * @var int
99
     *
100
     * @ORM\Column(name="votes", type="integer", nullable=true)
101
     */
102
    protected $votes;
103
104
    /**
105
     * @var ArrayCollection|MessageAttachment[]
106
     *
107
     * @ORM\OneToMany(targetEntity="MessageAttachment", mappedBy="message")
108
     */
109
    protected $attachments;
110
111
    /**
112
     * @var ArrayCollection|MessageFeedback[]
113
     *
114
     * @ORM\OneToMany(targetEntity="MessageFeedback", mappedBy="message", orphanRemoval=true)
115
     */
116
    protected $likes;
117
118
    public function __construct()
119
    {
120
        $this->sendDate = new \DateTime('now');
121
        $this->updateDate = $this->sendDate;
122
        $this->content = '';
123
        $this->attachments = new ArrayCollection();
124
        $this->children = new ArrayCollection();
125
        $this->likes = new ArrayCollection();
126
        $this->votes = 0;
127
    }
128
129
    /**
130
     * Set userSender.
131
     */
132
    public function setUserSender(User $userSender): self
133
    {
134
        $this->userSender = $userSender;
135
136
        return $this;
137
    }
138
139
    /**
140
     * Get userSender.
141
     */
142
    public function getUserSender(): User
143
    {
144
        return $this->userSender;
145
    }
146
147
    /**
148
     * Set userReceiver.
149
     */
150
    public function setUserReceiver(User $userReceiver): self
151
    {
152
        $this->userReceiver = $userReceiver;
153
154
        return $this;
155
    }
156
157
    /**
158
     * Get userReceiver.
159
     *
160
     * @return User
161
     */
162
    public function getUserReceiver()
163
    {
164
        return $this->userReceiver;
165
    }
166
167
    /**
168
     * Set msgStatus.
169
     */
170
    public function setMsgStatus(int $msgStatus): self
171
    {
172
        $this->msgStatus = $msgStatus;
173
174
        return $this;
175
    }
176
177
    /**
178
     * Get msgStatus.
179
     */
180
    public function getMsgStatus(): int
181
    {
182
        return $this->msgStatus;
183
    }
184
185
    /**
186
     * Set sendDate.
187
     *
188
     * @param \DateTime $sendDate
189
     *
190
     * @return Message
191
     */
192
    public function setSendDate($sendDate)
193
    {
194
        $this->sendDate = $sendDate;
195
196
        return $this;
197
    }
198
199
    /**
200
     * Get sendDate.
201
     *
202
     * @return \DateTime
203
     */
204
    public function getSendDate()
205
    {
206
        return $this->sendDate;
207
    }
208
209
    /**
210
     * Set title.
211
     *
212
     * @param string $title
213
     */
214
    public function setTitle($title): self
215
    {
216
        $this->title = $title;
217
218
        return $this;
219
    }
220
221
    /**
222
     * Get title.
223
     *
224
     * @return string
225
     */
226
    public function getTitle()
227
    {
228
        return $this->title;
229
    }
230
231
    /**
232
     * Set content.
233
     *
234
     * @param string $content
235
     */
236
    public function setContent($content): self
237
    {
238
        $this->content = $content;
239
240
        return $this;
241
    }
242
243
    /**
244
     * Get content.
245
     *
246
     * @return string
247
     */
248
    public function getContent()
249
    {
250
        return $this->content;
251
    }
252
253
    /**
254
     * Set groupId.
255
     *
256
     * @param int $groupId
257
     *
258
     * @return Message
259
     */
260
    public function setGroupId($groupId)
261
    {
262
        $this->groupId = $groupId;
263
264
        return $this;
265
    }
266
267
    /**
268
     * Get groupId.
269
     *
270
     * @return int
271
     */
272
    public function getGroupId()
273
    {
274
        return $this->groupId;
275
    }
276
277
    /**
278
     * Set updateDate.
279
     *
280
     * @param \DateTime $updateDate
281
     *
282
     * @return Message
283
     */
284
    public function setUpdateDate($updateDate)
285
    {
286
        $this->updateDate = $updateDate;
287
288
        return $this;
289
    }
290
291
    /**
292
     * Get updateDate.
293
     *
294
     * @return \DateTime
295
     */
296
    public function getUpdateDate()
297
    {
298
        return $this->updateDate;
299
    }
300
301
    /**
302
     * Get id.
303
     *
304
     * @return int
305
     */
306
    public function getId()
307
    {
308
        return $this->id;
309
    }
310
311
    /**
312
     * Set votes.
313
     *
314
     * @param int $votes
315
     */
316
    public function setVotes($votes): self
317
    {
318
        $this->votes = $votes;
319
320
        return $this;
321
    }
322
323
    /**
324
     * Get votes.
325
     *
326
     * @return int
327
     */
328
    public function getVotes()
329
    {
330
        return $this->votes;
331
    }
332
333
    /**
334
     * Get attachments.
335
     *
336
     * @return MessageAttachment[]|ArrayCollection
337
     */
338
    public function getAttachments()
339
    {
340
        return $this->attachments;
341
    }
342
343
    public function addAttachment(MessageAttachment $attachment): self
344
    {
345
        $this->attachments->add($attachment);
346
        $attachment->setMessage($this);
347
348
        return $this;
349
    }
350
351
    public function getParent(): self
352
    {
353
        return $this->parent;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->parent could return the type null which is incompatible with the type-hinted return Chamilo\CoreBundle\Entity\Message. Consider adding an additional type-check to rule them out.
Loading history...
354
    }
355
356
    /**
357
     * @return ArrayCollection|Message[]
358
     */
359
    public function getChildren()
360
    {
361
        return $this->children;
362
    }
363
364
    public function addChild(self $child): self
365
    {
366
        $this->children[] = $child;
367
        $child->setParent($this);
368
369
        return $this;
370
    }
371
372
    public function setParent(self $parent): self
373
    {
374
        $this->parent = $parent;
375
376
        return $this;
377
    }
378
379
    /**
380
     * Get an excerpt from the content.
381
     *
382
     * @param int $length Optional. Length of the excerpt.
383
     *
384
     * @return string
385
     */
386
    public function getExcerpt($length = 50)
387
    {
388
        $striped = strip_tags($this->content);
389
        $replaced = str_replace(["\r\n", "\n"], ' ', $striped);
390
        $trimmed = trim($replaced);
391
392
        return api_trunc_str($trimmed, $length);
393
    }
394
}
395