|
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
|
|
|
*/ |
|
22
|
|
|
class Coach implements UserInterface, EmailObjectInterface |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* @ORM\Id() |
|
26
|
|
|
* @ORM\GeneratedValue() |
|
27
|
|
|
* @ORM\Column(type="integer") |
|
28
|
|
|
*/ |
|
29
|
|
|
private $id; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @ORM\Column(type="string", length=180, unique=true) |
|
33
|
|
|
*/ |
|
34
|
|
|
private $email; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @ORM\Column(type="string", length=255, unique=true) |
|
38
|
|
|
*/ |
|
39
|
|
|
private $username; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @ORM\Column(type="json") |
|
43
|
|
|
*/ |
|
44
|
|
|
private $roles = [Roles::COACH]; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var string The hashed password |
|
48
|
|
|
* @ORM\Column(type="string") |
|
49
|
|
|
*/ |
|
50
|
|
|
private $password; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @Groups("user:write") |
|
54
|
|
|
* @SerializedName("password") |
|
55
|
|
|
* @Assert\NotBlank(groups={"create"}) |
|
56
|
|
|
*/ |
|
57
|
|
|
private $plainPassword; |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @ORM\OneToMany(targetEntity=Team::class, mappedBy="coach", orphanRemoval=true) |
|
61
|
|
|
*/ |
|
62
|
|
|
private $teams; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
|
66
|
|
|
*/ |
|
67
|
|
|
private $firstName; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
|
71
|
|
|
*/ |
|
72
|
|
|
private $lastName; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @ORM\Column(type="string", length=4, nullable=true) |
|
76
|
|
|
*/ |
|
77
|
|
|
private $locale; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @ORM\Column(type="boolean") |
|
81
|
|
|
*/ |
|
82
|
|
|
private $active; |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @ORM\Column(type="string", length=255, nullable=true) |
|
86
|
|
|
*/ |
|
87
|
|
|
private $hash; |
|
88
|
|
|
|
|
89
|
|
|
public function __construct() |
|
90
|
|
|
{ |
|
91
|
|
|
$this->teams = new ArrayCollection(); |
|
92
|
|
|
$this->active = false; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function getId(): ?int |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->id; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function getEmail(): ?string |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->email; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function setEmail(string $email): self |
|
106
|
|
|
{ |
|
107
|
|
|
$this->email = $email; |
|
108
|
|
|
|
|
109
|
|
|
return $this; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* A visual identifier that represents this user. |
|
114
|
|
|
* |
|
115
|
|
|
* @see UserInterface |
|
116
|
|
|
*/ |
|
117
|
|
|
public function getUsername(): string |
|
118
|
|
|
{ |
|
119
|
|
|
return (string) $this->username; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
/** |
|
123
|
|
|
* @see UserInterface |
|
124
|
|
|
*/ |
|
125
|
|
|
public function getRoles(): array |
|
126
|
|
|
{ |
|
127
|
|
|
$roles = $this->roles; |
|
128
|
|
|
// guarantee every user at least has OBBLM_USER |
|
129
|
|
|
$roles[] = Roles::COACH; |
|
130
|
|
|
|
|
131
|
|
|
return array_unique($roles); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function setRoles(array $roles): self |
|
135
|
|
|
{ |
|
136
|
|
|
$this->roles = $roles; |
|
137
|
|
|
|
|
138
|
|
|
return $this; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @see UserInterface |
|
143
|
|
|
*/ |
|
144
|
|
|
public function getPassword(): string |
|
145
|
|
|
{ |
|
146
|
|
|
return (string) $this->password; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
public function setPassword(string $password): self |
|
150
|
|
|
{ |
|
151
|
|
|
$this->password = $password; |
|
152
|
|
|
|
|
153
|
|
|
return $this; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
public function getPlainPassword(): ?string |
|
157
|
|
|
{ |
|
158
|
|
|
return $this->plainPassword; |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
public function setPlainPassword(string $plainPassword): self |
|
162
|
|
|
{ |
|
163
|
|
|
$this->plainPassword = $plainPassword; |
|
164
|
|
|
|
|
165
|
|
|
return $this; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @see UserInterface |
|
170
|
|
|
*/ |
|
171
|
|
|
public function getSalt() |
|
172
|
|
|
{ |
|
173
|
|
|
// not needed when using the "bcrypt" algorithm in security.yaml |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @see UserInterface |
|
178
|
|
|
*/ |
|
179
|
|
|
public function eraseCredentials() |
|
180
|
|
|
{ |
|
181
|
|
|
// If you store any temporary, sensitive data on the user, clear it here |
|
182
|
|
|
// $this->plainPassword = null; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* @return Collection|Team[] |
|
187
|
|
|
*/ |
|
188
|
|
|
public function getTeams(): Collection |
|
189
|
|
|
{ |
|
190
|
|
|
return $this->teams; |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
public function addTeam(Team $team): self |
|
194
|
|
|
{ |
|
195
|
|
|
if (!$this->teams->contains($team)) { |
|
196
|
|
|
$this->teams[] = $team; |
|
197
|
|
|
$team->setCoach($this); |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
return $this; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
public function removeTeam(Team $team): self |
|
204
|
|
|
{ |
|
205
|
|
|
if ($this->teams->contains($team)) { |
|
206
|
|
|
$this->teams->removeElement($team); |
|
207
|
|
|
// set the owning side to null (unless already changed) |
|
208
|
|
|
if ($team->getCoach() === $this) { |
|
209
|
|
|
$team->setCoach(null); |
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
|
|
|
|
213
|
|
|
return $this; |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
public function __toString() |
|
217
|
|
|
{ |
|
218
|
|
|
return $this->email; |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
public function getFirstName(): ?string |
|
222
|
|
|
{ |
|
223
|
|
|
return $this->firstName; |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
public function setFirstName(?string $firstName): self |
|
227
|
|
|
{ |
|
228
|
|
|
$this->firstName = $firstName; |
|
229
|
|
|
|
|
230
|
|
|
return $this; |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
public function getLastName(): ?string |
|
234
|
|
|
{ |
|
235
|
|
|
return $this->lastName; |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
public function setLastName(?string $lastName): self |
|
239
|
|
|
{ |
|
240
|
|
|
$this->lastName = $lastName; |
|
241
|
|
|
|
|
242
|
|
|
return $this; |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
public function getLocale(): ?string |
|
246
|
|
|
{ |
|
247
|
|
|
return $this->locale; |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
public function setLocale(?string $locale): self |
|
251
|
|
|
{ |
|
252
|
|
|
$this->locale = $locale; |
|
253
|
|
|
return $this; |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
public function setUsername(string $username): self |
|
257
|
|
|
{ |
|
258
|
|
|
$this->username = $username; |
|
259
|
|
|
|
|
260
|
|
|
return $this; |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
public function getActive(): ?bool |
|
264
|
|
|
{ |
|
265
|
|
|
return $this->active; |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
public function isActive(): ?bool |
|
269
|
|
|
{ |
|
270
|
|
|
return $this->active; |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
public function setActive(bool $active): self |
|
274
|
|
|
{ |
|
275
|
|
|
$this->active = $active; |
|
276
|
|
|
|
|
277
|
|
|
return $this; |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
public function getHash(): ?string |
|
281
|
|
|
{ |
|
282
|
|
|
return $this->hash; |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
public function setHash(?string $hash): self |
|
286
|
|
|
{ |
|
287
|
|
|
$this->hash = $hash; |
|
288
|
|
|
|
|
289
|
|
|
return $this; |
|
290
|
|
|
} |
|
291
|
|
|
} |
|
292
|
|
|
|