Completed
Pull Request — master (#288)
by Guilherme
06:38
created

Person::getUpdatedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\CoreBundle\Entity;
12
13
use Doctrine\ORM\Mapping as ORM;
14
use Doctrine\Common\Collections\ArrayCollection;
15
use Doctrine\Common\Collections\Collection;
16
use libphonenumber\PhoneNumber;
17
use LoginCidadao\BadgesControlBundle\Model\BadgeInterface;
18
use Symfony\Component\HttpFoundation\File\File;
19
use Symfony\Component\Validator\Constraints as Assert;
20
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
21
use Scheb\TwoFactorBundle\Model\BackupCodeInterface;
22
use Vich\UploaderBundle\Mapping\Annotation as Vich;
23
use JMS\Serializer\Annotation as JMS;
24
use FOS\UserBundle\Model\User as BaseUser;
25
use LoginCidadao\OAuthBundle\Entity\Client;
26
use LoginCidadao\CoreBundle\Model\LocationSelectData;
27
use LoginCidadao\CoreBundle\Model\PersonInterface;
28
use LoginCidadao\OAuthBundle\Model\ClientInterface;
29
use LoginCidadao\ValidationBundle\Validator\Constraints as LCAssert;
30
use Donato\PathWellBundle\Validator\Constraints\PathWell;
31
use Misd\PhoneNumberBundle\Validator\Constraints\PhoneNumber as AssertPhoneNumber;
32
use Rollerworks\Bundle\PasswordStrengthBundle\Validator\Constraints as RollerworksPassword;
33
34
/**
35
 * @ORM\Entity(repositoryClass="LoginCidadao\CoreBundle\Entity\PersonRepository")
36
 * @ORM\Table(name="person")
37
 * @UniqueEntity("cpf", message="person.validation.cpf.already_used", groups={"LoginCidadaoRegistration", "Registration", "Profile", "LoginCidadaoProfile", "Dynamic", "Documents"})
38
 * @UniqueEntity("username")
39
 * @UniqueEntity(fields="emailCanonical", errorPath="email", message="fos_user.email.already_used", groups={"LoginCidadaoRegistration", "Registration", "LoginCidadaoEmailForm", "LoginCidadaoProfile", "Dynamic"})
40
 * @ORM\HasLifecycleCallbacks
41
 * @JMS\ExclusionPolicy("all")
42
 * @Vich\Uploadable
43
 */
44
class Person extends BaseUser implements PersonInterface, BackupCodeInterface
45
{
46
    /**
47
     * @ORM\Id
48
     * @ORM\Column(type="integer")
49
     * @ORM\GeneratedValue(strategy="AUTO")
50
     * @JMS\Since("1.0")
51
     * @JMS\Until("2")
52
     */
53
    protected $id;
54
55
    /**
56
     * @JMS\Expose
57
     * @JMS\Groups({"first_name","full_name","public_profile","given_name","name"})
58
     * @ORM\Column(type="string", nullable=true)
59
     * @Assert\NotBlank(message="Please enter your name.", groups={"Profile", "LoginCidadaoProfile"})
60
     * @Assert\Length(
61
     *     min=3,
62
     *     max="255",
63
     *     minMessage="The name is too short.",
64
     *     maxMessage="The name is too long.",
65
     *     groups={"Registration", "Profile", "LoginCidadaoProfile"}
66
     * )
67
     * @JMS\Since("1.0")
68
     */
69
    protected $firstName;
70
71
    /**
72
     * @JMS\Expose
73
     * @JMS\Groups({"last_name","full_name","family_name","middle_name","name"})
74
     * @ORM\Column(type="string", nullable=true)
75
     * @Assert\NotBlank(message="Please enter your surname.", groups={"Profile", "LoginCidadaoProfile"})
76
     * @Assert\Length(
77
     *     min=1,
78
     *     max="255",
79
     *     minMessage="The surname is too short.",
80
     *     maxMessage="The surname is too long.",
81
     *     groups={"Registration", "Profile", "LoginCidadaoProfile"}
82
     * )
83
     * @JMS\Since("1.0")
84
     */
85
    protected $surname;
86
87
    /**
88
     * @JMS\Expose
89
     * @JMS\Groups({"username","preferred_username"})
90
     * @Assert\NotBlank
91
     * @Assert\Length(
92
     *     min="1",
93
     *     max="40",
94
     *     groups={"Registration", "Profile", "LoginCidadaoProfile"}
95
     * )
96
     * @JMS\Since("1.0")
97
     */
98
    protected $username;
99
100
    /**
101
     * @JMS\Exclude
102
     * @PathWell(
103
     *     groups={"Registration", "ResetPassword", "ChangePassword", "LoginCidadaoRegistration"}
104
     * )
105
     * @RollerworksPassword\PasswordRequirements(
106
     *     minLength=false,
107
     *     requireLetters=true,
108
     *     requireNumbers=true,
109
     *     missingLettersMessage="person.validation.password.missingLetters",
110
     *     missingNumbersMessage="person.validation.password.missingNumbers",
111
     *     groups={"Registration", "ResetPassword", "ChangePassword", "LoginCidadaoRegistration"}
112
     * )
113
     * @Assert\Length(
114
     *     min=8,
115
     *     max=72,
116
     *     maxMessage="person.validation.password.length.max",
117
     *     minMessage="person.validation.password.length.min",
118
     *     groups={"Registration", "ResetPassword", "ChangePassword", "LoginCidadaoRegistration"}
119
     * )
120
     * @Assert\NotBlank(message="person.validation.password.not_blank", groups={"Registration", "ResetPassword", "ChangePassword", "LoginCidadaoRegistration"})
121
     */
122
    protected $plainPassword;
123
124
    /**
125
     * @JMS\Expose
126
     * @JMS\Groups({"cpf"})
127
     * @ORM\Column(type="string", nullable=true, unique=true)
128
     * @LCAssert\CPF(groups={"Documents", "Dynamic", "LoginCidadaoRegistration"})
129
     * @JMS\Since("1.0")
130
     */
131
    protected $cpf;
132
133
    /**
134
     * @JMS\Expose
135
     * @JMS\Groups({"email"})
136
     * @JMS\Since("1.0")
137
     * @LCAssert\Email(strict=true, groups={"Profile", "LoginCidadaoProfile", "Registration", "ResetPassword", "ChangePassword", "LoginCidadaoRegistration", "LoginCidadaoEmailForm"})
138
     * @Assert\NotBlank(message="person.validation.email.not_blank", groups={"Profile", "LoginCidadaoProfile", "Registration", "ResetPassword", "ChangePassword", "LoginCidadaoRegistration", "LoginCidadaoEmailForm"})
139
     */
140
    protected $email;
141
142
    /**
143
     * @JMS\Expose
144
     * @JMS\Groups({"birthdate"})
145
     * @ORM\Column(type="date", nullable=true)
146
     * @JMS\Since("1.0")
147
     * @LCAssert\Age(max="150", groups={"Profile", "LoginCidadaoProfile", "Registration", "ResetPassword", "ChangePassword", "LoginCidadaoRegistration", "LoginCidadaoEmailForm"})
148
     */
149
    protected $birthdate;
150
151
    /**
152
     * @ORM\Column(name="email_expiration", type="datetime", nullable=true)
153
     * @JMS\Since("1.0")
154
     */
155
    protected $emailExpiration;
156
157
    /**
158
     * @JMS\Expose
159
     * @JMS\Groups({"mobile","phone_number"})
160
     * @JMS\Type("libphonenumber\PhoneNumber")
161
     * @ORM\Column(type="phone_number", nullable=true)
162
     * @JMS\Since("1.0")
163
     * @LCAssert\E164PhoneNumber(
164
     *     maxMessage="person.validation.mobile.length.max",
165
     *     groups={"Registration", "LoginCidadaoRegistration", "Dynamic", "Profile", "LoginCidadaoProfile"}
166
     * )
167
     * @LCAssert\MobilePhoneNumber(
168
     *     missing9thDigit="person.validation.mobile.9thDigit",
169
     *     groups={"Registration", "LoginCidadaoRegistration", "Dynamic", "Profile", "LoginCidadaoProfile"}
170
     * )
171
     * @AssertPhoneNumber(
172
     *     type="mobile",
173
     *     groups={"Registration", "LoginCidadaoRegistration", "Dynamic", "Profile", "LoginCidadaoProfile"}
174
     * )
175
     */
176
    protected $mobile;
177
178
    /**
179
     * @ORM\Column(type="string", length=255, nullable=true)
180
     * @var string
181
     * @JMS\Since("1.0")
182
     */
183
    protected $twitterPicture;
184
185
    /**
186
     * @JMS\Expose
187
     * @JMS\Groups({"city"})
188
     * @ORM\ManyToOne(targetEntity="LoginCidadao\CoreBundle\Entity\City")
189
     * @ORM\JoinColumn(name="city_id", referencedColumnName="id")
190
     * @JMS\Since("1.0")
191
     */
192
    protected $city;
193
194
    /**
195
     * @var string
196
     *
197
     * @ORM\Column(name="facebookId", type="string", length=255, nullable=true, unique=true)
198
     * @JMS\Exclude
199
     */
200
    protected $facebookId;
201
202
    /**
203
     * @var string
204
     *
205
     * @ORM\Column(name="facebookUsername", type="string", length=255, nullable=true)
206
     * @JMS\Exclude
207
     */
208
    protected $facebookUsername;
209
210
    /**
211
     * @var string
212
     *
213
     * @ORM\Column(name="facebookAccessToken", type="string", length=255, nullable=true)
214
     * @JMS\Exclude()
215
     */
216
    protected $facebookAccessToken;
217
218
    /**
219
     * @var string
220
     *
221
     * @ORM\Column(name="twitterId", type="string", length=255, nullable=true, unique=true)
222
     * @JMS\Exclude
223
     */
224
    protected $twitterId;
225
226
    /**
227
     * @var string
228
     *
229
     * @ORM\Column(name="twitterUsername", type="string", length=255, nullable=true)
230
     * @JMS\Exclude
231
     */
232
    protected $twitterUsername;
233
234
    /**
235
     * @var string
236
     *
237
     * @ORM\Column(name="twitterAccessToken", type="string", length=255, nullable=true)
238
     * @JMS\Exclude
239
     */
240
    protected $twitterAccessToken;
241
242
    /**
243
     * @ORM\OneToMany(targetEntity="Authorization", mappedBy="person", cascade={"remove"}, orphanRemoval=true)
244
     */
245
    protected $authorizations;
246
247
    /**
248
     * @ORM\Column(type="datetime", nullable=false)
249
     * @var \DateTime
250
     * @JMS\Since("1.0")
251
     */
252
    protected $createdAt;
253
254
    /**
255
     * @ORM\Column(type="datetime", nullable=true)
256
     * @var \DateTime
257
     * @JMS\Since("1.0")
258
     */
259
    protected $emailConfirmedAt;
260
261
    /**
262
     * @ORM\Column(type="string", length=255, nullable=true)
263
     * @var string
264
     * @JMS\Since("1.0")
265
     */
266
    protected $previousValidEmail;
267
268
    /**
269
     * @ORM\ManyToMany(targetEntity="LoginCidadao\OAuthBundle\Entity\Client", mappedBy="owners")
270
     */
271
    protected $clients;
272
273
    /**
274
     * @ORM\OneToMany(targetEntity="ClientSuggestion", mappedBy="person")
275
     */
276
    protected $suggestions;
277
278
    /**
279
     * @JMS\Expose
280
     * @JMS\Groups({"state"})
281
     * @ORM\ManyToOne(targetEntity="LoginCidadao\CoreBundle\Entity\State")
282
     * @ORM\JoinColumn(name="state_id", referencedColumnName="id")
283
     * @JMS\Since("1.0.2")
284
     */
285
    protected $state;
286
287
    /**
288
     * @JMS\Expose
289
     * @JMS\Groups({"country"})
290
     * @ORM\ManyToOne(targetEntity="LoginCidadao\CoreBundle\Entity\Country")
291
     * @ORM\JoinColumn(name="country_id", referencedColumnName="id")
292
     * @JMS\Since("1.0.2")
293
     */
294
    protected $country;
295
296
    /**
297
     * @Assert\File(
298
     *      maxSize="2M",
299
     *      maxSizeMessage="The maxmimum allowed file size is 2MB.",
300
     *      mimeTypes={"image/png", "image/jpeg", "image/pjpeg"},
301
     *      mimeTypesMessage="Only JPEG and PNG images are allowed."
302
     * )
303
     * @Vich\UploadableField(mapping="user_image", fileNameProperty="imageName")
304
     * @var File $image
305
     * @JMS\Since("1.0.2")
306
     */
307
    protected $image;
308
309
    /**
310
     * @ORM\Column(type="string", length=255, name="image_name", nullable=true)
311
     *
312
     * @var string $imageName
313
     * @JMS\Since("1.0.2")
314
     */
315
    protected $imageName;
316
317
    /**
318
     * @JMS\Expose
319
     * @JMS\Groups({"public_profile","picture"})
320
     * @JMS\Since("1.0.2")
321
     * @JMS\Until("2")
322
     */
323
    protected $profilePictureUrl;
324
325
    /**
326
     * @ORM\Column(type="datetime", nullable=true)
327
     * @JMS\Expose
328
     * @JMS\Groups({"public_profile","updated_at"})
329
     * @var \DateTime $updatedAt
330
     * @JMS\Since("1.0.2")
331
     */
332
    protected $updatedAt;
333
334
    /**
335
     * @var string
336
     *
337
     * @ORM\Column(name="googleId", type="string", length=255, nullable=true, unique=true)
338
     * @JMS\Exclude
339
     */
340
    protected $googleId;
341
342
    /**
343
     * @var string
344
     *
345
     * @ORM\Column(name="googleUsername", type="string", length=255, nullable=true)
346
     * @JMS\Exclude
347
     */
348
    protected $googleUsername;
349
350
    /**
351
     * @var string
352
     *
353
     * @ORM\Column(name="googleAccessToken", type="string", length=255, nullable=true)
354
     * @JMS\Exclude
355
     */
356
    protected $googleAccessToken;
357
358
    /**
359
     * @JMS\Expose
360
     * @JMS\Groups({"id_cards"})
361
     * @ORM\OneToMany(targetEntity="LoginCidadao\CoreBundle\Entity\IdCard", mappedBy="person")
362
     * @JMS\Since("1.0.3")
363
     */
364
    protected $idCards;
365
366
    /**
367
     * @JMS\Expose
368
     * @JMS\Groups({"public_profile"})
369
     * @JMS\Type("array<LoginCidadao\BadgesControlBundle\Model\Badge>")
370
     * @JMS\Since("2")
371
     * @JMS\Until("3")
372
     * @deprecated Use RemoteClaims instead
373
     * @var array|BadgeInterface[]
374
     */
375
    protected $badges = [];
376
377
    /**
378
     * @ORM\OneToMany(targetEntity="LoginCidadao\APIBundle\Entity\LogoutKey", mappedBy="person", cascade={"remove"}, orphanRemoval=true)
379
     */
380
    protected $logoutKeys;
381
382
    /**
383
     * @JMS\Expose
384
     * @JMS\Groups({"addresses","address"})
385
     * @ORM\OneToMany(targetEntity="LoginCidadao\CoreBundle\Entity\PersonAddress", mappedBy="person", cascade={"remove"}, orphanRemoval=true)
386
     */
387
    protected $addresses;
388
389
    /**
390
     * @ORM\Column(name="google_authenticator_secret", type="string", nullable=true)
391
     * @JMS\Exclude
392
     */
393
    protected $googleAuthenticatorSecret;
394
395
    /**
396
     * @JMS\Expose
397
     * @JMS\Groups({"nationality"})
398
     * @ORM\ManyToOne(targetEntity="LoginCidadao\CoreBundle\Entity\Country")
399
     * @ORM\JoinColumn(name="nationality_id", referencedColumnName="id")
400
     * @JMS\Since("1.0.2")
401
     */
402
    protected $nationality;
403
404
    /**
405
     * @var BackupCode[]|ArrayCollection
406
     *
407
     * @JMS\Exclude
408
     * @ORM\OneToMany(targetEntity="BackupCode", mappedBy="person", cascade={"remove"}, orphanRemoval=true)
409
     */
410
    protected $backupCodes;
411
412
    /**
413
     * @JMS\Exclude
414
     * @ORM\Column(name="password_encoder_name", type="string", length=255, nullable=true)
415
     */
416
    protected $passwordEncoderName;
417
418
    /**
419
     * @JMS\Expose
420
     * @JMS\Groups({"public_profile"})
421
     * @JMS\SerializedName("phone_number_verified")
422
     * @JMS\Since("1.1")
423
     * @var bool
424
     */
425
    protected $phoneNumberVerified = false;
426
427 49
    public function __construct()
428
    {
429 49
        parent::__construct();
430 49
        $this->authorizations = new ArrayCollection();
431 49
        $this->clients = new ArrayCollection();
432 49
        $this->logoutKeys = new ArrayCollection();
433 49
        $this->addresses = new ArrayCollection();
434 49
        $this->backupCodes = new ArrayCollection();
435 49
    }
436
437 2
    public function getEmail()
438
    {
439 2
        return $this->email;
440
    }
441
442 3
    public function setEmail($email)
443
    {
444 3
        $this->email = $email;
445
446 3
        return $this;
447
    }
448
449 3
    public function getFirstName()
450
    {
451 3
        return $this->firstName;
452
    }
453
454 1
    public function setFirstName($firstName)
455
    {
456 1
        $this->firstName = $firstName;
457
458 1
        return $this;
459
    }
460
461 3
    public function getSurname()
462
    {
463 3
        return $this->surname;
464
    }
465
466 1
    public function setSurname($suname)
467
    {
468 1
        $this->surname = $suname;
469
470 1
        return $this;
471
    }
472
473 2
    public function getBirthdate()
474
    {
475 2
        return $this->birthdate;
476
    }
477
478
    public function setBirthdate($birthdate)
479
    {
480
        $this->birthdate = $birthdate;
481
482
        return $this;
483
    }
484
485 9
    public function getMobile()
486
    {
487 9
        return $this->mobile;
488
    }
489
490 6
    public function setMobile($mobile)
491
    {
492 6
        if (!($mobile instanceof PhoneNumber)) {
493 1
            $mobile = preg_replace('/[^0-9+]/', '', $mobile);
494
495
            // PhoneNumberBundle won't work with empty strings.
496
            // See https://github.com/misd-service-development/phone-number-bundle/issues/58
497 1
            if (strlen(trim($mobile)) === 0) {
498 1
                $mobile = null;
499
            }
500
        }
501 6
        $this->mobile = $mobile;
502
503 6
        return $this;
504
    }
505
506
    public function addAuthorization(Authorization $authorization)
507
    {
508
        $this->authorizations->add($authorization);
509
        $authorization->setPerson($this);
510
511
        return $this;
512
    }
513
514
    public function removeAuthorization(Authorization $authorization)
515
    {
516
        if ($this->authorizations->contains($authorization)) {
517
            $this->authorizations->removeElement($authorization);
518
        }
519
520
        return $this;
521
    }
522
523
    /**
524
     * @return Authorization[]|ArrayCollection
525
     */
526
    public function getAuthorizations($uidToIgnore = null)
527
    {
528
        if ($uidToIgnore !== null) {
529
            return array_filter(
530
                $this->authorizations->toArray(),
531
                function (Authorization $authorization) use ($uidToIgnore) {
532
                    return $authorization->getClient()->getUid() != $uidToIgnore;
533
                }
534
            );
535
        }
536
537
        return $this->authorizations;
538
    }
539
540
    /**
541
     * Checks if a given Client can access this Person's specified scope.
542
     * @param ClientInterface $client
543
     * @param mixed $scope can be a single scope or an array with several.
544
     * @return boolean
545
     */
546
    public function isAuthorizedClient(ClientInterface $client, $scope)
547
    {
548
        $authorizations = $this->getAuthorizations();
549
        foreach ($authorizations as $auth) {
550
            $c = $auth->getClient();
551
            if ($c->getId() == $client->getId()) {
552
                return $auth->hasScopes($scope);
553
            }
554
        }
555
556
        return false;
557
    }
558
559
    /**
560
     * @param Client $client
561
     * @return array
562
     */
563
    public function getClientScope(Client $client)
564
    {
565
        $authorizations = $this->getAuthorizations();
566
        foreach ($authorizations as $auth) {
567
            $c = $auth->getClient();
568
            if ($c->getId() == $client->getId()) {
569
                return $auth->getScope();
570
            }
571
        }
572
573
        return null;
574
    }
575
576
    /**
577
     * Checks if this Person has any authorization for a given Client.
578
     * WARNING: Note that it does NOT validate scope!
579
     * @param \LoginCidadao\OAuthBundle\Entity\Client | integer $client
580
     */
581
    public function hasAuthorization($client)
582
    {
583
        if ($client instanceof ClientInterface) {
584
            $id = $client->getId();
585
        } else {
586
            $id = $client;
587
        }
588
        $authorizations = $this->getAuthorizations();
589
        if (is_array($authorizations) || $authorizations instanceof Collection) {
0 ignored issues
show
introduced by
$authorizations is always a sub-type of Doctrine\Common\Collections\Collection.
Loading history...
590
            foreach ($authorizations as $auth) {
591
                $c = $auth->getClient();
592
                if ($c->getId() == $id) {
593
                    return true;
594
                }
595
            }
596
        }
597
598
        return false;
599
    }
600
601
    public function setFacebookId($facebookId)
602
    {
603
        $this->facebookId = $facebookId;
604
605
        return $this;
606
    }
607
608
    public function getFacebookId()
609
    {
610
        return $this->facebookId;
611
    }
612
613
    public function setTwitterId($twitterId)
614
    {
615
        $this->twitterId = $twitterId;
616
617
        return $this;
618
    }
619
620
    public function getTwitterId()
621
    {
622
        return $this->twitterId;
623
    }
624
625
    public function setTwitterUsername($twitterUsername)
626
    {
627
        $this->twitterUsername = $twitterUsername;
628
629
        return $this;
630
    }
631
632
    public function getTwitterUsername()
633
    {
634
        return $this->twitterUsername;
635
    }
636
637
    public function setTwitterAccessToken($twitterAccessToken)
638
    {
639
        $this->twitterAccessToken = $twitterAccessToken;
640
641
        return $this;
642
    }
643
644
    public function getTwitterAccessToken()
645
    {
646
        return $this->twitterAccessToken;
647
    }
648
649
    public function serialize()
650
    {
651
        return serialize(array($this->facebookId, parent::serialize()));
652
    }
653
654
    public function unserialize($data)
655
    {
656
        list($this->facebookId, $parentData) = unserialize($data);
657
        parent::unserialize($parentData);
658
    }
659
660
    /**
661
     * Get the full name of the user (first + last name)
662
     * @JMS\Groups({"full_name", "name"})
663
     * @JMS\VirtualProperty
664
     * @JMS\SerializedName("full_name")
665
     * @return string
666
     */
667 3
    public function getFullName()
668
    {
669 3
        $fullName = array();
670 3
        if ($this->getFirstname() !== null) {
671 1
            $fullName[] = $this->getFirstname();
672
        }
673 3
        if ($this->getSurname() !== null) {
674 1
            $fullName[] = $this->getSurname();
675
        }
676
677 3
        if (count($fullName) > 0) {
678 1
            return implode(' ', $fullName);
679
        } else {
680 2
            return null;
681
        }
682
    }
683
684
    /**
685
     * Get the full name of the user (first + last name)
686
     * @JMS\Groups({"full_name", "name"})
687
     * @JMS\VirtualProperty
688
     * @JMS\SerializedName("name")
689
     * @return string
690
     */
691
    public function getOIDCName()
692
    {
693
        return $this->getFullName();
694
    }
695
696
    /**
697
     * @JMS\Groups({"badges", "public_profile"})
698
     * @JMS\VirtualProperty
699
     * @JMS\SerializedName("deprecated_badges")
700
     * @JMS\Until("2")
701
     * @return array
702
     */
703
    public function getDataValid()
704
    {
705
        $terms['cpf'] = is_numeric($this->cpf);
0 ignored issues
show
Comprehensibility Best Practice introduced by
$terms was never initialized. Although not strictly required by PHP, it is generally a good practice to add $terms = array(); before regardless.
Loading history...
706
        $terms['email'] = is_null($this->getConfirmationToken());
707
708
        return $terms;
709
    }
710
711
    public function setCpf($cpf)
712
    {
713
        $cpf = trim(preg_replace('/[^0-9]/', '', $cpf));
714
715
        if ($cpf === '') {
716
            $cpf = null;
717
        }
718
719
        $this->cpf = $cpf;
720
721
        return $this;
722
    }
723
724 3
    public function getCpf()
725
    {
726 3
        return $this->cpf;
727
    }
728
729
    /**
730
     * @param City $city
731
     * @return PersonInterface
732
     */
733 1
    public function setCity(City $city = null)
734
    {
735 1
        $this->city = $city;
736
737 1
        return $this;
738
    }
739
740
    /**
741
     * @return City
742
     */
743 2
    public function getCity()
744
    {
745 2
        return $this->city;
746
    }
747
748 1
    public function setCreatedAt(\DateTime $createdAt)
749
    {
750 1
        $this->createdAt = $createdAt;
751
752 1
        return $this;
753
    }
754
755 1
    public function getCreatedAt()
756
    {
757 1
        return $this->createdAt;
758
    }
759
760
    /**
761
     * @ORM\PrePersist
762
     */
763
    public function setCreatedAtValue()
764
    {
765
        if (!($this->getCreatedAt() instanceof \DateTime)) {
0 ignored issues
show
introduced by
$this->getCreatedAt() is always a sub-type of DateTime.
Loading history...
766
            $this->createdAt = new \DateTime();
767
        }
768
        if (!$this->updatedAt) {
769
            $this->updatedAt = new \DateTime();
770
        }
771
    }
772
773 3
    public function setEmailConfirmedAt(\DateTime $emailConfirmedAt = null)
774
    {
775 3
        $this->emailConfirmedAt = $emailConfirmedAt;
776
777 3
        return $this;
778
    }
779
780 6
    public function getEmailConfirmedAt()
781
    {
782 6
        return $this->emailConfirmedAt;
783
    }
784
785
    public function getSocialNetworksPicture()
786
    {
787
        if (!is_null($this->getFacebookId())) {
0 ignored issues
show
introduced by
The condition is_null($this->getFacebookId()) is always false.
Loading history...
788
            return "https://graph.facebook.com/{$this->getFacebookId()}/picture?height=245&width=245";
789
        }
790
791
        return null;
792
    }
793
794
    public function getClients()
795
    {
796
        return $this->clients;
797
    }
798
799
    public function setClients($var)
800
    {
801
        return $this->clients = $var;
802
    }
803
804
    public function setEmailExpiration($emailExpiration)
805
    {
806
        $this->emailExpiration = $emailExpiration;
807
808
        return $this;
809
    }
810
811
    public function getEmailExpiration()
812
    {
813
        return $this->emailExpiration;
814
    }
815
816
    public function setFacebookUsername($facebookUsername)
817
    {
818
        $this->facebookUsername = $facebookUsername;
819
820
        return $this;
821
    }
822
823
    public function getFacebookUsername()
824
    {
825
        return $this->facebookUsername;
826
    }
827
828
    public function getFacebookAccessToken()
829
    {
830
        return $this->facebookAccessToken;
831
    }
832
833
    public function setFacebookAccessToken($facebookAccessToken)
834
    {
835
        $this->facebookAccessToken = $facebookAccessToken;
836
837
        return $this;
838
    }
839
840
    public function setPreviousValidEmail($previousValidEmail)
841
    {
842
        $this->previousValidEmail = $previousValidEmail;
843
844
        return $this;
845
    }
846
847
    public function getPreviousValidEmail()
848
    {
849
        return $this->previousValidEmail;
850
    }
851
852
    public function hasPassword()
853
    {
854
        $password = $this->getPassword();
855
856
        return strlen($password) > 0;
857
    }
858
859 1
    public function setState(State $state = null)
860
    {
861 1
        $this->state = $state;
862
863 1
        return $this;
864
    }
865
866 2
    public function getState()
867
    {
868 2
        return $this->state;
869
    }
870
871
    /**
872
     * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
873
     * of 'UploadedFile' is injected into this setter to trigger the  update. If this
874
     * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
875
     * must be able to accept an instance of 'File' as the bundle will inject one here
876
     * during Doctrine hydration.
877
     *
878
     * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
879
     */
880
    public function setImage($image)
881
    {
882
        $this->image = $image;
883
884
        if ($this->image) {
885
            $this->updatedAt = new \DateTime('now');
886
        }
887
    }
888
889
    /**
890
     * @return File
891
     */
892
    public function getImage()
893
    {
894
        return $this->image;
895
    }
896
897
    /**
898
     * @param string $imageName
899
     */
900
    public function setImageName($imageName)
901
    {
902
        $this->imageName = $imageName;
903
    }
904
905
    /**
906
     * @return string
907
     */
908
    public function getImageName()
909
    {
910
        return $this->imageName;
911
    }
912
913
    public function setProfilePictureUrl($profilePictureUrl)
914
    {
915
        $this->profilePictureUrl = $profilePictureUrl;
916
917
        return $this;
918
    }
919
920
    public function getProfilePictureUrl()
921
    {
922
        return $this->profilePictureUrl;
923
    }
924
925
    /**
926
     * @JMS\Groups({"public_profile"})
927
     * @JMS\VirtualProperty
928
     * @JMS\SerializedName("age_range")
929
     * @JMS\Type("array")
930
     * @return array
931
     */
932
    public function getAgeRange()
933
    {
934
        $today = new \DateTime('today');
935
        if (!$this->getBirthdate()) {
936
            return array();
937
        }
938
        $age = $this->getBirthdate()->diff($today)->y;
939
940
        $range = array();
941
        if ($age < 13) {
942
            $range['max'] = 13;
943
        }
944
        if ($age >= 13 && $age < 18) {
945
            $range['min'] = 13;
946
            $range['max'] = 17;
947
        }
948
        if ($age >= 18 && $age < 21) {
949
            $range['min'] = 18;
950
            $range['max'] = 20;
951
        }
952
        if ($age >= 21) {
953
            $range['min'] = 21;
954
        }
955
956
        return $range;
957
    }
958
959
    public function getSuggestions()
960
    {
961
        return $this->suggestions;
962
    }
963
964
    public function setSuggestions($suggestions)
965
    {
966
        $this->suggestions = $suggestions;
967
968
        return $this;
969
    }
970
971
    public function isClientAuthorized($app_id)
972
    {
973
        foreach ($this->getAuthorizations() as $auth) {
974
            if ($auth->getClient()->getPublicId() === $app_id) {
975
                return true;
976
            }
977
        }
978
979
        return false;
980
    }
981
982
    /**
983
     * @ORM\PreUpdate
984
     */
985 1
    public function setUpdatedAt($updatedAt = null)
986
    {
987 1
        if ($updatedAt instanceof \DateTime) {
988 1
            $this->updatedAt = $updatedAt;
989
        } else {
990
            $this->updatedAt = new \DateTime('now');
991
        }
992
993 1
        return $this;
994
    }
995
996 1
    public function getUpdatedAt()
997
    {
998 1
        return $this->updatedAt;
999
    }
1000
1001
    public function setGoogleId($var)
1002
    {
1003
        $this->googleId = $var;
1004
1005
        return $this;
1006
    }
1007
1008
    public function getGoogleId()
1009
    {
1010
        return $this->googleId;
1011
    }
1012
1013
    public function setGoogleUsername($var)
1014
    {
1015
        $this->googleUsername = $var;
1016
1017
        return $this;
1018
    }
1019
1020
    public function getGoogleUsername()
1021
    {
1022
        return $this->googleUsername;
1023
    }
1024
1025
    public function setGoogleAccessToken($var)
1026
    {
1027
        $this->googleAccessToken = $var;
1028
1029
        return $this;
1030
    }
1031
1032
    public function getGoogleAccessToken()
1033
    {
1034
        return $this->googleAccessToken;
1035
    }
1036
1037 1
    public function setCountry(Country $country = null)
1038
    {
1039 1
        $this->country = $country;
1040
1041 1
        return $this;
1042
    }
1043
1044 2
    public function getCountry()
1045
    {
1046 2
        return $this->country;
1047
    }
1048
1049
    public function getIdCards()
1050
    {
1051
        return $this->idCards;
1052
    }
1053
1054 1
    public function getBadges()
1055
    {
1056
        return /** @scrutinizer ignore-deprecated */
1057 1
            $this->badges;
1058
    }
1059
1060 1
    public function mergeBadges(array $badges)
1061
    {
1062
        /** @scrutinizer ignore-deprecated */
1063 1
        $this->badges = array_merge(/** @scrutinizer ignore-deprecated */
1064 1
            $this->badges, $badges);
1065
1066 1
        return $this;
1067
    }
1068
1069
    public function getFullNameOrUsername()
1070
    {
1071
        if (null === $this->firstName) {
1072
            return $this->username;
1073
        }
1074
1075
        return $this->getFullName();
1076
    }
1077
1078
    public function getLogoutKeys()
1079
    {
1080
        return $this->logoutKeys;
1081
    }
1082
1083
    /**
1084
     * @return ArrayCollection
1085
     */
1086
    public function getAddresses()
1087
    {
1088
        return $this->addresses;
1089
    }
1090
1091
    public function setLogoutKeys($logoutKeys)
1092
    {
1093
        $this->logoutKeys = $logoutKeys;
1094
1095
        return $this;
1096
    }
1097
1098
    public function setAddresses($addresses)
1099
    {
1100
        $this->addresses = $addresses;
1101
1102
        return $this;
1103
    }
1104
1105
    /**
1106
     * Checks whether 2FA is enabled.
1107
     *
1108
     * @return boolean
1109
     */
1110
    public function isTwoFactorAuthenticationEnabled()
1111
    {
1112
        return $this->googleAuthenticatorSecret !== null;
1113
    }
1114
1115
    public function getGoogleAuthenticatorSecret()
1116
    {
1117
        return $this->googleAuthenticatorSecret;
1118
    }
1119
1120
    public function setGoogleAuthenticatorSecret($googleAuthenticatorSecret)
1121
    {
1122
        $this->googleAuthenticatorSecret = $googleAuthenticatorSecret;
1123
1124
        return $this;
1125
    }
1126
1127
    public function getBackupCodes()
1128
    {
1129
        return $this->backupCodes;
1130
    }
1131
1132
    public function setBackupCodes(ArrayCollection $backupCodes)
1133
    {
1134
        $this->backupCodes = $backupCodes;
1135
1136
        return $this;
1137
    }
1138
1139
    public function invalidateBackupCode($code)
1140
    {
1141
        $backupCode = $this->findBackupCode($code);
1142
        $backupCode->setUsed(true);
1143
1144
        return $this;
1145
    }
1146
1147
    public function isBackupCode($code)
1148
    {
1149
        $backupCode = $this->findBackupCode($code);
1150
1151
        return $backupCode !== false && $backupCode->getUsed() === false;
1152
    }
1153
1154
    /**
1155
     * @param string $code
1156
     * @return BackupCode|false
1157
     */
1158
    private function findBackupCode($code)
1159
    {
1160
        $backupCodes = $this->getBackupCodes();
1161
        foreach ($backupCodes as $backupCode) {
1162
            if ($backupCode->getCode() === $code) {
1163
                return $backupCode;
1164
            }
1165
        }
1166
1167
        return false;
1168
    }
1169
1170
    public function setNationality($var)
1171
    {
1172
        $this->nationality = $var;
1173
1174
        return $this;
1175
    }
1176
1177
    public function getNationality()
1178
    {
1179
        return $this->nationality;
1180
    }
1181
1182
    public function getPlaceOfBirth()
1183
    {
1184
        $location = new LocationSelectData();
1185
        $location->getFromObject($this);
1186
1187
        return $location;
1188
    }
1189
1190
    public function setPlaceOfBirth(LocationSelectData $location)
1191
    {
1192
        $location->toObject($this);
1193
    }
1194
1195
    /**
1196
     * @JMS\Groups({"public_profile"})
1197
     * @JMS\VirtualProperty
1198
     * @JMS\SerializedName("given_name")
1199
     * @JMS\Since("1.0")
1200
     */
1201
    public function getGivenName()
1202
    {
1203
        return $this->getFirstName();
1204
    }
1205
1206
    /**
1207
     * @JMS\Groups({"full_name","name"})
1208
     * @JMS\VirtualProperty
1209
     * @JMS\SerializedName("family_name")
1210
     * @JMS\Since("1")
1211
     */
1212
    public function getFamilyName()
1213
    {
1214
        return $this->getSurname();
1215
    }
1216
1217
    /**
1218
     * @JMS\Groups({"mobile", "phone_number"})
1219
     * @JMS\VirtualProperty
1220
     * @JMS\SerializedName("phone_number")
1221
     */
1222
    public function getPhoneNumber()
1223
    {
1224
        return $this->getMobile();
1225
    }
1226
1227
    /**
1228
     * @param bool $verified
1229
     * @return $this
1230
     */
1231 1
    public function setPhoneNumberVerified($verified = false)
1232
    {
1233 1
        $this->phoneNumberVerified = $verified;
1234
1235 1
        return $this;
1236
    }
1237
1238
    /**
1239
     * @return bool
1240
     */
1241 2
    public function getPhoneNumberVerified()
1242
    {
1243 2
        return $this->phoneNumberVerified;
1244
    }
1245
1246
    public function getPasswordEncoderName()
1247
    {
1248
        return $this->passwordEncoderName;
1249
    }
1250
1251
    public function setPasswordEncoderName($passwordEncoderName)
1252
    {
1253
        $this->passwordEncoderName = $passwordEncoderName;
1254
1255
        return $this;
1256
    }
1257
1258
    public function getEncoderName()
1259
    {
1260
        $encoder = $this->passwordEncoderName;
1261
1262
        // BC for PR #357
1263
        if ($encoder === null || strlen($encoder) < 1) {
1264
            return null;
1265
        }
1266
1267
        return $encoder;
1268
    }
1269
1270
    public function getLongDisplayName()
1271
    {
1272
        if ($this->getFullName()) {
1273
            return $this->getFullName();
1274
        } else {
1275
            return $this->getEmail();
1276
        }
1277
    }
1278
1279
    public function getShortDisplayName()
1280
    {
1281
        if ($this->getGivenName()) {
1282
            return $this->getGivenName();
1283
        } else {
1284
            return $this->getEmail();
1285
        }
1286
    }
1287
}
1288