|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
7
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
|
8
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* User |
|
12
|
|
|
* |
|
13
|
|
|
* @ORM\Table(name="user") |
|
14
|
|
|
* @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository") |
|
15
|
|
|
*/ |
|
16
|
|
|
class User |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var int |
|
20
|
|
|
* |
|
21
|
|
|
* @ORM\Column(name="id", type="integer") |
|
22
|
|
|
* @ORM\Id |
|
23
|
|
|
* @ORM\GeneratedValue(strategy="AUTO") |
|
24
|
|
|
*/ |
|
25
|
|
|
private $id; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var string |
|
29
|
|
|
* |
|
30
|
|
|
* @ORM\Column(name="name", type="string", length=50, unique=true) |
|
31
|
|
|
* |
|
32
|
|
|
* @Assert\NotBlank() |
|
33
|
|
|
* @Assert\Length(max = 50) |
|
34
|
|
|
*/ |
|
35
|
|
|
private $name; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var string |
|
39
|
|
|
* |
|
40
|
|
|
* @Gedmo\Slug(fields={"name"}, updatable=true, separator="_") |
|
41
|
|
|
* @ORM\Column(name="slug", type="string", length=50, unique=true) |
|
42
|
|
|
* |
|
43
|
|
|
* @Assert\NotBlank() |
|
44
|
|
|
* @Assert\Length(max = 50) |
|
45
|
|
|
*/ |
|
46
|
|
|
private $slug; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @var string |
|
50
|
|
|
* |
|
51
|
|
|
* @ORM\Column(name="photo", type="string", length=150, nullable=true) |
|
52
|
|
|
* |
|
53
|
|
|
* @Assert\Length(max = 150) |
|
54
|
|
|
*/ |
|
55
|
|
|
private $photo; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @var string |
|
59
|
|
|
* |
|
60
|
|
|
* @ORM\Column(name="email", type="string", length=50) |
|
61
|
|
|
* |
|
62
|
|
|
* @Assert\NotBlank() |
|
63
|
|
|
* @Assert\Email() |
|
64
|
|
|
*/ |
|
65
|
|
|
private $email; |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @var string |
|
69
|
|
|
* |
|
70
|
|
|
* @ORM\Column(name="password", type="string", length=100) |
|
71
|
|
|
* |
|
72
|
|
|
* @Assert\NotBlank() |
|
73
|
|
|
* @Assert\Length(max = 100) |
|
74
|
|
|
*/ |
|
75
|
|
|
private $password; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @ORM\OneToMany(targetEntity="Article", mappedBy="user") |
|
79
|
|
|
*/ |
|
80
|
|
|
private $articles; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @ORM\OneToMany(targetEntity="Comment", mappedBy="user") |
|
84
|
|
|
*/ |
|
85
|
|
|
private $comments; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @ORM\ManyToOne(targetEntity="Role", inversedBy="users") |
|
89
|
|
|
* @ORM\JoinColumn(name="role_id", referencedColumnName="id") |
|
90
|
|
|
*/ |
|
91
|
|
|
private $role; |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @var \DateTime |
|
95
|
|
|
* |
|
96
|
|
|
* @Gedmo\Timestampable(on="create") |
|
97
|
|
|
* @ORM\Column(name="created_at", type="datetime") |
|
98
|
|
|
* |
|
99
|
|
|
* @Assert\DateTime() |
|
100
|
|
|
*/ |
|
101
|
|
|
private $createdAt; |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @var \DateTime |
|
105
|
|
|
* |
|
106
|
|
|
* @Gedmo\Timestampable(on="change", field={"user", "role", "email", "password"}) |
|
107
|
|
|
* @ORM\Column(name="updated_at", type="datetime", nullable=true) |
|
108
|
|
|
* |
|
109
|
|
|
* @Assert\DateTime() |
|
110
|
|
|
*/ |
|
111
|
|
|
private $updatedAt; |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @var \DateTime |
|
115
|
|
|
* |
|
116
|
|
|
* @ORM\Column(name="deleted_at", type="datetime", nullable=true) |
|
117
|
|
|
* |
|
118
|
|
|
* @Assert\DateTime() |
|
119
|
|
|
*/ |
|
120
|
|
|
private $deletedAt; |
|
121
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Get id |
|
125
|
|
|
* |
|
126
|
|
|
* @return int |
|
127
|
|
|
*/ |
|
128
|
|
|
public function getId() |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->id; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Set user |
|
135
|
|
|
* |
|
136
|
|
|
* @param string $name |
|
137
|
|
|
* |
|
138
|
|
|
* @return User |
|
139
|
|
|
*/ |
|
140
|
|
|
public function setName($name) |
|
141
|
|
|
{ |
|
142
|
|
|
$this->name = $name; |
|
143
|
|
|
|
|
144
|
|
|
return $this; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Get user |
|
149
|
|
|
* |
|
150
|
|
|
* @return string |
|
151
|
|
|
*/ |
|
152
|
7 |
|
public function getName() |
|
153
|
|
|
{ |
|
154
|
7 |
|
return $this->name; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* Set slug |
|
159
|
|
|
* |
|
160
|
|
|
* @param string $slug |
|
161
|
|
|
* |
|
162
|
|
|
* @return User |
|
163
|
|
|
*/ |
|
164
|
|
|
public function setSlug($slug) |
|
165
|
|
|
{ |
|
166
|
|
|
$this->slug = $slug; |
|
167
|
|
|
|
|
168
|
|
|
return $this; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* Get slug |
|
173
|
|
|
* |
|
174
|
|
|
* @return string |
|
175
|
|
|
*/ |
|
176
|
6 |
|
public function getSlug() |
|
177
|
|
|
{ |
|
178
|
6 |
|
return $this->slug; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* Set email |
|
183
|
|
|
* |
|
184
|
|
|
* @param string $email |
|
185
|
|
|
* |
|
186
|
|
|
* @return User |
|
187
|
|
|
*/ |
|
188
|
|
|
public function setEmail($email) |
|
189
|
|
|
{ |
|
190
|
|
|
$this->email = $email; |
|
191
|
|
|
|
|
192
|
|
|
return $this; |
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
/** |
|
196
|
|
|
* Get email |
|
197
|
|
|
* |
|
198
|
|
|
* @return string |
|
199
|
|
|
*/ |
|
200
|
|
|
public function getEmail() |
|
201
|
|
|
{ |
|
202
|
|
|
return $this->email; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
/** |
|
206
|
|
|
* Set createdAt |
|
207
|
|
|
* |
|
208
|
|
|
* @param \DateTime $createdAt |
|
209
|
|
|
* |
|
210
|
|
|
* @return User |
|
211
|
|
|
*/ |
|
212
|
|
|
public function setCreatedAt($createdAt) |
|
213
|
|
|
{ |
|
214
|
|
|
$this->createdAt = $createdAt; |
|
215
|
|
|
|
|
216
|
|
|
return $this; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* Get createdAt |
|
221
|
|
|
* |
|
222
|
|
|
* @return \DateTime |
|
223
|
|
|
*/ |
|
224
|
|
|
public function getCreatedAt() |
|
225
|
|
|
{ |
|
226
|
|
|
return $this->createdAt; |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* Set updatedAt |
|
231
|
|
|
* |
|
232
|
|
|
* @param \DateTime $updatedAt |
|
233
|
|
|
* |
|
234
|
|
|
* @return User |
|
235
|
|
|
*/ |
|
236
|
|
|
public function setUpdatedAt($updatedAt) |
|
237
|
|
|
{ |
|
238
|
|
|
$this->updatedAt = $updatedAt; |
|
239
|
|
|
|
|
240
|
|
|
return $this; |
|
241
|
|
|
} |
|
242
|
|
|
|
|
243
|
|
|
/** |
|
244
|
|
|
* Get updatedAt |
|
245
|
|
|
* |
|
246
|
|
|
* @return \DateTime |
|
247
|
|
|
*/ |
|
248
|
|
|
public function getUpdatedAt() |
|
249
|
|
|
{ |
|
250
|
|
|
return $this->updatedAt; |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
/** |
|
254
|
|
|
* Set deletedAt |
|
255
|
|
|
* |
|
256
|
|
|
* @param \DateTime $deletedAt |
|
257
|
|
|
* |
|
258
|
|
|
* @return User |
|
259
|
|
|
*/ |
|
260
|
|
|
public function setDeletedAt($deletedAt) |
|
261
|
|
|
{ |
|
262
|
|
|
$this->deletedAt = $deletedAt; |
|
263
|
|
|
|
|
264
|
|
|
return $this; |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
/** |
|
268
|
|
|
* Get deletedAt |
|
269
|
|
|
* |
|
270
|
|
|
* @return \DateTime |
|
271
|
|
|
*/ |
|
272
|
|
|
public function getDeletedAt() |
|
273
|
|
|
{ |
|
274
|
|
|
return $this->deletedAt; |
|
275
|
|
|
} |
|
276
|
|
|
/** |
|
277
|
|
|
* Constructor |
|
278
|
|
|
*/ |
|
279
|
|
|
public function __construct() |
|
280
|
|
|
{ |
|
281
|
|
|
$this->articles = new ArrayCollection(); |
|
282
|
|
|
$this->comments = new ArrayCollection(); |
|
283
|
|
|
} |
|
284
|
|
|
|
|
285
|
|
|
/** |
|
286
|
|
|
* Add article |
|
287
|
|
|
* |
|
288
|
|
|
* @param \AppBundle\Entity\Article $article |
|
289
|
|
|
* |
|
290
|
|
|
* @return User |
|
291
|
|
|
*/ |
|
292
|
|
|
public function addArticle(Article $article) |
|
293
|
|
|
{ |
|
294
|
|
|
$this->articles[] = $article; |
|
295
|
|
|
|
|
296
|
|
|
return $this; |
|
297
|
|
|
} |
|
298
|
|
|
|
|
299
|
|
|
/** |
|
300
|
|
|
* Remove article |
|
301
|
|
|
* |
|
302
|
|
|
* @param \AppBundle\Entity\Article $article |
|
303
|
|
|
*/ |
|
304
|
|
|
public function removeArticle(Article $article) |
|
305
|
|
|
{ |
|
306
|
|
|
$this->articles->removeElement($article); |
|
307
|
|
|
} |
|
308
|
|
|
|
|
309
|
|
|
/** |
|
310
|
|
|
* Get articles |
|
311
|
|
|
* |
|
312
|
|
|
* @return \Doctrine\Common\Collections\Collection |
|
313
|
|
|
*/ |
|
314
|
|
|
public function getArticles() |
|
315
|
|
|
{ |
|
316
|
|
|
return $this->articles; |
|
317
|
|
|
} |
|
318
|
|
|
|
|
319
|
|
|
/** |
|
320
|
|
|
* Add comment |
|
321
|
|
|
* |
|
322
|
|
|
* @param \AppBundle\Entity\Comment $comment |
|
323
|
|
|
* |
|
324
|
|
|
* @return User |
|
325
|
|
|
*/ |
|
326
|
|
|
public function addComment(Comment $comment) |
|
327
|
|
|
{ |
|
328
|
|
|
$this->comments[] = $comment; |
|
329
|
|
|
|
|
330
|
|
|
return $this; |
|
331
|
|
|
} |
|
332
|
|
|
|
|
333
|
|
|
/** |
|
334
|
|
|
* Remove comment |
|
335
|
|
|
* |
|
336
|
|
|
* @param \AppBundle\Entity\Comment $comment |
|
337
|
|
|
*/ |
|
338
|
|
|
public function removeComment(Comment $comment) |
|
339
|
|
|
{ |
|
340
|
|
|
$this->comments->removeElement($comment); |
|
341
|
|
|
} |
|
342
|
|
|
|
|
343
|
|
|
/** |
|
344
|
|
|
* Get comments |
|
345
|
|
|
* |
|
346
|
|
|
* @return \Doctrine\Common\Collections\Collection |
|
347
|
|
|
*/ |
|
348
|
|
|
public function getComments() |
|
349
|
|
|
{ |
|
350
|
|
|
return $this->comments; |
|
351
|
|
|
} |
|
352
|
|
|
|
|
353
|
|
|
/** |
|
354
|
|
|
* Set role |
|
355
|
|
|
* |
|
356
|
|
|
* @param \AppBundle\Entity\Role $role |
|
357
|
|
|
* |
|
358
|
|
|
* @return User |
|
359
|
|
|
*/ |
|
360
|
|
|
public function setRole(Role $role = null) |
|
361
|
|
|
{ |
|
362
|
|
|
$this->role = $role; |
|
363
|
|
|
|
|
364
|
|
|
return $this; |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
/** |
|
368
|
|
|
* Get role |
|
369
|
|
|
* |
|
370
|
|
|
* @return \AppBundle\Entity\Role |
|
371
|
|
|
*/ |
|
372
|
|
|
public function getRole() |
|
373
|
|
|
{ |
|
374
|
|
|
return $this->role; |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
/** |
|
378
|
|
|
* Set password |
|
379
|
|
|
* |
|
380
|
|
|
* @param string $password |
|
381
|
|
|
* |
|
382
|
|
|
* @return User |
|
383
|
|
|
*/ |
|
384
|
|
|
public function setPassword($password) |
|
385
|
|
|
{ |
|
386
|
|
|
$this->password = $password; |
|
387
|
|
|
|
|
388
|
|
|
return $this; |
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
|
|
/** |
|
392
|
|
|
* Get password |
|
393
|
|
|
* |
|
394
|
|
|
* @return string |
|
395
|
|
|
*/ |
|
396
|
|
|
public function getPassword() |
|
397
|
|
|
{ |
|
398
|
|
|
return $this->password; |
|
399
|
|
|
} |
|
400
|
|
|
|
|
401
|
|
|
/** |
|
402
|
|
|
* Set photo |
|
403
|
|
|
* |
|
404
|
|
|
* @param string $photo |
|
405
|
|
|
* |
|
406
|
|
|
* @return User |
|
407
|
|
|
*/ |
|
408
|
|
|
public function setPhoto($photo) |
|
409
|
|
|
{ |
|
410
|
|
|
$this->photo = $photo; |
|
411
|
|
|
|
|
412
|
|
|
return $this; |
|
413
|
|
|
} |
|
414
|
|
|
|
|
415
|
|
|
/** |
|
416
|
|
|
* Get photo |
|
417
|
|
|
* |
|
418
|
|
|
* @return string |
|
419
|
|
|
*/ |
|
420
|
6 |
|
public function getPhoto() |
|
421
|
|
|
{ |
|
422
|
6 |
|
return $this->photo; |
|
423
|
|
|
} |
|
424
|
|
|
} |
|
425
|
|
|
|