Passed
Push — master ( 3e42de...6c1980 )
by Alexey
03:33
created

Account::toggleSubscriberNotification()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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