src/Entity/Uid.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UidRepository;
  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. /**
  11.  * @ORM\Entity(repositoryClass=UidRepository::class)
  12.  * @UniqueEntity(fields={"email"}, message="E-mail déjà lié à un compte")
  13.  */
  14. class Uid implements UserInterfacePasswordAuthenticatedUserInterface
  15. {
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=180, unique=true)
  24.      */
  25.     private $email;
  26.     /**
  27.      * @ORM\Column(type="json")
  28.      */
  29.     private $roles = [];
  30.     /**
  31.      * @var string The hashed password
  32.      * @ORM\Column(type="string")
  33.      */
  34.     private $password;
  35.     /**
  36.      * @ORM\OneToOne(targetEntity=Address::class, mappedBy="uid", cascade={"persist", "remove"})
  37.      */
  38.     private $address;
  39.     /**
  40.      * @ORM\Column(type="datetime_immutable")
  41.      */
  42.     private $createdAt;
  43.     /**
  44.      * @ORM\Column(type="boolean")
  45.      */
  46.     private $isActiv;
  47.     /**
  48.      * @ORM\Column(type="string", length=255)
  49.      */
  50.     private $firstname;
  51.     /**
  52.      * @ORM\Column(type="string", length=255)
  53.      */
  54.     private $lastname;
  55.     /**
  56.      * @ORM\Column(type="datetime_immutable", nullable=true)
  57.      */
  58.     private $connectedAt;
  59.     /**
  60.      * @ORM\Column(type="boolean")
  61.      */
  62.     private $isVerified false;
  63.     /**
  64.      * @ORM\OneToMany(targetEntity=Order::class, mappedBy="user")
  65.      */
  66.     private $orders;
  67.     /**
  68.      * @ORM\Column(type="string", length=255, nullable=true)
  69.      */
  70.     private $signature;
  71.     /**
  72.      * @ORM\Column(type="string", length=14)
  73.      */
  74.     private $phone;
  75.     /**
  76.      * @ORM\OneToOne(targetEntity=Cart::class, mappedBy="customer")
  77.      */
  78.     private ?Cart $cart null;
  79.     public function __construct()
  80.     {
  81.         $this->orders = new ArrayCollection();
  82.     }
  83.     /**
  84.      * @return int|null
  85.      */
  86.     public function getId(): ?int
  87.     {
  88.         return $this->id;
  89.     }
  90.     /**
  91.      * @return string|null
  92.      */
  93.     public function getEmail(): ?string
  94.     {
  95.         return $this->email;
  96.     }
  97.     /**
  98.      * @param string $email
  99.      * 
  100.      * @return self
  101.      */
  102.     public function setEmail(string $email): self
  103.     {
  104.         $this->email $email;
  105.         return $this;
  106.     }
  107.     /**
  108.      * A visual identifier that represents this user.
  109.      *
  110.      * @see UserInterface
  111.      */
  112.     public function getUserIdentifier(): string
  113.     {
  114.         return (string) $this->email;
  115.     }
  116.     /**
  117.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  118.      */
  119.     public function getUsername(): string
  120.     {
  121.         return (string) "$this->firstname $this->lastname";
  122.     }
  123.     /**
  124.      * @see UserInterface
  125.      */
  126.     public function getRoles(): array
  127.     {
  128.         $roles $this->roles;
  129.         // guarantee every user at least has ROLE_USER
  130.         $roles[] = 'ROLE_USER';
  131.         return array_unique($roles);
  132.     }
  133.     /**
  134.      * @param array $roles
  135.      * 
  136.      * @return self
  137.      */
  138.     public function setRoles(array $roles): self
  139.     {
  140.         $this->roles $roles;
  141.         return $this;
  142.     }
  143.     /**
  144.      * @see PasswordAuthenticatedUserInterface
  145.      */
  146.     public function getPassword(): string
  147.     {
  148.         return $this->password;
  149.     }
  150.     public function setPassword(string $password): self
  151.     {
  152.         $this->password $password;
  153.         return $this;
  154.     }
  155.     /**
  156.      * Returning a salt is only needed, if you are not using a modern
  157.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  158.      *
  159.      * @see UserInterface
  160.      */
  161.     public function getSalt(): ?string
  162.     {
  163.         return null;
  164.     }
  165.     /**
  166.      * @see UserInterface
  167.      */
  168.     public function eraseCredentials()
  169.     {
  170.         // If you store any temporary, sensitive data on the user, clear it here
  171.         // $this->plainPassword = null;
  172.     }
  173.     /**
  174.      * @return Address|null
  175.      */
  176.     public function getAddress(): ?Address
  177.     {
  178.         return $this->address;
  179.     }
  180.     /**
  181.      * @param Address $address
  182.      * 
  183.      * @return self
  184.      */
  185.     public function setAddress(Address $address): self
  186.     {
  187.         // set the owning side of the relation if necessary
  188.         if ($address->getUid() !== $this) {
  189.             $address->setUid($this);
  190.         }
  191.         $this->address $address;
  192.         return $this;
  193.     }
  194.     /**
  195.      * @return \DateTimeImmutable|null
  196.      */
  197.     public function getCreatedAt(): ?\DateTimeImmutable
  198.     {
  199.         return $this->createdAt;
  200.     }
  201.     /**
  202.      * @param \DateTimeImmutable $createdAt
  203.      * 
  204.      * @return self
  205.      */
  206.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  207.     {
  208.         $this->createdAt $createdAt;
  209.         return $this;
  210.     }
  211.     /**
  212.      * @return bool|null
  213.      */
  214.     public function getIsActiv(): ?bool
  215.     {
  216.         return $this->isActiv;
  217.     }
  218.     /**
  219.      * @param bool $isActiv
  220.      * 
  221.      * @return self
  222.      */
  223.     public function setIsActiv(bool $isActiv): self
  224.     {
  225.         $this->isActiv $isActiv;
  226.         return $this;
  227.     }
  228.     /**
  229.      * @return string|null
  230.      */
  231.     public function getFirstname(): ?string
  232.     {
  233.         return $this->firstname;
  234.     }
  235.     /**
  236.      * @param string $firstname
  237.      * 
  238.      * @return self
  239.      */
  240.     public function setFirstname(string $firstname): self
  241.     {
  242.         $this->firstname $firstname;
  243.         return $this;
  244.     }
  245.     /**
  246.      * @return string|null
  247.      */
  248.     public function getLastname(): ?string
  249.     {
  250.         return $this->lastname;
  251.     }
  252.     /**
  253.      * @param string $lastname
  254.      * 
  255.      * @return self
  256.      */
  257.     public function setLastname(string $lastname): self
  258.     {
  259.         $this->lastname $lastname;
  260.         return $this;
  261.     }
  262.     /**
  263.      * @return \DateTimeImmutable|null
  264.      */
  265.     public function getConnectedAt(): ?\DateTimeImmutable
  266.     {
  267.         return $this->connectedAt;
  268.     }
  269.     /**
  270.      * @param \DateTimeImmutable|null $connectedAt
  271.      * 
  272.      * @return self
  273.      */
  274.     public function setConnectedAt(?\DateTimeImmutable $connectedAt): self
  275.     {
  276.         $this->connectedAt $connectedAt;
  277.         return $this;
  278.     }
  279.     public function __toString()
  280.     {
  281.         return $this->firstname ' ' $this->lastname;
  282.     }
  283.     /**
  284.      * @return bool|null
  285.      */
  286.     public function isVerified(): bool
  287.     {
  288.         return $this->isVerified;
  289.     }
  290.     /**
  291.      * @param bool $isVerified
  292.      * 
  293.      * @return self
  294.      */
  295.     public function setIsVerified(bool $isVerified): self
  296.     {
  297.         $this->isVerified $isVerified;
  298.         return $this;
  299.     }
  300.     /**
  301.      * @return Collection|Order[]
  302.      */
  303.     public function getOrders(): Collection
  304.     {
  305.         return $this->orders;
  306.     }
  307.     public function addOrder(Order $order): self
  308.     {
  309.         if (!$this->orders->contains($order)) {
  310.             $this->orders[] = $order;
  311.             $order->setUser($this);
  312.         }
  313.         return $this;
  314.     }
  315.     public function removeOrder(Order $order): self
  316.     {
  317.         if ($this->orders->removeElement($order)) {
  318.             // set the owning side to null (unless already changed)
  319.             if ($order->getUser() === $this) {
  320.                 $order->setUser(null);
  321.             }
  322.         }
  323.         return $this;
  324.     }
  325.     public function getSignature(): ?string
  326.     {
  327.         return $this->signature;
  328.     }
  329.     public function setSignature(?string $signature): self
  330.     {
  331.         $this->signature $signature;
  332.         return $this;
  333.     }
  334.     public function getPhone(): ?string
  335.     {
  336.         return $this->phone;
  337.     }
  338.     public function setPhone(string $phone): self
  339.     {
  340.         $this->phone $phone;
  341.         return $this;
  342.     }
  343.     public function getCart(): ?Cart
  344.     {
  345.         return $this->cart;
  346.     }
  347.     public function setCart(Cart $cart): self
  348.     {
  349.         // set the owning side of the relation if necessary
  350.         if ($cart->getCustomer() !== $this) {
  351.             $cart->setCustomer($this);
  352.         }
  353.         $this->cart $cart;
  354.         return $this;
  355.     }
  356. }