1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Obblm\Core\Entity; |
4
|
|
|
|
5
|
|
|
use Obblm\Core\Repository\CoachRepository; |
6
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
7
|
|
|
use Doctrine\Common\Collections\Collection; |
8
|
|
|
use Doctrine\ORM\Mapping as ORM; |
9
|
|
|
use Obblm\Core\Security\Roles; |
10
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
11
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
12
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
13
|
|
|
use Symfony\Component\Serializer\Annotation\SerializedName; |
14
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @ORM\Entity(repositoryClass=CoachRepository::class) |
18
|
|
|
* @ORM\Table(name="obblm_coach") |
19
|
|
|
* @UniqueEntity(fields="email", message="Email is already taken.") |
20
|
|
|
* @UniqueEntity(fields="username", message="Username is already taken.") |
21
|
|
|
* @ORM\HasLifecycleCallbacks() |
22
|
|
|
*/ |
23
|
|
|
class Coach implements UserInterface, EmailObjectInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @ORM\Id() |
27
|
|
|
* @ORM\GeneratedValue() |
28
|
|
|
* @ORM\Column(type="integer") |
29
|
|
|
*/ |
30
|
|
|
private $id; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @ORM\Column(type="string", length=180, unique=true) |
34
|
|
|
*/ |
35
|
|
|
private $email; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @ORM\Column(type="string", length=255, unique=true) |
39
|
|
|
*/ |
40
|
|
|
private $username; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @ORM\Column(type="json") |
44
|
|
|
*/ |
45
|
|
|
private $roles = [Roles::COACH]; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string The hashed password |
49
|
|
|
* @ORM\Column(type="string") |
50
|
|
|
*/ |
51
|
|
|
private $password; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @Groups("user:write") |
55
|
|
|
* @SerializedName("password") |
56
|
|
|
* @Assert\NotBlank(groups={"create"}) |
57
|
|
|
*/ |
58
|
|
|
private $plainPassword; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @ORM\OneToMany(targetEntity=Team::class, mappedBy="coach", orphanRemoval=true) |
62
|
|
|
*/ |
63
|
|
|
private $teams; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
67
|
|
|
*/ |
68
|
|
|
private $firstName; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
72
|
|
|
*/ |
73
|
|
|
private $lastName; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @ORM\Column(type="string", length=4, nullable=true) |
77
|
|
|
*/ |
78
|
|
|
private $locale; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @ORM\Column(type="boolean") |
82
|
|
|
*/ |
83
|
|
|
private $active; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
87
|
|
|
*/ |
88
|
|
|
private $hash; |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @ORM\Column(type="datetime") |
92
|
|
|
*/ |
93
|
|
|
private $createdAt; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @ORM\Column(type="datetime", nullable=true) |
97
|
|
|
*/ |
98
|
|
|
private $resetPasswordAt; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
102
|
|
|
*/ |
103
|
|
|
private $resetPasswordHash; |
104
|
|
|
|
105
|
|
|
public function __construct() |
106
|
|
|
{ |
107
|
|
|
$this->teams = new ArrayCollection(); |
108
|
|
|
$this->active = false; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function getId(): ?int |
112
|
|
|
{ |
113
|
|
|
return $this->id; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function getEmail(): ?string |
117
|
|
|
{ |
118
|
|
|
return $this->email; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function setEmail(string $email): self |
122
|
|
|
{ |
123
|
|
|
$this->email = $email; |
124
|
|
|
|
125
|
|
|
return $this; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* A visual identifier that represents this user. |
130
|
|
|
* |
131
|
|
|
* @see UserInterface |
132
|
|
|
*/ |
133
|
|
|
public function getUsername(): string |
134
|
|
|
{ |
135
|
|
|
return (string) $this->username; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @see UserInterface |
140
|
|
|
*/ |
141
|
|
|
public function getRoles(): array |
142
|
|
|
{ |
143
|
|
|
$roles = $this->roles; |
144
|
|
|
// guarantee every user at least has OBBLM_USER |
145
|
|
|
$roles[] = Roles::COACH; |
146
|
|
|
|
147
|
|
|
return array_unique($roles); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function setRoles(array $roles): self |
151
|
|
|
{ |
152
|
|
|
$this->roles = $roles; |
153
|
|
|
|
154
|
|
|
return $this; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @see UserInterface |
159
|
|
|
*/ |
160
|
|
|
public function getPassword(): string |
161
|
|
|
{ |
162
|
|
|
return (string) $this->password; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function setPassword(string $password): self |
166
|
|
|
{ |
167
|
|
|
$this->password = $password; |
168
|
|
|
|
169
|
|
|
return $this; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function getPlainPassword(): ?string |
173
|
|
|
{ |
174
|
|
|
return $this->plainPassword; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function setPlainPassword(string $plainPassword): self |
178
|
|
|
{ |
179
|
|
|
$this->plainPassword = $plainPassword; |
180
|
|
|
|
181
|
|
|
return $this; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @see UserInterface |
186
|
|
|
*/ |
187
|
|
|
public function getSalt() |
188
|
|
|
{ |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @see UserInterface |
193
|
|
|
*/ |
194
|
|
|
public function eraseCredentials() |
195
|
|
|
{ |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @return Collection|Team[] |
200
|
|
|
*/ |
201
|
|
|
public function getTeams(): Collection |
202
|
|
|
{ |
203
|
|
|
return $this->teams; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
public function addTeam(Team $team): self |
207
|
|
|
{ |
208
|
|
|
if (!$this->teams->contains($team)) { |
209
|
|
|
$this->teams[] = $team; |
210
|
|
|
$team->setCoach($this); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
return $this; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
public function removeTeam(Team $team): self |
217
|
|
|
{ |
218
|
|
|
if ($this->teams->contains($team)) { |
219
|
|
|
$this->teams->removeElement($team); |
220
|
|
|
// set the owning side to null (unless already changed) |
221
|
|
|
if ($team->getCoach() === $this) { |
222
|
|
|
$team->setCoach(null); |
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
return $this; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
public function getFirstName(): ?string |
230
|
|
|
{ |
231
|
|
|
return $this->firstName; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
public function setFirstName(?string $firstName): self |
235
|
|
|
{ |
236
|
|
|
$this->firstName = $firstName; |
237
|
|
|
|
238
|
|
|
return $this; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
public function getLastName(): ?string |
242
|
|
|
{ |
243
|
|
|
return $this->lastName; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
public function setLastName(?string $lastName): self |
247
|
|
|
{ |
248
|
|
|
$this->lastName = $lastName; |
249
|
|
|
|
250
|
|
|
return $this; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
public function getLocale(): ?string |
254
|
|
|
{ |
255
|
|
|
return $this->locale; |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
public function setLocale(?string $locale): self |
259
|
|
|
{ |
260
|
|
|
$this->locale = $locale; |
261
|
|
|
return $this; |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
public function setUsername(string $username): self |
265
|
|
|
{ |
266
|
|
|
$this->username = $username; |
267
|
|
|
|
268
|
|
|
return $this; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
public function getActive(): ?bool |
272
|
|
|
{ |
273
|
|
|
return $this->active; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
public function isActive(): ?bool |
277
|
|
|
{ |
278
|
|
|
return $this->active; |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
public function setActive(bool $active): self |
282
|
|
|
{ |
283
|
|
|
$this->active = $active; |
284
|
|
|
|
285
|
|
|
return $this; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
public function getHash(): ?string |
289
|
|
|
{ |
290
|
|
|
return $this->hash; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
public function setHash(?string $hash): self |
294
|
|
|
{ |
295
|
|
|
$this->hash = $hash; |
296
|
|
|
|
297
|
|
|
return $this; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
public function getCreatedAt(): ?\DateTimeInterface |
301
|
|
|
{ |
302
|
|
|
return $this->createdAt; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
public function setCreatedAt(\DateTimeInterface $createdAt): self |
306
|
|
|
{ |
307
|
|
|
$this->createdAt = $createdAt; |
308
|
|
|
|
309
|
|
|
return $this; |
310
|
|
|
} |
311
|
|
|
|
312
|
|
|
public function getResetPasswordAt(): ?\DateTimeInterface |
313
|
|
|
{ |
314
|
|
|
return $this->resetPasswordAt; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
public function setResetPasswordAt(?\DateTimeInterface $resetPasswordAt): self |
318
|
|
|
{ |
319
|
|
|
$this->resetPasswordAt = $resetPasswordAt; |
320
|
|
|
|
321
|
|
|
return $this; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
public function getResetPasswordHash(): ?string |
325
|
|
|
{ |
326
|
|
|
return $this->resetPasswordHash; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
public function setResetPasswordHash(?string $resetPasswordHash): self |
330
|
|
|
{ |
331
|
|
|
$this->resetPasswordHash = $resetPasswordHash; |
332
|
|
|
|
333
|
|
|
return $this; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
public function __toString():string |
337
|
|
|
{ |
338
|
|
|
return $this->username; |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* @ORM\PrePersist |
343
|
|
|
*/ |
344
|
|
|
public function setCreatedAtValue() |
345
|
|
|
{ |
346
|
|
|
$this->createdAt = new \DateTime(); |
347
|
|
|
} |
348
|
|
|
} |
349
|
|
|
|