Completed
Pull Request — dev (#26)
by nonanerz
03:42
created

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