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