src/Entity/User.php line 18

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\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. /**
  12.  * @ORM\Entity(repositoryClass=UserRepository::class)
  13.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  14.  */
  15. class User implements UserInterfacePasswordAuthenticatedUserInterface
  16. {
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="string", length=180, unique=true)
  25.      * @Assert\Email
  26.      */
  27.     private $email;
  28.     /**
  29.      * @ORM\Column(type="json")
  30.      */
  31.     private $roles = [];
  32.     /**
  33.      * @var string The hashed password
  34.      * @ORM\Column(type="string")
  35.      */
  36.     private $password;
  37.     /**
  38.      * @ORM\Column(type="boolean")
  39.      */
  40.     private $isVerified false;
  41.     /**
  42.      * @ORM\Column(type="string", length=2)
  43.      */
  44.     private $lang;
  45.     /**
  46.      * @ORM\Column(type="string", length=255)
  47.      * @Assert\NotBlank
  48.      */
  49.     private $firstname;
  50.     /**
  51.      * @ORM\Column(type="string", length=255)
  52.      * @Assert\NotBlank
  53.      */
  54.     private $lastname;
  55.     /**
  56.      * @ORM\Column(type="string", length=255)
  57.      * @Assert\NotBlank
  58.      */
  59.     private $company;
  60.     /**
  61.      * @ORM\Column(type="datetime_immutable")
  62.      * @Assert\NotNull
  63.      */
  64.     private $created_at;
  65.     /**
  66.      * @ORM\OneToMany(targetEntity=JobAd::class, mappedBy="user", orphanRemoval=true, cascade={"remove"})
  67.      */
  68.     private $jobAds;
  69.     /**
  70.      * @ORM\OneToOne(targetEntity=UserAddress::class, cascade={"persist", "remove"})
  71.      * @Assert\Valid
  72.      */
  73.     private $address;
  74.     /**
  75.      * @ORM\OneToMany(targetEntity=Order::class, mappedBy="user", orphanRemoval=true)
  76.      */
  77.     private $orders;
  78.     public function __construct()
  79.     {
  80.         $this->created_at = new \DateTimeImmutable();
  81.         $this->jobAds = new ArrayCollection();
  82.         $this->orders = new ArrayCollection();
  83.     }
  84.     public function getId(): ?int
  85.     {
  86.         return $this->id;
  87.     }
  88.     public function getEmail(): ?string
  89.     {
  90.         return $this->email;
  91.     }
  92.     public function setEmail(string $email): self
  93.     {
  94.         $this->email $email;
  95.         return $this;
  96.     }
  97.     /**
  98.      * A visual identifier that represents this user.
  99.      *
  100.      * @see UserInterface
  101.      */
  102.     public function getUserIdentifier(): string
  103.     {
  104.         return (string) $this->email;
  105.     }
  106.     /**
  107.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  108.      */
  109.     public function getUsername(): string
  110.     {
  111.         return (string) $this->email;
  112.     }
  113.     /**
  114.      * @see UserInterface
  115.      */
  116.     public function getRoles(): array
  117.     {
  118.         $roles $this->roles;
  119.         // guarantee every user at least has ROLE_USER
  120.         $roles[] = 'ROLE_USER';
  121.         return array_unique($roles);
  122.     }
  123.     public function setRoles(array $roles): self
  124.     {
  125.         $this->roles $roles;
  126.         return $this;
  127.     }
  128.     /**
  129.      * @see PasswordAuthenticatedUserInterface
  130.      */
  131.     public function getPassword(): string
  132.     {
  133.         return $this->password;
  134.     }
  135.     public function setPassword(string $password): self
  136.     {
  137.         $this->password $password;
  138.         return $this;
  139.     }
  140.     /**
  141.      * Returning a salt is only needed, if you are not using a modern
  142.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  143.      *
  144.      * @see UserInterface
  145.      */
  146.     public function getSalt(): ?string
  147.     {
  148.         return null;
  149.     }
  150.     /**
  151.      * @see UserInterface
  152.      */
  153.     public function eraseCredentials()
  154.     {
  155.         // If you store any temporary, sensitive data on the user, clear it here
  156.         // $this->plainPassword = null;
  157.     }
  158.     public function isVerified(): bool
  159.     {
  160.         return $this->isVerified;
  161.     }
  162.     public function setIsVerified(bool $isVerified): self
  163.     {
  164.         $this->isVerified $isVerified;
  165.         return $this;
  166.     }
  167.     public function getLang(): ?string
  168.     {
  169.         return $this->lang;
  170.     }
  171.     public function setLang(string $lang): self
  172.     {
  173.         $this->lang $lang;
  174.         return $this;
  175.     }
  176.     public function getFirstname(): ?string
  177.     {
  178.         return $this->firstname;
  179.     }
  180.     public function setFirstname(?string $firstname): self
  181.     {
  182.         $this->firstname $firstname;
  183.         return $this;
  184.     }
  185.     public function getLastname(): ?string
  186.     {
  187.         return $this->lastname;
  188.     }
  189.     public function setLastname(?string $lastname): self
  190.     {
  191.         $this->lastname $lastname;
  192.         return $this;
  193.     }
  194.     public function getCompany(): ?string
  195.     {
  196.         return $this->company;
  197.     }
  198.     public function setCompany(?string $company): self
  199.     {
  200.         $this->company $company;
  201.         return $this;
  202.     }
  203.     public function getCreatedAt(): ?\DateTimeImmutable
  204.     {
  205.         return $this->created_at;
  206.     }
  207.     public function setCreatedAt(\DateTimeImmutable $created_at): self
  208.     {
  209.         $this->created_at $created_at;
  210.         return $this;
  211.     }
  212.     /**
  213.      * @return Collection|JobAd[]
  214.      */
  215.     public function getJobAds(): Collection
  216.     {
  217.         return $this->jobAds;
  218.     }
  219.     public function addJobAd(JobAd $jobAd): self
  220.     {
  221.         if (!$this->jobAds->contains($jobAd)) {
  222.             $this->jobAds[] = $jobAd;
  223.             $jobAd->setUser($this);
  224.         }
  225.         return $this;
  226.     }
  227.     public function removeJobAd(JobAd $jobAd): self
  228.     {
  229.         if ($this->jobAds->removeElement($jobAd)) {
  230.             // set the owning side to null (unless already changed)
  231.             if ($jobAd->getUser() === $this) {
  232.                 $jobAd->setUser(null);
  233.             }
  234.         }
  235.         return $this;
  236.     }
  237.     public function getAddress(): ?UserAddress
  238.     {
  239.         return $this->address;
  240.     }
  241.     public function setAddress(?UserAddress $address): self
  242.     {
  243.         $this->address $address;
  244.         return $this;
  245.     }
  246.     /**
  247.      * @return Collection<int, Order>
  248.      */
  249.     public function getOrders(): Collection
  250.     {
  251.         return $this->orders;
  252.     }
  253.     public function addOrder(Order $order): self
  254.     {
  255.         if (!$this->orders->contains($order)) {
  256.             $this->orders[] = $order;
  257.             $order->setUser($this);
  258.         }
  259.         return $this;
  260.     }
  261.     public function removeOrder(Order $order): self
  262.     {
  263.         if ($this->orders->removeElement($order)) {
  264.             // set the owning side to null (unless already changed)
  265.             if ($order->getUser() === $this) {
  266.                 $order->setUser(null);
  267.             }
  268.         }
  269.         return $this;
  270.     }
  271. }