src/Entity/User/Identity.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\User;
  3. use App\Repository\User\IdentityRepository;
  4. use DateTime;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Ramsey\Uuid\Doctrine\UuidGenerator;
  7. use Ramsey\Uuid\Uuid;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Serializer\Annotation\SerializedName;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. /**
  12.  * @ORM\Entity(repositoryClass=IdentityRepository::class)
  13.  */
  14. class Identity
  15. {
  16.     const GENDER_MALE 'M';
  17.     const GENDER_FEMALE 'MME';
  18.     const GENDER_LIST = [
  19.         self::GENDER_MALE,
  20.         self::GENDER_FEMALE,
  21.     ];
  22.     /**
  23.      * @ORM\Id
  24.      * @ORM\Column(type="uuid", unique=true)
  25.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  26.      * @SerializedName("id")
  27.      * @Assert\Uuid()
  28.      * @Groups({
  29.      *     "User:output",
  30.      *     "get_godfather_by_godchild_email",
  31.      *     "SponsorshipRequest:io",
  32.      * })
  33.      */
  34.     private string $id;
  35.     /**
  36.      * @ORM\Column(type="string", length=25)
  37.      * @SerializedName("first_name")
  38.      * @Assert\Length(max="25")
  39.      * @Groups({"User:io", "get_godfather_by_godchild_email", "SponsorshipRequest:io"})
  40.      * @Assert\Regex("/^[a-zA-Z-ëêéèâàäôïîç ]*$/",
  41.      *     message = "Numbers or special characters are not allowed")
  42.      */
  43.     private string $firstName;
  44.     /**
  45.      * @ORM\Column(type="string", length=25)
  46.      * @SerializedName("last_name")
  47.      * @Assert\Length(max="25")
  48.      * @Groups({"User:io", "get_godfather_by_godchild_email", "SponsorshipRequest:io"})
  49.      * @Assert\Regex("/^[a-zA-Z-ëêéèâàäôïîç ]*$/",
  50.      *     message = "Numbers or special characters are not allowed")
  51.      */
  52.     private string $lastName;
  53.     /**
  54.      * @ORM\Column(type="string", length=5, columnDefinition="ENUM('M', 'MME')")
  55.      * @SerializedName("gender")
  56.      * @Assert\Length(max="5")
  57.      * @Assert\Choice(choices=Identity::GENDER_LIST)
  58.      * @Groups({"User:io"})
  59.      */
  60.     private ?string $gender null;
  61.     /**
  62.      * @ORM\Column(type="datetime", nullable=true)
  63.      * @SerializedName("birthdate")
  64.      * @Assert\GreaterThan("1900-01-01")
  65.      * @Groups({"User:io"})
  66.      */
  67.     private ?DateTime $birthdate null;
  68.     /**
  69.      * @ORM\OneToOne(targetEntity=Identity::class)
  70.      * @ORM\JoinColumn(name="previous_identity_id", referencedColumnName="id", nullable=true)
  71.      * @Groups({"User:io"})
  72.      */
  73.     private ?Identity $previousIdentity;
  74.     public function __construct()
  75.     {
  76.         $this->id Uuid::uuid4();
  77.         $this->previousIdentity null;
  78.     }
  79.     /**
  80.      * @return string
  81.      */
  82.     public function getId(): ?string
  83.     {
  84.         return $this->id;
  85.     }
  86.     public function getFirstName(): ?string
  87.     {
  88.         return $this->firstName;
  89.     }
  90.     public function setFirstName(string $firstName): self
  91.     {
  92.         $this->firstName $firstName;
  93.         return $this;
  94.     }
  95.     public function getLastName(): ?string
  96.     {
  97.         return $this->lastName;
  98.     }
  99.     public function setLastName(string $lastName): self
  100.     {
  101.         $this->lastName $lastName;
  102.         return $this;
  103.     }
  104.     public function getGender(): ?string
  105.     {
  106.         return $this->gender;
  107.     }
  108.     public function setGender(string $gender): self
  109.     {
  110.         $this->gender $gender;
  111.         return $this;
  112.     }
  113.     public function getFormatedGender(): string
  114.     {
  115.         return ucfirst(strtolower($this->gender));
  116.     }
  117.     public function getBirthdate(): ?DateTime
  118.     {
  119.         return $this->birthdate;
  120.     }
  121.     public function setBirthdate(?DateTime $birthdate): Identity
  122.     {
  123.         $this->birthdate $birthdate;
  124.         return $this;
  125.     }
  126.     public function __toString(): string
  127.     {
  128.         return $this->firstName;
  129.     }
  130.     public function getPreviousIdentity() : ?Identity
  131.     {
  132.         return $this->previousIdentity;
  133.     }
  134.     public function setPreviousIdentity(?Identity $previousIdentity) : ?Identity
  135.     {
  136.         $this->previousIdentity $previousIdentity;
  137.         return $this;
  138.     }
  139. }