1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Skobkin\Bundle\PointToolsBundle\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @ORM\Table(name="users", schema="users", indexes={ |
10
|
|
|
* @ORM\Index(name="idx_user_public", columns={"public"}), |
11
|
|
|
* @ORM\Index(name="idx_user_removed", columns={"is_removed"}) |
12
|
|
|
* }) |
13
|
|
|
* @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\UserRepository") |
14
|
|
|
* @ORM\HasLifecycleCallbacks |
15
|
|
|
*/ |
16
|
|
|
class User |
17
|
|
|
{ |
18
|
|
|
public const AVATAR_SIZE_SMALL = '24'; |
19
|
|
|
public const AVATAR_SIZE_MEDIUM = '40'; |
20
|
|
|
public const AVATAR_SIZE_LARGE = '80'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var int |
24
|
|
|
* |
25
|
|
|
* @ORM\Column(name="id", type="integer") |
26
|
|
|
* @ORM\Id |
27
|
|
|
*/ |
28
|
|
|
private $id; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
* |
33
|
|
|
* @ORM\Column(name="login", type="string", length=255, nullable=false) |
34
|
|
|
*/ |
35
|
|
|
private $login; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string|null |
39
|
|
|
* |
40
|
|
|
* @ORM\Column(name="name", type="string", length=255, nullable=true) |
41
|
|
|
*/ |
42
|
|
|
private $name; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var \DateTime |
46
|
|
|
* |
47
|
|
|
* @ORM\Column(name="created_at", type="datetime") |
48
|
|
|
*/ |
49
|
|
|
private $createdAt; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var \DateTime |
53
|
|
|
* |
54
|
|
|
* @ORM\Column(name="updated_at", type="datetime", nullable=true) |
55
|
|
|
*/ |
56
|
|
|
private $updatedAt; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @var bool |
60
|
|
|
* |
61
|
|
|
* @ORM\Column(name="public", type="boolean", nullable=false, options={"default": false}) |
62
|
|
|
*/ |
63
|
|
|
private $public = false; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var bool |
67
|
|
|
* |
68
|
|
|
* @ORM\Column(name="whitelist_only", type="boolean", nullable=false, options={"default": false}) |
69
|
|
|
*/ |
70
|
|
|
private $whitelistOnly = false; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var ArrayCollection|Subscription[] |
74
|
|
|
* |
75
|
|
|
* @ORM\OneToMany(targetEntity="Subscription", mappedBy="author", fetch="EXTRA_LAZY") |
76
|
|
|
*/ |
77
|
|
|
private $subscribers; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var ArrayCollection|Subscription[] |
81
|
|
|
* |
82
|
|
|
* @ORM\OneToMany(targetEntity="Subscription", mappedBy="subscriber", fetch="EXTRA_LAZY") |
83
|
|
|
*/ |
84
|
|
|
private $subscriptions; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @var ArrayCollection|SubscriptionEvent[] |
88
|
|
|
* |
89
|
|
|
* @ORM\OneToMany(targetEntity="SubscriptionEvent", mappedBy="author", fetch="EXTRA_LAZY") |
90
|
|
|
*/ |
91
|
|
|
private $newSubscriberEvents; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @var bool |
95
|
|
|
* |
96
|
|
|
* @ORM\Column(name="is_removed", type="boolean", options={"default": false}) |
97
|
|
|
*/ |
98
|
|
|
private $removed = false; |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
public function __construct(int $id, \DateTime $createdAt = null, string $login = null, string $name = null) |
102
|
|
|
{ |
103
|
|
|
$this->id = $id; |
104
|
|
|
$this->login = $login; |
105
|
|
|
$this->name = $name; |
106
|
3 |
|
$this->createdAt = $createdAt ?: new \DateTime(); |
107
|
|
|
|
108
|
3 |
|
$this->subscribers = new ArrayCollection(); |
109
|
|
|
$this->subscriptions = new ArrayCollection(); |
110
|
|
|
$this->newSubscriberEvents = new ArrayCollection(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @ORM\PreUpdate |
115
|
|
|
*/ |
116
|
|
|
public function preUpdate(): void |
117
|
|
|
{ |
118
|
|
|
$this->updatedAt = new \DateTime(); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function getId(): int |
122
|
7 |
|
{ |
123
|
|
|
return $this->id; |
124
|
7 |
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
public function getLogin(): string |
128
|
|
|
{ |
129
|
|
|
return $this->login; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function getName(): ?string |
133
|
|
|
{ |
134
|
1 |
|
return $this->name; |
135
|
|
|
} |
136
|
1 |
|
|
137
|
|
|
public function updateLoginAndName(string $login, ?string $name): self |
138
|
|
|
{ |
139
|
|
|
$this->login = $login; |
140
|
|
|
$this->name = $name; |
141
|
|
|
|
142
|
|
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function addSubscriber(Subscription $subscribers): self |
146
|
|
|
{ |
147
|
|
|
$this->subscribers[] = $subscribers; |
148
|
|
|
|
149
|
|
|
return $this; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function removeSubscriber(Subscription $subscribers) |
153
|
|
|
{ |
154
|
|
|
$this->subscribers->removeElement($subscribers); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @return Subscription[]|ArrayCollection |
159
|
|
|
*/ |
160
|
|
|
public function getSubscribers(): ArrayCollection |
161
|
|
|
{ |
162
|
|
|
return $this->subscribers; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @return Subscription[]|ArrayCollection |
167
|
|
|
*/ |
168
|
|
|
public function getSubscriptions(): ArrayCollection |
169
|
|
|
{ |
170
|
|
|
return $this->subscriptions; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
public function addNewSubscriberEvent(SubscriptionEvent $newSubscriberEvents): self |
174
|
|
|
{ |
175
|
|
|
$this->newSubscriberEvents[] = $newSubscriberEvents; |
176
|
|
|
|
177
|
|
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @return SubscriptionEvent[]|ArrayCollection |
182
|
|
|
*/ |
183
|
|
|
public function getNewSubscriberEvents(): ArrayCollection |
184
|
|
|
{ |
185
|
|
|
return $this->newSubscriberEvents; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function getCreatedAt(): \DateTime |
189
|
|
|
{ |
190
|
|
|
return $this->createdAt; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
public function getUpdatedAt(): ?\DateTime |
194
|
|
|
{ |
195
|
|
|
return $this->updatedAt; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
public function updatePrivacy(?bool $public, ?bool $whitelistOnly): void |
199
|
|
|
{ |
200
|
|
|
$this->public = $public; |
201
|
|
|
$this->whitelistOnly = $whitelistOnly; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
public function isPublic(): ?bool |
205
|
|
|
{ |
206
|
|
|
return $this->public; |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
public function isWhitelistOnly(): ?bool |
210
|
|
|
{ |
211
|
|
|
return $this->whitelistOnly; |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
public function isRemoved(): bool |
215
|
|
|
{ |
216
|
|
|
return $this->removed; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
public function markAsRemoved(): void |
220
|
|
|
{ |
221
|
|
|
$this->removed = true; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
public function restore(): void |
225
|
|
|
{ |
226
|
|
|
$this->removed = false; |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
|