1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* |
5
|
|
|
* part-db version 0.1 |
6
|
|
|
* Copyright (C) 2005 Christoph Lechner |
7
|
|
|
* http://www.cl-projects.de/ |
8
|
|
|
* |
9
|
|
|
* part-db version 0.2+ |
10
|
|
|
* Copyright (C) 2009 K. Jacobs and others (see authors.php) |
11
|
|
|
* http://code.google.com/p/part-db/ |
12
|
|
|
* |
13
|
|
|
* Part-DB Version 0.4+ |
14
|
|
|
* Copyright (C) 2016 - 2019 Jan Böhmer |
15
|
|
|
* https://github.com/jbtronics |
16
|
|
|
* |
17
|
|
|
* This program is free software; you can redistribute it and/or |
18
|
|
|
* modify it under the terms of the GNU General Public License |
19
|
|
|
* as published by the Free Software Foundation; either version 2 |
20
|
|
|
* of the License, or (at your option) any later version. |
21
|
|
|
* |
22
|
|
|
* This program is distributed in the hope that it will be useful, |
23
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
24
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
25
|
|
|
* GNU General Public License for more details. |
26
|
|
|
* |
27
|
|
|
* You should have received a copy of the GNU General Public License |
28
|
|
|
* along with this program; if not, write to the Free Software |
29
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
30
|
|
|
* |
31
|
|
|
*/ |
32
|
|
|
|
33
|
|
|
namespace App\Entity; |
34
|
|
|
|
35
|
|
|
use Doctrine\ORM\Mapping as ORM; |
36
|
|
|
use Symfony\Component\Security\Core\User\UserInterface; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* This entity represents a user, which can log in and have permissions. |
40
|
|
|
* Also this entity is able to save some informations about the user, like the names, email-address and other info. |
41
|
|
|
* |
42
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\UserRepository") |
43
|
|
|
* @ORM\Table("users") |
44
|
|
|
*/ |
45
|
|
|
class User extends NamedDBElement implements UserInterface |
46
|
|
|
{ |
47
|
|
|
/** |
48
|
|
|
* @ORM\Id() |
49
|
|
|
* @ORM\GeneratedValue() |
50
|
|
|
* @ORM\Column(type="integer") |
51
|
|
|
*/ |
52
|
|
|
protected $id; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @ORM\Column(type="string", length=180, unique=true) |
56
|
|
|
*/ |
57
|
|
|
protected $name; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* //@ORM\Column(type="json") |
61
|
|
|
*/ |
62
|
|
|
//protected $roles = []; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var string The hashed password |
66
|
|
|
* @ORM\Column(type="string") |
67
|
|
|
*/ |
68
|
|
|
protected $password; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var string The first name of the User |
72
|
|
|
* @ORM\Column(type="string", length=255) |
73
|
|
|
*/ |
74
|
|
|
protected $first_name = ""; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var string The last name of the User |
78
|
|
|
* @ORM\Column(type="string", length=255) |
79
|
|
|
*/ |
80
|
|
|
protected $last_name = ""; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @var string The department the user is working |
84
|
|
|
* @ORM\Column(type="string", length=255) |
85
|
|
|
*/ |
86
|
|
|
protected $department = ""; |
87
|
|
|
|
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @var string The email address of the user |
91
|
|
|
* @ORM\Column(type="string", length=255) |
92
|
|
|
*/ |
93
|
|
|
protected $email = ""; |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @var string The language/locale the user prefers |
97
|
|
|
* @ORM\Column(type="string", name="config_language") |
98
|
|
|
*/ |
99
|
|
|
protected $language = ""; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @var string The timezone the user prefers |
103
|
|
|
* @ORM\Column(type="string", name="config_timezone") |
104
|
|
|
*/ |
105
|
|
|
protected $timezone = ""; |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @var string The theme |
109
|
|
|
* @ORM\Column(type="string", name="config_theme") |
110
|
|
|
*/ |
111
|
|
|
protected $theme = ""; |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @var Group|null The group this user belongs to. |
115
|
|
|
* @ORM\ManyToOne(targetEntity="Group", inversedBy="users") |
116
|
|
|
* @ORM\JoinColumn(name="group_id", referencedColumnName="id") |
117
|
|
|
*/ |
118
|
|
|
protected $group; |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* A visual identifier that represents this user. |
123
|
|
|
* |
124
|
|
|
* @see UserInterface |
125
|
|
|
*/ |
126
|
|
|
public function getUsername(): string |
127
|
|
|
{ |
128
|
|
|
return (string) $this->name; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @see UserInterface |
133
|
|
|
*/ |
134
|
|
|
public function getRoles(): array |
135
|
|
|
{ |
136
|
|
|
$roles = []; |
137
|
|
|
//$roles = $this->roles; |
138
|
|
|
// guarantee every user at least has ROLE_USER |
139
|
|
|
$roles[] = 'ROLE_USER'; |
140
|
|
|
|
141
|
|
|
return array_unique($roles); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function setRoles(array $roles): self |
|
|
|
|
145
|
|
|
{ |
146
|
|
|
//$this->roles = $roles; |
147
|
|
|
|
148
|
|
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @see UserInterface |
153
|
|
|
*/ |
154
|
|
|
public function getPassword(): string |
155
|
|
|
{ |
156
|
|
|
return (string) $this->password; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function setPassword(string $password): self |
160
|
|
|
{ |
161
|
|
|
$this->password = $password; |
162
|
|
|
|
163
|
|
|
return $this; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @see UserInterface |
168
|
|
|
*/ |
169
|
|
|
public function getSalt() |
170
|
|
|
{ |
171
|
|
|
// not needed when using the "bcrypt" algorithm in security.yaml |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @see UserInterface |
176
|
|
|
*/ |
177
|
|
|
public function eraseCredentials() |
178
|
|
|
{ |
179
|
|
|
// If you store any temporary, sensitive data on the user, clear it here |
180
|
|
|
// $this->plainPassword = null; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Returns the ID as an string, defined by the element class. |
185
|
|
|
* This should have a form like P000014, for a part with ID 14. |
186
|
|
|
* @return string The ID as a string; |
187
|
|
|
*/ |
188
|
|
|
public function getIDString(): string |
189
|
|
|
{ |
190
|
|
|
return 'U' . sprintf('%06d', $this->getID()); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
|
194
|
|
|
/************************************************ |
195
|
|
|
* Getters |
196
|
|
|
************************************************/ |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @return string |
200
|
|
|
*/ |
201
|
|
|
public function getFirstName(): string |
202
|
|
|
{ |
203
|
|
|
return $this->first_name; |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @param string $first_name |
208
|
|
|
* @return User |
209
|
|
|
*/ |
210
|
|
|
public function setFirstName(string $first_name): User |
211
|
|
|
{ |
212
|
|
|
$this->first_name = $first_name; |
213
|
|
|
return $this; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @return string |
218
|
|
|
*/ |
219
|
|
|
public function getLastName(): string |
220
|
|
|
{ |
221
|
|
|
return $this->last_name; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* @param string $last_name |
226
|
|
|
* @return User |
227
|
|
|
*/ |
228
|
|
|
public function setLastName(string $last_name): User |
229
|
|
|
{ |
230
|
|
|
$this->last_name = $last_name; |
231
|
|
|
return $this; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* @return string |
236
|
|
|
*/ |
237
|
|
|
public function getDepartment(): string |
238
|
|
|
{ |
239
|
|
|
return $this->department; |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @param string $department |
244
|
|
|
* @return User |
245
|
|
|
*/ |
246
|
|
|
public function setDepartment(string $department): User |
247
|
|
|
{ |
248
|
|
|
$this->department = $department; |
249
|
|
|
return $this; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* @return string |
254
|
|
|
*/ |
255
|
|
|
public function getEmail(): string |
256
|
|
|
{ |
257
|
|
|
return $this->email; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* @param string $email |
262
|
|
|
* @return User |
263
|
|
|
*/ |
264
|
|
|
public function setEmail(string $email): User |
265
|
|
|
{ |
266
|
|
|
$this->email = $email; |
267
|
|
|
return $this; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @return string |
272
|
|
|
*/ |
273
|
|
|
public function getLanguage(): string |
274
|
|
|
{ |
275
|
|
|
return $this->language; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* @param string $language |
280
|
|
|
* @return User |
281
|
|
|
*/ |
282
|
|
|
public function setLanguage(string $language): User |
283
|
|
|
{ |
284
|
|
|
$this->language = $language; |
285
|
|
|
return $this; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @return string |
290
|
|
|
*/ |
291
|
|
|
public function getTimezone(): string |
292
|
|
|
{ |
293
|
|
|
return $this->timezone; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
/** |
297
|
|
|
* @param string $timezone |
298
|
|
|
* @return User |
299
|
|
|
*/ |
300
|
|
|
public function setTimezone(string $timezone): User |
301
|
|
|
{ |
302
|
|
|
$this->timezone = $timezone; |
303
|
|
|
return $this; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* @return string |
308
|
|
|
*/ |
309
|
|
|
public function getTheme(): string |
310
|
|
|
{ |
311
|
|
|
return $this->theme; |
312
|
|
|
} |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* @param string $theme |
316
|
|
|
* @return User |
317
|
|
|
*/ |
318
|
|
|
public function setTheme(string $theme): User |
319
|
|
|
{ |
320
|
|
|
$this->theme = $theme; |
321
|
|
|
return $this; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
public function getGroup(): ?Group |
325
|
|
|
{ |
326
|
|
|
return $this->group; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
public function setGroup(?Group $group): self |
330
|
|
|
{ |
331
|
|
|
$this->group = $group; |
332
|
|
|
return $this; |
333
|
|
|
} |
334
|
|
|
|
335
|
|
|
} |
336
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.