src/Entity/User.php line 17

Open in your IDE?
  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\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. /**
  10.  * @ORM\Entity(repositoryClass=UserRepository::class)
  11.  * @ORM\Table(name="`user`")
  12.  */
  13. class User implements UserInterfacePasswordAuthenticatedUserInterface
  14. {
  15.     
  16.     /**
  17.      * @ORM\OneToMany(targetEntity=Wishlist::class, mappedBy="user")
  18.      */
  19.     private $wishlists;
  20.     
  21.     /**
  22.      * @ORM\Id
  23.      * @ORM\GeneratedValue
  24.      * @ORM\Column(type="integer")
  25.      */
  26.     private $id;
  27.     /**
  28.      * @ORM\Column(type="string", length=180, unique=true)
  29.      */
  30.     private $email;
  31.     /**
  32.      * @ORM\Column(type="json")
  33.      */
  34.     private $roles = [];
  35.     /**
  36.      * @var string The hashed password
  37.      * @ORM\Column(type="string")
  38.      */
  39.     private $password;
  40.     public function getFullName(): string{
  41.         return $this->getFirstname().' '.$this->getLastname();
  42.     }
  43.     /**
  44.      * @ORM\Column(type="string", length=255)
  45.      */
  46.     private $firstname;
  47.     /**
  48.      * @ORM\Column(type="string", length=255)
  49.      */
  50.     private $lastname;
  51.     /**
  52.      * @ORM\OneToMany(targetEntity=Address::class, mappedBy="user")
  53.      */
  54.     private $addresses;
  55.     /**
  56.      * @ORM\OneToMany(targetEntity=Order::class, mappedBy="user")
  57.      */
  58.     private $orders;
  59.     public function __construct()
  60.     {
  61.         $this->addresses = new ArrayCollection();
  62.         $this->orders = new ArrayCollection();
  63.         $this->wishlists = new ArrayCollection();
  64.     }
  65.     public function getId(): ?int
  66.     {
  67.         return $this->id;
  68.     }
  69.     public function getEmail(): ?string
  70.     {
  71.         return $this->email;
  72.     }
  73.     public function setEmail(string $email): self
  74.     {
  75.         $this->email $email;
  76.         return $this;
  77.     }
  78.     /**
  79.      * A visual identifier that represents this user.
  80.      *
  81.      * @see UserInterface
  82.      */
  83.     public function getUserIdentifier(): string
  84.     {
  85.         return (string) $this->email;
  86.     }
  87.     /**
  88.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  89.      */
  90.     public function getUsername(): string
  91.     {
  92.         return (string) $this->email;
  93.     }
  94.     /**
  95.      * @see UserInterface
  96.      */
  97.     public function getRoles(): array
  98.     {
  99.         $roles $this->roles;
  100.         // guarantee every user at least has ROLE_USER
  101.         $roles[] = 'ROLE_USER';
  102.         return array_unique($roles);
  103.     }
  104.     public function setRoles(array $roles): self
  105.     {
  106.         $this->roles $roles;
  107.         return $this;
  108.     }
  109.     /**
  110.      * @see PasswordAuthenticatedUserInterface
  111.      */
  112.     public function getPassword(): string
  113.     {
  114.         return $this->password;
  115.     }
  116.     public function setPassword(string $password): self
  117.     {
  118.         $this->password $password;
  119.         return $this;
  120.     }
  121.     /**
  122.      * Returning a salt is only needed, if you are not using a modern
  123.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  124.      *
  125.      * @see UserInterface
  126.      */
  127.     public function getSalt(): ?string
  128.     {
  129.         return null;
  130.     }
  131.     /**
  132.      * @see UserInterface
  133.      */
  134.     public function eraseCredentials()
  135.     {
  136.         // If you store any temporary, sensitive data on the user, clear it here
  137.         // $this->plainPassword = null;
  138.     }
  139.     public function getFirstname(): ?string
  140.     {
  141.         return $this->firstname;
  142.     }
  143.     public function setFirstname(string $firstname): self
  144.     {
  145.         $this->firstname $firstname;
  146.         return $this;
  147.     }
  148.     public function getLastname(): ?string
  149.     {
  150.         return $this->lastname;
  151.     }
  152.     public function setLastname(string $lastname): self
  153.     {
  154.         $this->lastname $lastname;
  155.         return $this;
  156.     }
  157.     /**
  158.      * @return Collection<int, Address>
  159.      */
  160.     public function getAddresses(): Collection
  161.     {
  162.         return $this->addresses;
  163.     }
  164.     public function addAddress(Address $address): self
  165.     {
  166.         if (!$this->addresses->contains($address)) {
  167.             $this->addresses[] = $address;
  168.             $address->setUser($this);
  169.         }
  170.         return $this;
  171.     }
  172.     public function removeAddress(Address $address): self
  173.     {
  174.         if ($this->addresses->removeElement($address)) {
  175.             // set the owning side to null (unless already changed)
  176.             if ($address->getUser() === $this) {
  177.                 $address->setUser(null);
  178.             }
  179.         }
  180.         return $this;
  181.     }
  182.     /**
  183.      * @return Collection<int, Order>
  184.      */
  185.     public function getOrders(): Collection
  186.     {
  187.         return $this->orders;
  188.     }
  189.     public function addOrder(Order $order): self
  190.     {
  191.         if (!$this->orders->contains($order)) {
  192.             $this->orders[] = $order;
  193.             $order->setUser($this);
  194.         }
  195.         return $this;
  196.     }
  197.     public function removeOrder(Order $order): self
  198.     {
  199.         if ($this->orders->removeElement($order)) {
  200.             // set the owning side to null (unless already changed)
  201.             if ($order->getUser() === $this) {
  202.                 $order->setUser(null);
  203.             }
  204.         }
  205.         return $this;
  206.     }
  207. }