1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Skobkin\Bundle\PointToolsBundle\Entity\Telegram; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
6
|
|
|
use Skobkin\Bundle\PointToolsBundle\Entity\User; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @ORM\Table(name="telegram_accounts", schema="users", indexes={ |
10
|
|
|
* @ORM\Index(name="subscriber_notification_idx", columns={"subscriber_notification"}, options={"where": "subscriber_notification = TRUE"}), |
11
|
|
|
* @ORM\Index(name="rename_notification_idx", columns={"rename_notification"}, options={"where": "rename_notification = TRUE"}), |
12
|
|
|
* }) |
13
|
|
|
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Telegram\AccountRepository") |
14
|
|
|
* @ORM\HasLifecycleCallbacks() |
15
|
|
|
*/ |
16
|
|
|
class Account |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Telegram user ID |
20
|
|
|
* |
21
|
|
|
* @var int |
22
|
|
|
* |
23
|
|
|
* @ORM\Id() |
24
|
|
|
* @ORM\Column(name="account_id", type="integer") |
25
|
|
|
*/ |
26
|
|
|
private $id; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var \DateTime |
30
|
|
|
* |
31
|
|
|
* @ORM\Column(name="created_at", type="datetime") |
32
|
|
|
*/ |
33
|
|
|
private $createdAt; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var \DateTime |
37
|
|
|
* |
38
|
|
|
* @ORM\Column(name="updated_at", type="datetime", nullable=true) |
39
|
|
|
*/ |
40
|
|
|
private $updatedAt; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var \DateTime |
44
|
|
|
* |
45
|
|
|
* @ORM\Column(name="linked_at", type="datetime", nullable=true) |
46
|
|
|
*/ |
47
|
|
|
private $linkedAt; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var string |
51
|
|
|
* |
52
|
|
|
* @ORM\Column(name="first_name", type="text") |
53
|
|
|
*/ |
54
|
|
|
private $firstName; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var string|null |
58
|
|
|
* |
59
|
|
|
* @ORM\Column(name="last_name", type="text", nullable=true) |
60
|
|
|
*/ |
61
|
|
|
private $lastName; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var string|null |
65
|
|
|
* |
66
|
|
|
* @ORM\Column(name="username", type="text", nullable=true) |
67
|
|
|
*/ |
68
|
|
|
private $username; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* ID of private chat with user |
72
|
|
|
* |
73
|
|
|
* @var int |
74
|
|
|
* |
75
|
|
|
* @ORM\Column(name="private_chat_id", type="bigint", nullable=true) |
76
|
|
|
*/ |
77
|
|
|
private $chatId; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var User |
81
|
|
|
* |
82
|
|
|
* @ORM\OneToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User") |
83
|
|
|
* @ORM\JoinColumn(name="user_id", nullable=true, onDelete="CASCADE") |
84
|
|
|
*/ |
85
|
|
|
private $user; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Notifications about new subscribers |
89
|
|
|
* |
90
|
|
|
* @var bool |
91
|
|
|
* |
92
|
|
|
* @ORM\Column(name="subscriber_notification", type="boolean") |
93
|
|
|
*/ |
94
|
|
|
private $subscriberNotification = false; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Notifications about user renaming |
98
|
|
|
* |
99
|
|
|
* @var bool |
100
|
|
|
* |
101
|
|
|
* @ORM\Column(name="rename_notification", type="boolean") |
102
|
|
|
*/ |
103
|
|
|
private $renameNotification = false; |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
public function __construct(int $id) |
107
|
|
|
{ |
108
|
|
|
$this->id = $id; |
109
|
|
|
$this->createdAt = new \DateTime(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @ORM\PreUpdate() |
114
|
|
|
*/ |
115
|
|
|
public function preUpdate(): void |
116
|
|
|
{ |
117
|
|
|
$this->updatedAt = new \DateTime(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function getId(): int |
121
|
|
|
{ |
122
|
|
|
return $this->id; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function getCreatedAt(): \DateTime |
126
|
|
|
{ |
127
|
|
|
return $this->createdAt; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function getUpdatedAt(): \DateTime |
131
|
|
|
{ |
132
|
|
|
return $this->updatedAt; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
public function getLinkedAt(): \DateTime |
136
|
|
|
{ |
137
|
|
|
return $this->linkedAt; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function getFirstName(): string |
141
|
|
|
{ |
142
|
|
|
return $this->firstName; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function setFirstName(string $firstName): Account |
146
|
|
|
{ |
147
|
|
|
$this->firstName = $firstName; |
148
|
|
|
|
149
|
|
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function getLastName(): ?string |
153
|
|
|
{ |
154
|
|
|
return $this->lastName; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function setLastName(?string $lastName = null): Account |
158
|
|
|
{ |
159
|
|
|
$this->lastName = $lastName; |
160
|
|
|
|
161
|
|
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
public function getUsername(): string |
165
|
|
|
{ |
166
|
|
|
return $this->username; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function setUsername(string $username = null): Account |
170
|
|
|
{ |
171
|
|
|
$this->username = $username; |
172
|
|
|
|
173
|
|
|
return $this; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function setChatId(int $chatId): self |
177
|
|
|
{ |
178
|
|
|
$this->chatId = $chatId; |
179
|
|
|
|
180
|
|
|
return $this; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function getChatId(): int |
184
|
|
|
{ |
185
|
|
|
return $this->chatId; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function getUser(): ?User |
189
|
|
|
{ |
190
|
|
|
return $this->user; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
public function setUser(User $user): Account |
194
|
|
|
{ |
195
|
|
|
if (!$this->user && $user) { |
196
|
|
|
$this->linkedAt = new \DateTime(); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
$this->user = $user; |
200
|
|
|
|
201
|
|
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function getUserId(): int |
205
|
|
|
{ |
206
|
|
|
return $this->user->getId(); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
public function disableNotifications(): self |
210
|
|
|
{ |
211
|
|
|
$this->subscriberNotification = false; |
212
|
|
|
$this->renameNotification = false; |
213
|
|
|
|
214
|
|
|
return $this; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
public function setSubscriberNotification(bool $subscriberNotification): self |
218
|
|
|
{ |
219
|
|
|
$this->subscriberNotification = $subscriberNotification; |
220
|
|
|
|
221
|
|
|
return $this; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
public function toggleSubscriberNotification(): self |
225
|
|
|
{ |
226
|
|
|
$this->subscriberNotification = !$this->subscriberNotification; |
227
|
|
|
|
228
|
|
|
return $this; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
public function isSubscriberNotification(): bool |
232
|
|
|
{ |
233
|
|
|
return $this->subscriberNotification; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
public function setRenameNotification(bool $renameNotification): self |
237
|
|
|
{ |
238
|
|
|
$this->renameNotification = $renameNotification; |
239
|
|
|
|
240
|
|
|
return $this; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
public function toggleRenameNotification(): self |
244
|
|
|
{ |
245
|
|
|
$this->renameNotification = !$this->renameNotification; |
246
|
|
|
|
247
|
|
|
return $this; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
public function isRenameNotification(): bool |
251
|
|
|
{ |
252
|
|
|
return $this->renameNotification; |
253
|
|
|
} |
254
|
|
|
} |
255
|
|
|
|