src/Entity/Users.php line 16

  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Trait\CreatedAtTrait;
  4. use App\Repository\UsersRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  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. #[ORM\Entity(repositoryClass: UsersRepository::class)]
  12. #[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
  13. class Users implements UserInterface, PasswordAuthenticatedUserInterface
  14. {
  15.     use CreatedAtTrait;
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column]
  19.     private ?int $id = null;
  20.     #[ORM\Column(length: 180, unique: true)]
  21.     private ?string $email = null;
  22.     #[ORM\Column]
  23.     private array $roles = [];
  24.     /**
  25.      * @var string The hashed password
  26.      */
  27.     #[ORM\Column]
  28.     private ?string $password = null;
  29.     #[ORM\Column(length: 100)]
  30.     private ?string $lastname = null;
  31.     #[ORM\Column(length: 100)]
  32.     private ?string $firstname = null;
  33.     #[ORM\Column(length: 255)]
  34.     private ?string $address = null;
  35.     #[ORM\Column(length: 5)]
  36.     private ?string $zipcode = null;
  37.     #[ORM\Column(length: 150)]
  38.     private ?string $city = null;
  39.     #[ORM\Column(type: 'boolean')]
  40.     private $is_verified = false;
  41.     
  42.     #[ORM\Column(type: 'string', length: 100, nullable: true)]
  43.     private ?string $resetToken = null;
  44.     #[ORM\OneToMany(mappedBy: 'users', targetEntity: Orders::class)]
  45.     private Collection $orders;
  46.     public function __construct()
  47.     {
  48.         $this->orders = new ArrayCollection();
  49.         $this->created_at = new \DateTimeImmutable(); 
  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 setRoles(array $roles): self
  84.     {
  85.         $this->roles = $roles;
  86.         return $this;
  87.     }
  88.     /**
  89.      * @see PasswordAuthenticatedUserInterface
  90.      */
  91.     public function getPassword(): string
  92.     {
  93.         return $this->password;
  94.     }
  95.     public function setPassword(string $password): self
  96.     {
  97.         $this->password = $password;
  98.         return $this;
  99.     }
  100.     /**
  101.      * @see UserInterface
  102.      */
  103.     public function eraseCredentials()
  104.     {
  105.         // If you store any temporary, sensitive data on the user, clear it here
  106.         // $this->plainPassword = null;
  107.     }
  108.     public function getLastname(): ?string
  109.     {
  110.         return $this->lastname;
  111.     }
  112.     public function setLastname(string $lastname): self
  113.     {
  114.         $this->lastname = $lastname;
  115.         return $this;
  116.     }
  117.     public function getFirstname(): ?string
  118.     {
  119.         return $this->firstname;
  120.     }
  121.     public function setFirstname(string $firstname): self
  122.     {
  123.         $this->firstname = $firstname;
  124.         return $this;
  125.     }
  126.     public function getAddress(): ?string
  127.     {
  128.         return $this->address;
  129.     }
  130.     public function setAddress(string $address): self
  131.     {
  132.         $this->address = $address;
  133.         return $this;
  134.     }
  135.     public function getZipcode(): ?string
  136.     {
  137.         return $this->zipcode;
  138.     }
  139.     public function setZipcode(string $zipcode): self
  140.     {
  141.         $this->zipcode = $zipcode;
  142.         return $this;
  143.     }
  144.     public function getCity(): ?string
  145.     {
  146.         return $this->city;
  147.     }
  148.     public function setCity(string $city): self
  149.     {
  150.         $this->city = $city;
  151.         return $this;
  152.     }
  153.     public function getIsVerified(): ?bool
  154.     {
  155.         return $this->is_verified;
  156.     }
  157.     public function setIsVerified(bool $is_verified): self
  158.     {
  159.         $this->is_verified = $is_verified;
  160.         return $this;
  161.     }
  162.     public function getResetToken(): ?string
  163.     {
  164.         return $this->resetToken;
  165.     }
  166.     public function setResetToken(?string $resetToken): self
  167.     {
  168.         $this->resetToken = $resetToken;
  169.         return $this;
  170.     }
  171.     /**
  172.      * @return Collection<int, Orders>
  173.      */
  174.     public function getOrders(): Collection
  175.     {
  176.         return $this->orders;
  177.     }
  178.     public function addOrder(Orders $order): self
  179.     {
  180.         if (!$this->orders->contains($order)) {
  181.             $this->orders->add($order);
  182.             $order->setUsers($this);
  183.         }
  184.         return $this;
  185.     }
  186.     public function removeOrder(Orders $order): self
  187.     {
  188.         if ($this->orders->removeElement($order)) {
  189.             // set the owning side to null (unless already changed)
  190.             if ($order->getUsers() === $this) {
  191.                 $order->setUsers(null);
  192.             }
  193.         }
  194.         return $this;
  195.     }
  196. }