1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
6
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Entity; |
8
|
|
|
|
9
|
|
|
use Chamilo\CourseBundle\Entity\CGroup; |
10
|
|
|
use DateTime; |
11
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
12
|
|
|
use Doctrine\Common\Collections\Collection; |
13
|
|
|
use Doctrine\ORM\Mapping as ORM; |
14
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
15
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Message. |
19
|
|
|
* |
20
|
|
|
* @ORM\Table(name="message", indexes={ |
21
|
|
|
* @ORM\Index(name="idx_message_user_sender", columns={"user_sender_id"}), |
22
|
|
|
* @ORM\Index(name="idx_message_user_receiver", columns={"user_receiver_id"}), |
23
|
|
|
* @ORM\Index(name="idx_message_user_sender_user_receiver", columns={"user_sender_id", "user_receiver_id"}), |
24
|
|
|
* @ORM\Index(name="idx_message_user_receiver_status", columns={"user_receiver_id", "msg_status"}), |
25
|
|
|
* @ORM\Index(name="idx_message_receiver_status_send_date", columns={"user_receiver_id", "msg_status", "send_date"}), |
26
|
|
|
* @ORM\Index(name="idx_message_group", columns={"group_id"}), |
27
|
|
|
* @ORM\Index(name="idx_message_status", columns={"msg_status"}) |
28
|
|
|
* }) |
29
|
|
|
* @ORM\Entity(repositoryClass="Chamilo\CoreBundle\Repository\MessageRepository") |
30
|
|
|
*/ |
31
|
|
|
class Message |
32
|
|
|
{ |
33
|
|
|
public const MESSAGE_TYPE_INBOX = 1; |
34
|
|
|
public const MESSAGE_TYPE_OUTBOX = 2; |
35
|
|
|
public const MESSAGE_TYPE_PROMOTED = 3; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @ORM\Column(name="id", type="bigint") |
39
|
|
|
* @ORM\Id |
40
|
|
|
* @ORM\GeneratedValue() |
41
|
|
|
*/ |
42
|
|
|
protected int $id; |
43
|
|
|
|
44
|
|
|
#[Assert\NotBlank] |
45
|
|
|
/** |
46
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", inversedBy="sentMessages") |
47
|
|
|
* @ORM\JoinColumn(name="user_sender_id", referencedColumnName="id", nullable=false) |
48
|
|
|
*/ |
49
|
|
|
protected User $userSender; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", inversedBy="receivedMessages") |
53
|
|
|
* @ORM\JoinColumn(name="user_receiver_id", referencedColumnName="id", nullable=true) |
54
|
|
|
*/ |
55
|
|
|
protected User $userReceiver; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @ORM\Column(name="msg_status", type="smallint", nullable=false) |
59
|
|
|
*/ |
60
|
|
|
protected int $msgStatus; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @ORM\Column(name="send_date", type="datetime", nullable=false) |
64
|
|
|
*/ |
65
|
|
|
protected DateTime $sendDate; |
66
|
|
|
|
67
|
|
|
#[Assert\NotBlank] |
68
|
|
|
/** |
69
|
|
|
* @ORM\Column(name="title", type="string", length=255, nullable=false) |
70
|
|
|
*/ |
71
|
|
|
protected string $title; |
72
|
|
|
|
73
|
|
|
#[Assert\NotBlank] |
74
|
|
|
/** |
75
|
|
|
* @ORM\Column(name="content", type="text", nullable=false) |
76
|
|
|
*/ |
77
|
|
|
protected string $content; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CourseBundle\Entity\CGroup") |
81
|
|
|
* @ORM\JoinColumn(name="group_id", referencedColumnName="iid", nullable=true, onDelete="CASCADE") |
82
|
|
|
*/ |
83
|
|
|
protected ?CGroup $group = null; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @var Collection|Message[] |
87
|
|
|
* @ORM\OneToMany(targetEntity="Message", mappedBy="parent") |
88
|
|
|
*/ |
89
|
|
|
protected Collection $children; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @ORM\ManyToOne(targetEntity="Message", inversedBy="children") |
93
|
|
|
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id") |
94
|
|
|
*/ |
95
|
|
|
protected ?Message $parent = null; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @Gedmo\Timestampable(on="update") |
99
|
|
|
* @ORM\Column(name="update_date", type="datetime", nullable=true) |
100
|
|
|
*/ |
101
|
|
|
protected ?DateTime $updateDate; |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @ORM\Column(name="votes", type="integer", nullable=true) |
105
|
|
|
*/ |
106
|
|
|
protected ?int $votes; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @var Collection|MessageAttachment[] |
110
|
|
|
* |
111
|
|
|
* @ORM\OneToMany(targetEntity="MessageAttachment", mappedBy="message") |
112
|
|
|
*/ |
113
|
|
|
protected Collection $attachments; |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @var Collection|MessageFeedback[] |
117
|
|
|
* |
118
|
|
|
* @ORM\OneToMany(targetEntity="MessageFeedback", mappedBy="message", orphanRemoval=true) |
119
|
|
|
*/ |
120
|
|
|
protected Collection $likes; |
121
|
|
|
|
122
|
|
|
public function __construct() |
123
|
|
|
{ |
124
|
|
|
$this->sendDate = new DateTime('now'); |
125
|
|
|
$this->updateDate = $this->sendDate; |
126
|
|
|
$this->content = ''; |
127
|
|
|
$this->attachments = new ArrayCollection(); |
128
|
|
|
$this->children = new ArrayCollection(); |
129
|
|
|
$this->likes = new ArrayCollection(); |
130
|
|
|
$this->votes = 0; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function setUserSender(User $userSender): self |
134
|
|
|
{ |
135
|
|
|
$this->userSender = $userSender; |
136
|
|
|
|
137
|
|
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function getUserSender(): User |
141
|
|
|
{ |
142
|
|
|
return $this->userSender; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function setUserReceiver(User $userReceiver): self |
146
|
|
|
{ |
147
|
|
|
$this->userReceiver = $userReceiver; |
148
|
|
|
|
149
|
|
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Get userReceiver. |
154
|
|
|
* |
155
|
|
|
* @return User |
156
|
|
|
*/ |
157
|
|
|
public function getUserReceiver() |
158
|
|
|
{ |
159
|
|
|
return $this->userReceiver; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function setMsgStatus(int $msgStatus): self |
163
|
|
|
{ |
164
|
|
|
$this->msgStatus = $msgStatus; |
165
|
|
|
|
166
|
|
|
return $this; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function getMsgStatus(): int |
170
|
|
|
{ |
171
|
|
|
return $this->msgStatus; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
public function setSendDate(DateTime $sendDate): self |
175
|
|
|
{ |
176
|
|
|
$this->sendDate = $sendDate; |
177
|
|
|
|
178
|
|
|
return $this; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Get sendDate. |
183
|
|
|
* |
184
|
|
|
* @return DateTime |
185
|
|
|
*/ |
186
|
|
|
public function getSendDate() |
187
|
|
|
{ |
188
|
|
|
return $this->sendDate; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
public function setTitle(string $title): self |
192
|
|
|
{ |
193
|
|
|
$this->title = $title; |
194
|
|
|
|
195
|
|
|
return $this; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
public function getTitle(): string |
199
|
|
|
{ |
200
|
|
|
return $this->title; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public function setContent(string $content): self |
204
|
|
|
{ |
205
|
|
|
$this->content = $content; |
206
|
|
|
|
207
|
|
|
return $this; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Get content. |
212
|
|
|
* |
213
|
|
|
* @return string |
214
|
|
|
*/ |
215
|
|
|
public function getContent() |
216
|
|
|
{ |
217
|
|
|
return $this->content; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
public function setUpdateDate(DateTime $updateDate): self |
221
|
|
|
{ |
222
|
|
|
$this->updateDate = $updateDate; |
223
|
|
|
|
224
|
|
|
return $this; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Get updateDate. |
229
|
|
|
* |
230
|
|
|
* @return DateTime |
231
|
|
|
*/ |
232
|
|
|
public function getUpdateDate() |
233
|
|
|
{ |
234
|
|
|
return $this->updateDate; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* Get id. |
239
|
|
|
* |
240
|
|
|
* @return int |
241
|
|
|
*/ |
242
|
|
|
public function getId() |
243
|
|
|
{ |
244
|
|
|
return $this->id; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
public function setVotes(int $votes): self |
248
|
|
|
{ |
249
|
|
|
$this->votes = $votes; |
250
|
|
|
|
251
|
|
|
return $this; |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
public function getVotes(): int |
255
|
|
|
{ |
256
|
|
|
return $this->votes; |
|
|
|
|
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* Get attachments. |
261
|
|
|
* |
262
|
|
|
* @return Collection|MessageAttachment[] |
263
|
|
|
*/ |
264
|
|
|
public function getAttachments() |
265
|
|
|
{ |
266
|
|
|
return $this->attachments; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
public function addAttachment(MessageAttachment $attachment): self |
270
|
|
|
{ |
271
|
|
|
$this->attachments->add($attachment); |
272
|
|
|
$attachment->setMessage($this); |
273
|
|
|
|
274
|
|
|
return $this; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
public function getParent(): ?self |
278
|
|
|
{ |
279
|
|
|
return $this->parent; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* @return Collection|Message[] |
284
|
|
|
*/ |
285
|
|
|
public function getChildren() |
286
|
|
|
{ |
287
|
|
|
return $this->children; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
public function addChild(self $child): self |
291
|
|
|
{ |
292
|
|
|
$this->children[] = $child; |
293
|
|
|
$child->setParent($this); |
294
|
|
|
|
295
|
|
|
return $this; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
public function setParent(self $parent = null): self |
299
|
|
|
{ |
300
|
|
|
$this->parent = $parent; |
301
|
|
|
|
302
|
|
|
return $this; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* @return MessageFeedback[]|Collection |
307
|
|
|
*/ |
308
|
|
|
public function getLikes() |
309
|
|
|
{ |
310
|
|
|
return $this->likes; |
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
public function getGroup(): ?CGroup |
314
|
|
|
{ |
315
|
|
|
return $this->group; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
public function setGroup(?CGroup $group): self |
319
|
|
|
{ |
320
|
|
|
$this->group = $group; |
321
|
|
|
|
322
|
|
|
return $this; |
323
|
|
|
} |
324
|
|
|
} |
325
|
|
|
|