src/Entity/User.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  6. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. #[ORM\Entity(repositoryClassUserRepository::class)]
  10. #[UniqueEntity(['email'])]
  11. #[UniqueEntity(['username'])]
  12. class User implements UserInterfacePasswordAuthenticatedUserInterface
  13. {
  14.     final const USER_SUPER_ADMIN_ID 1;
  15.     final const USER_DEFAULT_ID 2;
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column(type'integer')]
  19.     private ?int $id;
  20.     #[ORM\Column(type'string'length180uniquetrue)]
  21.     #[Assert\Email]
  22.     #[Assert\NotNull]
  23.     private ?string $email;
  24.     #[ORM\Column(length255)]
  25. //    #[Assert\Length(
  26. //        min: 3,
  27. //        max: 4096,
  28. //        minMessage: " the username must have minimum {{ limit }} characters")]
  29. //    #[Assert\NotNull]
  30.     private ?string $username null;
  31.     #[ORM\Column(type'json')]
  32.     private array $roles = [];
  33.     #[ORM\Column(type'string')]
  34.     #[Assert\Length(min6minMessage'Your password should be at least {{ limit }} characters')]
  35.     private ?string $password=  null;
  36.     #[ORM\OneToOne(inversedBy'user'targetEntityPersonal::class, cascade: ['persist''remove'])]
  37.     private ?Personal $personal;
  38.     #[ORM\Column(type'boolean')]
  39.     private bool $isVerified false;
  40.     #[ORM\Column(nullablefalse)]
  41.     private ?bool $active null;
  42.     #[ORM\ManyToOne(cascade: ['persist'])]
  43.     private ?Customer $customer null;
  44.     #[ORM\Column(length255,nullabletrue)]
  45.     private ?string $google_id null;
  46.     /*    #[ORM\Column(type: 'string')]
  47.         private ?string $verifToken = null;*/
  48.     public function __construct()
  49.     {
  50.     }
  51.     public function getId(): ?int
  52.     {
  53.         return $this->id;
  54.     }
  55.     public function getEmail(): ?string
  56.     {
  57.         return $this->email;
  58.     }
  59.     public function setEmail(?string $email): self
  60.     {
  61.         $this->email $email;
  62.         return $this;
  63.     }
  64.     /**
  65.      * A visual identifier that represents this user.
  66.      *
  67.      * @see UserInterface
  68.      */
  69.     public function getUserIdentifier(): string
  70.     {
  71.         return (string)$this->email;
  72.     }
  73.     /**
  74.      * @see UserInterface
  75.      */
  76.     public function getRoles(): array
  77.     {
  78.         $roles $this->roles;
  79.         // guarantee every user at least has ROLE_USER
  80.         $roles[] = 'ROLE_USER';
  81.         return array_unique($roles);
  82.     }
  83.     public function getRole(): string
  84.     {
  85.         if ($this->roles && count($this->roles) > 0) {
  86.             $role $this->roles[0];
  87.             $role str_replace("ROLE_"""$role);
  88.             //$role = str_replace("_"," ", $role);
  89.             return $role;
  90.         }
  91.         return '';
  92.     }
  93.     public function setRoles(array $roles): self
  94.     {
  95.         $this->roles $roles;
  96.         return $this;
  97.     }
  98.     /**
  99.      * @see PasswordAuthenticatedUserInterface
  100.      */
  101.     public function getPassword(): ?string
  102.     {
  103.         return $this->password;
  104.     }
  105.     public function setPassword(?string $password): self
  106.     {
  107.         $this->password $password;
  108.         return $this;
  109.     }
  110.     /**
  111.      * @see UserInterface
  112.      */
  113.     public function eraseCredentials()
  114.     {
  115.         // If you store any temporary, sensitive data on the user, clear it here
  116.         // $this->plainPassword = null;
  117.     }
  118.     public function getPersonal(): ?Personal
  119.     {
  120.         return $this->personal;
  121.     }
  122.     public function setPersonal(?Personal $personal): self
  123.     {
  124.         $this->personal $personal;
  125.         return $this;
  126.     }
  127.     public function isVerified(): bool
  128.     {
  129.         return $this->isVerified;
  130.     }
  131.     public function setIsVerified(bool $isVerified): self
  132.     {
  133.         $this->isVerified $isVerified;
  134.         return $this;
  135.     }
  136.     public function getUsername(): ?string
  137.     {
  138.         return $this->username;
  139.     }
  140.     public function setUsername(string $username): self
  141.     {
  142.         $this->username $username;
  143.         return $this;
  144.     }
  145.     public function isActive(): ?bool
  146.     {
  147.         return $this->active;
  148.     }
  149.     public function setActive(?bool $active): self
  150.     {
  151.         $this->active $active;
  152.         return $this;
  153.     }
  154.     public function getCustomer(): ?Customer
  155.     {
  156.         return $this->customer;
  157.     }
  158.     public function setCustomer(?Customer $customer): self
  159.     {
  160.         $this->customer $customer;
  161.         return $this;
  162.     }
  163.     public function __toString(): string
  164.     {
  165.         return $this->username;
  166.     }
  167.     public function getGoogleId(): ?string
  168.     {
  169.         return $this->google_id;
  170.     }
  171.     public function setGoogleId(string $google_id): static
  172.     {
  173.         $this->google_id $google_id;
  174.         return $this;
  175.     }
  176. }