src/Entity/User.php line 19

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Timestampable\Traits\TimestampableEntity;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. #[ORM\Entity(repositoryClassUserRepository::class)]
  13. #[ORM\Table(name'`users`')]
  14. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  15. //#[UniqueEntity('email')]
  16. class User implements UserInterfacePasswordAuthenticatedUserInterface
  17. {
  18.     use TimestampableEntity;
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue]
  21.     #[ORM\Column]
  22.     private ?int $id null;
  23. //    #[Assert\All([
  24. //        new Assert\NotBlank,
  25. //        new Assert\Length(min: 2)
  26. //    ])]
  27.     #[Assert\Length(min2,max30)]
  28.     #[ORM\Column(length30,)]
  29.     private ?string $last_name null;
  30. //    #[Assert\All([
  31. //        new Assert\NotBlank,
  32. //        new Assert\Length(min: 2)
  33. //    ])]
  34.     #[Assert\NotBlank()]
  35.     #[Assert\Length(min2,max50)]
  36.     #[ORM\Column(length50,)]
  37.     private ?string $first_name null;
  38. //    #[Assert\All([
  39. //        new Assert\Email()
  40. //    ])]
  41.     #[Assert\NotBlank()]
  42.     #[Assert\Length(min2,max180)]
  43.     #[Assert\Email()]
  44.     #[ORM\Column(length180uniquetrue)]
  45.     private ?string $email null;
  46.     #[ORM\Column(length50nullabletrue)]
  47.     private ?string $phone null;
  48.     #[ORM\Column(length100nullabletrue)]
  49.     private ?string $address null;
  50.     #[ORM\Column(length50nullabletrue)]
  51.     private ?string $city null;
  52.     #[ORM\Column(length100nullabletrue)]
  53.     private ?string $country null;
  54.     #[ORM\Column(length50nullabletrue)]
  55.     private ?string $company null;
  56.     #[ORM\Column]
  57.     private array $roles = [];
  58.     /**
  59.      * @var string The hashed password
  60.      */
  61.     #[ORM\Column]
  62.     private ?string $password null;
  63.     #[ORM\Column(type'boolean')]
  64.     private $isVerified false;
  65.     #[ORM\OneToMany(mappedBy'user'targetEntityNotification::class, cascade: ['ALL'])]
  66.     private Collection $notifications;
  67.     public function __construct()
  68.     {
  69.         $this->notifications = new ArrayCollection();
  70.     }
  71.     public function getId(): ?int
  72.     {
  73.         return $this->id;
  74.     }
  75.     public function getLastName(): ?string
  76.     {
  77.         return $this->last_name;
  78.     }
  79.     public function setLastName(string $last_name): self
  80.     {
  81.         $this->last_name $last_name;
  82.         return $this;
  83.     }
  84.     public function getFirstName(): ?string
  85.     {
  86.         return $this->first_name;
  87.     }
  88.     public function setFirstName(string $first_name): self
  89.     {
  90.         $this->first_name $first_name;
  91.         return $this;
  92.     }
  93.     public function getEmail(): ?string
  94.     {
  95.         return $this->email;
  96.     }
  97.     public function setEmail(string $email): self
  98.     {
  99.         $this->email $email;
  100.         return $this;
  101.     }
  102.     public function getPhone(): ?string
  103.     {
  104.         return $this->phone;
  105.     }
  106.     public function setPhone(string $phone): self
  107.     {
  108.         $this->phone $phone;
  109.         return $this;
  110.     }
  111.     public function getAddress(): ?string
  112.     {
  113.         return $this->address;
  114.     }
  115.     public function setAddress(string $address): self
  116.     {
  117.         $this->address $address;
  118.         return $this;
  119.     }
  120.     public function getCity(): ?string
  121.     {
  122.         return $this->city;
  123.     }
  124.     public function setCity(string $city): self
  125.     {
  126.         $this->city $city;
  127.         return $this;
  128.     }
  129.     public function getCountry(): ?string
  130.     {
  131.         return $this->country;
  132.     }
  133.     public function setCountry(string $country): self
  134.     {
  135.         $this->country $country;
  136.         return $this;
  137.     }
  138.     public function getCompany(): ?string
  139.     {
  140.         return $this->company;
  141.     }
  142.     public function setCompany(string $company): self
  143.     {
  144.         $this->company $company;
  145.         return $this;
  146.     }
  147.     /**
  148.      * A visual identifier that represents this user.
  149.      *
  150.      * @see UserInterface
  151.      */
  152.     public function getUserIdentifier(): string
  153.     {
  154.         return (string) $this->email;
  155.     }
  156.     /**
  157.      * @see UserInterface
  158.      */
  159.     public function getRoles(): array
  160.     {
  161.         $roles $this->roles;
  162.         // guarantee every user at least has ROLE_USER
  163.         $roles[] = 'ROLE_USER';
  164.         return array_unique($roles);
  165.     }
  166.     public function setRoles(array $roles): self
  167.     {
  168.         $this->roles $roles;
  169.         return $this;
  170.     }
  171.     /**
  172.      * @see PasswordAuthenticatedUserInterface
  173.      */
  174.     public function getPassword(): string
  175.     {
  176.         return $this->password;
  177.     }
  178.     public function setPassword(string $password): self
  179.     {
  180.         $this->password $password;
  181.         return $this;
  182.     }
  183.     /**
  184.      * @see UserInterface
  185.      */
  186.     public function eraseCredentials()
  187.     {
  188.         // If you store any temporary, sensitive data on the user, clear it here
  189.         // $this->plainPassword = null;
  190.     }
  191.     public function isVerified(): bool
  192.     {
  193.         return $this->isVerified;
  194.     }
  195.     public function setIsVerified(bool $isVerified): self
  196.     {
  197.         $this->isVerified $isVerified;
  198.         return $this;
  199.     }
  200.     /**
  201.      * @return Collection<int, Notification>
  202.      */
  203.     public function getNotifications(): Collection
  204.     {
  205.         return $this->notifications;
  206.     }
  207.     public function addNotification(Notification $notification): self
  208.     {
  209.         if (!$this->notifications->contains($notification)) {
  210.             $this->notifications->add($notification);
  211.             $notification->setUser($this);
  212.         }
  213.         return $this;
  214.     }
  215.     public function removeNotification(Notification $notification): self
  216.     {
  217.         if ($this->notifications->removeElement($notification)) {
  218.             // set the owning side to null (unless already changed)
  219.             if ($notification->getUser() === $this) {
  220.                 $notification->setUser(null);
  221.             }
  222.         }
  223.         return $this;
  224.     }
  225.     public function getFullName(): string
  226.     {
  227.         return $this->last_name ' ' $this->first_name;
  228.     }
  229. }