src/Entity/User.php line 15

  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 Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. #[ORM\Entity(repositoryClassUserRepository::class)]
  11. #[UniqueEntity(fields: ['email'], message'There is already an account with this email')]
  12. class User implements UserInterfacePasswordAuthenticatedUserInterface
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     private ?int $id null;
  18.     #[ORM\Column(length180uniquetrue)]
  19.     private ?string $email null;
  20.     #[ORM\Column]
  21.     private array $roles = [];
  22.     /**
  23.      * @var ?string The hashed password
  24.      */
  25.     #[ORM\Column]
  26.     private ?string $password '';
  27.     #[ORM\Column(type'boolean')]
  28.     private bool $isVerified false;
  29.     #[ORM\Column(type'string')]
  30.     private string $name;
  31.     #[ORM\Column(type'string')]
  32.     private string $surName;
  33.     #[ORM\Column(type'integer',nullabletrue)]
  34.     private  ?int $verificationCode null;
  35.     #[ORM\Column(type'string',nullabletrue)]
  36.     private  ?string $uuid null;
  37.     #[ORM\Column(type'string')]
  38.     private string $phone;
  39.     #[ORM\Column(type'string'nullabletrue)]
  40.     private mixed $birthdate null;
  41.     #[ORM\Column(type'string')]
  42.     private string $country;
  43.     #[ORM\Column(type'string')]
  44.     private string $city;
  45.     #[ORM\Column(type'string')]
  46.     private string $gender;
  47.     #[ORM\OneToMany(mappedBy'user'targetEntityBasket::class, cascade: ['persist''remove'])]
  48.     private Collection $basket;
  49.     #[ORM\OneToMany(mappedBy'user'targetEntityTransaction::class, cascade: ['persist''remove'])]
  50.     private Collection $transaction;
  51.     public function __construct()
  52.     {
  53.         $this->basket = new ArrayCollection();
  54.         $this->transaction = new ArrayCollection();
  55.     }
  56.     public function __toString(): string
  57.     {
  58.         return $this->name ?? "";
  59.     }
  60.     public function getId(): ?int
  61.     {
  62.         return $this->id;
  63.     }
  64.     public function getEmail(): ?string
  65.     {
  66.         return $this->email;
  67.     }
  68.     public function setEmail(string $email): self
  69.     {
  70.         $this->email $email;
  71.         return $this;
  72.     }
  73.     /**
  74.      * A visual identifier that represents this user.
  75.      *
  76.      * @see UserInterface
  77.      */
  78.     public function getUserIdentifier(): string
  79.     {
  80.         return (string) $this->email;
  81.     }
  82.     /**
  83.      * @see UserInterface
  84.      */
  85.     public function getRoles(): array
  86.     {
  87.         $roles $this->roles;
  88.         // guarantee every user at least has ROLE_USER
  89.         $roles[] = 'ROLE_USER';
  90.         return array_unique($roles);
  91.     }
  92.     public function setRoles(array $roles): self
  93.     {
  94.         $this->roles $roles;
  95.         return $this;
  96.     }
  97.     /**
  98.      * @see PasswordAuthenticatedUserInterface
  99.      */
  100.     public function getPassword(): ?string
  101.     {
  102.         return $this->password;
  103.     }
  104.     public function setPassword(?string $password): self
  105.     {
  106.         $this->password $password;
  107.         return $this;
  108.     }
  109.     /**
  110.      * @see UserInterface
  111.      */
  112.     public function eraseCredentials()
  113.     {
  114.         // If you store any temporary, sensitive data on the user, clear it here
  115.         // $this->plainPassword = null;
  116.     }
  117.     public function isVerified(): bool
  118.     {
  119.         return $this->isVerified;
  120.     }
  121.     public function setIsVerified(bool $isVerified): self
  122.     {
  123.         $this->isVerified $isVerified;
  124.         return $this;
  125.     }
  126.     public function isIsVerified(): ?bool
  127.     {
  128.         return $this->isVerified;
  129.     }
  130.     public function getName(): string
  131.     {
  132.         return $this->name;
  133.     }
  134.     public function setName(string $name): void
  135.     {
  136.         $this->name $name;
  137.     }
  138.     public function getSurName(): string
  139.     {
  140.         return $this->surName;
  141.     }
  142.     public function setSurName(string $surName): void
  143.     {
  144.         $this->surName $surName;
  145.     }
  146.     public function getPhone(): string
  147.     {
  148.         return $this->phone;
  149.     }
  150.     public function setPhone(string $phone): void
  151.     {
  152.         $this->phone $phone;
  153.     }
  154.     public function getBirthdate(): mixed
  155.     {
  156.         return $this->birthdate;
  157.     }
  158.     public function setBirthdate(mixed $birthdate): void
  159.     {
  160.         $this->birthdate $birthdate;
  161.     }
  162.     public function getCountry(): string
  163.     {
  164.         return $this->country;
  165.     }
  166.     public function setCountry(string $country): void
  167.     {
  168.         $this->country $country;
  169.     }
  170.     public function getCity(): string
  171.     {
  172.         return $this->city;
  173.     }
  174.     public function setCity(string $city): void
  175.     {
  176.         $this->city $city;
  177.     }
  178.     public function getGender(): string
  179.     {
  180.         return $this->gender;
  181.     }
  182.     public function setGender(string $gender): void
  183.     {
  184.         $this->gender $gender;
  185.     }
  186.     /**
  187.      * @return Collection<int, Basket>
  188.      */
  189.     public function getBasket(): Collection
  190.     {
  191.         return $this->basket;
  192.     }
  193.     public function addBasket(Basket $basket): static
  194.     {
  195.         if (!$this->basket->contains($basket)) {
  196.             $this->basket->add($basket);
  197.             $basket->setUser($this);
  198.         }
  199.         return $this;
  200.     }
  201.     public function removeBasket(Basket $basket): static
  202.     {
  203.         if ($this->basket->removeElement($basket)) {
  204.             // set the owning side to null (unless already changed)
  205.             if ($basket->getUser() === $this) {
  206.                 $basket->setUser(null);
  207.             }
  208.         }
  209.         return $this;
  210.     }
  211.     public function getVerificationCode(): ?int
  212.     {
  213.         return $this->verificationCode;
  214.     }
  215.     public function setVerificationCode(?int $verificationCode): void
  216.     {
  217.         $this->verificationCode $verificationCode;
  218.     }
  219.     public function getUuid(): ?string
  220.     {
  221.         return $this->uuid;
  222.     }
  223.     public function setUuid(?string $uuid): void
  224.     {
  225.         $this->uuid $uuid;
  226.     }
  227.     /**
  228.      * @return Collection<int, Transaction>
  229.      */
  230.     public function getTransaction(): Collection
  231.     {
  232.         return $this->transaction;
  233.     }
  234.     public function addTransaction(Transaction $transaction): static
  235.     {
  236.         if (!$this->transaction->contains($transaction)) {
  237.             $this->transaction->add($transaction);
  238.             $transaction->setUser($this);
  239.         }
  240.         return $this;
  241.     }
  242.     public function removeTransaction(Transaction $transaction): static
  243.     {
  244.         if ($this->transaction->removeElement($transaction)) {
  245.             // set the owning side to null (unless already changed)
  246.             if ($transaction->getUser() === $this) {
  247.                 $transaction->setUser(null);
  248.             }
  249.         }
  250.         return $this;
  251.     }
  252. }