1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Stu\Orm\Entity; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\Mapping\Column; |
8
|
|
|
use Doctrine\ORM\Mapping\Entity; |
9
|
|
|
use Doctrine\ORM\Mapping\GeneratedValue; |
10
|
|
|
use Doctrine\ORM\Mapping\Id; |
11
|
|
|
use Doctrine\ORM\Mapping\Index; |
12
|
|
|
use Doctrine\ORM\Mapping\JoinColumn; |
13
|
|
|
use Doctrine\ORM\Mapping\ManyToOne; |
14
|
|
|
use Doctrine\ORM\Mapping\OneToOne; |
15
|
|
|
use Doctrine\ORM\Mapping\Table; |
16
|
|
|
use Stu\Orm\Attribute\TruncateOnGameReset; |
17
|
|
|
use Stu\Orm\Repository\PrivateMessageRepository; |
18
|
|
|
|
19
|
|
|
#[Table(name: 'stu_pms')] |
20
|
|
|
#[Index(name: 'recipient_folder_idx', columns: ['recip_user', 'cat_id'])] |
21
|
|
|
#[Index(name: 'correspondence', columns: ['recip_user', 'send_user'])] |
22
|
|
|
#[Index(name: 'pm_date_idx', columns: ['date'])] |
23
|
|
|
#[Entity(repositoryClass: PrivateMessageRepository::class)] |
24
|
|
|
#[TruncateOnGameReset] |
25
|
|
|
class PrivateMessage |
26
|
|
|
{ |
27
|
|
|
#[Id] |
28
|
|
|
#[Column(type: 'integer')] |
29
|
|
|
#[GeneratedValue(strategy: 'IDENTITY')] |
30
|
|
|
private int $id; |
31
|
|
|
|
32
|
|
|
#[Column(type: 'integer')] |
33
|
|
|
private int $send_user = 0; |
34
|
|
|
|
35
|
|
|
#[Column(type: 'integer')] |
36
|
|
|
private int $recip_user = 0; |
37
|
|
|
|
38
|
|
|
#[Column(type: 'text')] |
39
|
|
|
private string $text = ''; |
40
|
|
|
|
41
|
|
|
#[Column(type: 'integer')] |
42
|
|
|
private int $date = 0; |
43
|
|
|
|
44
|
|
|
#[Column(type: 'boolean')] |
45
|
|
|
private bool $new = false; |
46
|
|
|
|
47
|
|
|
#[Column(type: 'integer')] |
48
|
|
|
private int $cat_id = 0; |
49
|
|
|
|
50
|
|
|
#[Column(type: 'integer', nullable: true)] |
51
|
|
|
private ?int $inbox_pm_id = null; |
|
|
|
|
52
|
|
|
|
53
|
|
|
#[Column(type: 'string', nullable: true)] |
54
|
|
|
private ?string $href = null; |
55
|
|
|
|
56
|
|
|
#[Column(type: 'integer', nullable: true)] |
57
|
|
|
private ?int $deleted = null; |
58
|
|
|
|
59
|
|
|
#[Column(type: 'integer', nullable: true)] |
60
|
|
|
private ?int $former_send_user = null; |
61
|
|
|
|
62
|
|
|
#[Column(type: 'integer', nullable: true)] |
63
|
|
|
private ?int $former_recip_user = null; |
64
|
|
|
|
65
|
|
|
#[ManyToOne(targetEntity: PrivateMessageFolder::class)] |
66
|
|
|
#[JoinColumn(name: 'cat_id', nullable: false, referencedColumnName: 'id', onDelete: 'CASCADE')] |
67
|
|
|
private PrivateMessageFolder $category; |
68
|
|
|
|
69
|
|
|
#[ManyToOne(targetEntity: User::class)] |
70
|
|
|
#[JoinColumn(name: 'send_user', nullable: false, referencedColumnName: 'id', onDelete: 'CASCADE')] |
71
|
|
|
private User $sendingUser; |
72
|
|
|
|
73
|
|
|
#[ManyToOne(targetEntity: User::class)] |
74
|
|
|
#[JoinColumn(name: 'recip_user', nullable: false, referencedColumnName: 'id', onDelete: 'CASCADE')] |
75
|
|
|
private User $receivingUser; |
76
|
|
|
|
77
|
|
|
#[OneToOne(targetEntity: PrivateMessage::class, inversedBy: 'outboxPm')] |
78
|
|
|
#[JoinColumn(name: 'inbox_pm_id', referencedColumnName: 'id')] |
79
|
|
|
private ?PrivateMessage $inboxPm = null; |
80
|
|
|
|
81
|
|
|
#[OneToOne(targetEntity: PrivateMessage::class, mappedBy: 'inboxPm')] |
82
|
|
|
private ?PrivateMessage $outboxPm = null; |
83
|
|
|
|
84
|
1 |
|
public function getId(): int |
85
|
|
|
{ |
86
|
1 |
|
return $this->id; |
87
|
|
|
} |
88
|
|
|
|
89
|
1 |
|
public function getSenderId(): int |
90
|
|
|
{ |
91
|
1 |
|
return $this->send_user; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function getRecipientId(): int |
95
|
|
|
{ |
96
|
|
|
return $this->recip_user; |
97
|
|
|
} |
98
|
|
|
|
99
|
1 |
|
public function getText(): string |
100
|
|
|
{ |
101
|
1 |
|
return $this->text; |
102
|
|
|
} |
103
|
|
|
|
104
|
4 |
|
public function setText(string $text): PrivateMessage |
105
|
|
|
{ |
106
|
4 |
|
$this->text = $text; |
107
|
4 |
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
1 |
|
public function getDate(): int |
111
|
|
|
{ |
112
|
1 |
|
return $this->date; |
113
|
|
|
} |
114
|
|
|
|
115
|
4 |
|
public function setDate(int $date): PrivateMessage |
116
|
|
|
{ |
117
|
4 |
|
$this->date = $date; |
118
|
4 |
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
1 |
|
public function getNew(): bool |
122
|
|
|
{ |
123
|
1 |
|
return $this->new; |
124
|
|
|
} |
125
|
|
|
|
126
|
4 |
|
public function setNew(bool $new): PrivateMessage |
127
|
|
|
{ |
128
|
4 |
|
$this->new = $new; |
129
|
4 |
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function getCategoryId(): int |
133
|
|
|
{ |
134
|
|
|
return $this->cat_id; |
135
|
|
|
} |
136
|
|
|
|
137
|
1 |
|
public function getInboxPm(): ?PrivateMessage |
138
|
|
|
{ |
139
|
1 |
|
return $this->inboxPm; |
140
|
|
|
} |
141
|
|
|
|
142
|
4 |
|
public function setInboxPm(?PrivateMessage $pm): PrivateMessage |
143
|
|
|
{ |
144
|
4 |
|
$this->inboxPm = $pm; |
145
|
4 |
|
return $this; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
public function getOutboxPm(): ?PrivateMessage |
149
|
|
|
{ |
150
|
|
|
return $this->outboxPm; |
151
|
|
|
} |
152
|
|
|
|
153
|
1 |
|
public function getHref(): ?string |
154
|
|
|
{ |
155
|
1 |
|
return $this->href; |
156
|
|
|
} |
157
|
|
|
|
158
|
4 |
|
public function setHref(?string $href): PrivateMessage |
159
|
|
|
{ |
160
|
4 |
|
$this->href = $href; |
161
|
4 |
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
1 |
|
public function getCategory(): PrivateMessageFolder |
165
|
|
|
{ |
166
|
1 |
|
return $this->category; |
167
|
|
|
} |
168
|
|
|
|
169
|
4 |
|
public function setCategory(PrivateMessageFolder $folder): PrivateMessage |
170
|
|
|
{ |
171
|
4 |
|
$this->category = $folder; |
172
|
4 |
|
return $this; |
173
|
|
|
} |
174
|
|
|
|
175
|
1 |
|
public function getSender(): User |
176
|
|
|
{ |
177
|
1 |
|
return $this->sendingUser; |
178
|
|
|
} |
179
|
|
|
|
180
|
4 |
|
public function setSender(User $user): PrivateMessage |
181
|
|
|
{ |
182
|
4 |
|
$this->sendingUser = $user; |
183
|
4 |
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
1 |
|
public function getRecipient(): User |
187
|
|
|
{ |
188
|
1 |
|
return $this->receivingUser; |
189
|
|
|
} |
190
|
|
|
|
191
|
4 |
|
public function setRecipient(User $recipient): PrivateMessage |
192
|
|
|
{ |
193
|
4 |
|
$this->receivingUser = $recipient; |
194
|
4 |
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
1 |
|
public function isDeleted(): bool |
198
|
|
|
{ |
199
|
1 |
|
return $this->deleted !== null; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
public function setDeleted(int $timestamp): PrivateMessage |
203
|
|
|
{ |
204
|
|
|
$this->deleted = $timestamp; |
205
|
|
|
|
206
|
|
|
return $this; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
public function hasTranslation(): bool |
210
|
|
|
{ |
211
|
|
|
$text = $this->getText(); |
212
|
|
|
return strpos($text, '[translate]') !== false && strpos($text, '[/translate]') !== false; |
213
|
|
|
} |
214
|
|
|
|
215
|
1 |
|
public function getFormerSendUser(): ?int |
216
|
|
|
{ |
217
|
1 |
|
return $this->former_send_user; |
218
|
|
|
} |
219
|
|
|
|
220
|
4 |
|
public function setFormerSendUser(?int $former_send_user): PrivateMessage |
221
|
|
|
{ |
222
|
4 |
|
$this->former_send_user = $former_send_user; |
223
|
4 |
|
return $this; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
public function getFormerRecipUser(): ?int |
227
|
|
|
{ |
228
|
|
|
return $this->former_recip_user; |
229
|
|
|
} |
230
|
|
|
|
231
|
4 |
|
public function setFormerRecipUser(?int $former_recip_user): PrivateMessage |
232
|
|
|
{ |
233
|
4 |
|
$this->former_recip_user = $former_recip_user; |
234
|
4 |
|
return $this; |
235
|
|
|
} |
236
|
|
|
} |