Completed
Pull Request — dev (#22)
by
unknown
03:40
created

User::isAccountNonLocked()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace AppBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Symfony\Component\Security\Core\User\UserInterface;
7
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Symfony\Component\Validator\Constraints as Assert;
10
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
11
12
/**
13
 * User.
14
 *
15
 * @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
16
 * @UniqueEntity("email")
17
 */
18
class User implements UserInterface, \Serializable
19
{
20
    use ORMBehaviors\Timestampable\Timestampable;
21
    /**
22
     * @var int
23
     *
24
     * @ORM\Column(type="integer")
25
     * @ORM\Id
26
     * @ORM\GeneratedValue(strategy="AUTO")
27
     */
28
    private $id;
29
30
    /**
31
     * @var string
32
     * @Assert\NotBlank()
33
     * @Assert\Regex(
34
     *     pattern="/\d/",
35
     *     match=false,
36
     *     message="Your name cannot contain a number"
37
     * )
38
     * @Assert\Type("string")
39
     * @Assert\Length(
40
     *      min = 2,
41
     *      max = 190
42
     * )
43
     * @ORM\Column(type="string", length=190)
44
     */
45
    private $firstName;
46
47
    /**
48
     * @var string
49
     * @Assert\NotBlank()
50
     * @Assert\Regex(
51
     *     pattern="/\d/",
52
     *     match=false,
53
     *     message="Your lastname cannot contain a number"
54
     * )
55
     * @Assert\Type("string")
56
     * @Assert\Length(
57
     *      max = 190
58
     * )
59
     * @ORM\Column(type="string", length=190, nullable=true)
60
     */
61
    private $lastName;
62
63
    /**
64
     * @var string
65
     * @Assert\Image()
66
     * @ORM\Column(type="string", nullable=true)
67
     */
68
    private $image;
69
70
    /**
71
     * @var string
72
     * @Assert\NotBlank()
73
     * @Assert\Email(
74
     *     checkMX = true
75
     * )
76
     * @Assert\Type("string")
77
     * @Assert\Length(
78
     *      max = 250
79
     * )
80
     * @ORM\Column(type="string", length=250, unique=true)
81
     */
82
    private $email;
83
84
    /**
85
     * @var string
86
     * @ORM\Column(type="string", length=255)
87
     */
88
    private $password;
89
90
    /**
91
     * @var string
92
     * @Assert\Type("string")
93
     * @Assert\Length(
94
     *      max = 255
95
     * )
96
     * @Assert\NotBlank(groups={"registration"})
97
     */
98
    private $plainPassword;
99
100
    /**
101
     * @var bool
102
     * @ORM\Column(type="boolean")
103
     */
104
    private $enabled = true;
105
106
    /**
107
     * @var
108
     * @ORM\Column(type="json_array")
109
     */
110
    protected $roles;
111
112
    /**
113
     * @var string
114
     *
115
     * @ORM\Column(type="string", unique=true, nullable=true)
116
     */
117
    private $apiToken;
118
119
    /**
120
     * @var ArrayCollection[Event]
121
     * @ORM\ManyToMany(targetEntity="Event", inversedBy="users")
122
     */
123
    private $events;
124
125
    /**
126
     * @var ArrayCollection[FormRequest]
127
     * @ORM\OneToMany(targetEntity="FormRequest", mappedBy="user")
128
     */
129
    private $formRequests;
130
131
    /**
132
     * @var ArrayCollection[Survey]
133
     * @ORM\OneToMany(targetEntity="Survey", mappedBy="user")
134
     */
135
    private $surveys;
136
137
    /**
138
     * @var ArrayCollection[SurveyAnswer]
139
     * @ORM\OneToMany(targetEntity="SurveyAnswer", mappedBy="user")
140
     */
141
    private $answers;
142
143
    public function __construct()
144
    {
145
        $this->events = new ArrayCollection();
146
        $this->formRequests = new ArrayCollection();
147
        $this->surveys = new ArrayCollection();
148
        $this->answers = new ArrayCollection();
149
        $this->roles = array('ROLE_USER');
150
    }
151
152
    /**
153
     * Get id.
154
     *
155
     * @return int
156
     */
157
    public function getId()
158
    {
159
        return $this->id;
160
    }
161
162
    /**
163
     * Get name.
164
     *
165
     * @return string
166
     */
167
    public function getUsername()
168
    {
169
        return $this->email;
170
    }
171
172
    /**
173
     * Set firstname.
174
     *
175
     * @param string $name
176
     *
177
     * @return User
178
     */
179
    public function setFirstName($name)
180
    {
181
        $this->firstName = $name;
182
183
        return $this;
184
    }
185
186
    /**
187
     * Get first name.
188
     *
189
     * @return string
190
     */
191
    public function getFirstName()
192
    {
193
        return $this->firstName;
194
    }
195
196
    /**
197
     * Set lastName.
198
     *
199
     * @param string $lastName
200
     *
201
     * @return User
202
     */
203
    public function setLastName($lastName)
204
    {
205
        $this->lastName = $lastName;
206
207
        return $this;
208
    }
209
210
    /**
211
     * Get lastName.
212
     *
213
     * @return string
214
     */
215
    public function getLastName()
216
    {
217
        return $this->lastName;
218
    }
219
220
    /**
221
     * Set image.
222
     *
223
     * @param string $image
224
     *
225
     * @return User
226
     */
227
    public function setImage($image)
228
    {
229
        $this->image = $image;
230
231
        return $this;
232
    }
233
234
    /**
235
     * Get image.
236
     *
237
     * @return string
238
     */
239
    public function getImage()
240
    {
241
        return $this->image;
242
    }
243
244
    /**
245
     * Set email.
246
     *
247
     * @param string $email
248
     *
249
     * @return User
250
     */
251
    public function setEmail($email)
252
    {
253
        $this->email = $email;
254
255
        return $this;
256
    }
257
258
    /**
259
     * Get email.
260
     *
261
     * @return string
262
     */
263
    public function getEmail()
264
    {
265
        return $this->email;
266
    }
267
268
    /**
269
     * Set password.
270
     *
271
     * @param string $password
272
     *
273
     * @return User
274
     */
275
    public function setPassword($password)
276
    {
277
        $this->password = $password;
278
279
        return $this;
280
    }
281
282
    /**
283
     * Get password.
284
     *
285
     * @return string
286
     */
287
    public function getPassword()
288
    {
289
        return $this->password;
290
    }
291
292
    /**
293
     * @return string
294
     */
295
    public function getPlainPassword()
296
    {
297
        return $this->plainPassword;
298
    }
299
300
    /**
301
     * @param string $plainPassword
302
     */
303
    public function setPlainPassword($plainPassword)
304
    {
305
        $this->plainPassword = $plainPassword;
306
    }
307
308
    /**
309
     * @param mixed $roles
310
     */
311
    public function setRoles($roles)
312
    {
313
        $this->roles = $roles;
314
    }
315
316
    /**
317
     * @return mixed
318
     */
319
    public function getRoles()
320
    {
321
        return $this->roles;
322
    }
323
324
    /**
325
     * Set api token.
326
     *
327
     * @param string $apiToken
328
     *
329
     * @return User
330
     */
331
    public function setApiToken($apiToken)
332
    {
333
        $this->apiToken = $apiToken;
334
335
        return $this;
336
    }
337
338
    /**
339
     * @return string
340
     */
341
    public function getApiToken()
342
    {
343
        return $this->apiToken;
344
    }
345
346
    /**
347
     * @param Event $event
348
     *
349
     * @return User
350
     */
351
    public function setEvent($event)
352
    {
353
        if (!$this->events->contains($event)) {
354
            $this->events->add($event);
355
            $event->setUsers($this);
356
        }
357
358
        return $this;
359
    }
360
361
    /**
362
     * @return ArrayCollection
363
     */
364
    public function getEvents()
365
    {
366
        return $this->events;
367
    }
368
369
    /**
370
     * @return ArrayCollection
371
     */
372
    public function getFormRequests()
373
    {
374
        return $this->formRequests;
375
    }
376
377
    /**
378
     * @return ArrayCollection
379
     */
380
    public function getSurveys()
381
    {
382
        return $this->surveys;
383
    }
384
    /**
385
     * @return ArrayCollection
386
     */
387
    public function getAnswers()
388
    {
389
        return $this->answers;
390
    }
391
392
    /**
393
     * Set enabled
394
     *
395
     * @param boolean $enabled
396
     *
397
     * @return User
398
     */
399
    public function setEnabled(bool $enabled)
400
    {
401
        $this->enabled = $enabled;
402
403
        return $this;
404
    }
405
406
    /**
407
     * Get enabled
408
     *
409
     * @return boolean
410
     */
411
    public function isEnabled()
412
    {
413
        return $this->enabled;
414
    }
415
416
    public function getSalt()
417
    {
418
        // TODO: Implement getSalt() method.
419
    }
420
421
    public function eraseCredentials()
422
    {
423
        $this->setPlainPassword(null);
424
    }
425
426
    /** @see \Serializable::serialize() */
427
    public function serialize()
428
    {
429
        return serialize(array(
430
            $this->id,
431
            $this->firstName,
432
            $this->lastName,
433
            $this->email,
434
            $this->enabled,
435
        ));
436
    }
437
438
    /** @see \Serializable::unserialize() */
439
    public function unserialize($serialized)
440
    {
441
        list(
442
            $this->id,
443
            $this->firstName,
444
            $this->lastName,
445
            $this->email,
446
            $this->enabled) = unserialize($serialized);
447
    }
448
}
449