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\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=UserRepository::class)
  12.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  13.  */
  14. class User 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\Column(type="string", length=255)
  37.      */
  38.     private $firstname;
  39.     /**
  40.      * @ORM\Column(type="string", length=255)
  41.      */
  42.     private $lastname;
  43.     /**
  44.      * @ORM\Column(type="string", length=100)
  45.      */
  46.     private $phone;
  47.     /**
  48.      * @ORM\ManyToOne(targetEntity=Service::class, inversedBy="users")
  49.      * @ORM\JoinColumn(nullable=true)
  50.      */
  51.     private $service;
  52.     /**
  53.      * @ORM\ManyToOne(targetEntity=Category::class, inversedBy="users")
  54.      * @ORM\JoinColumn(nullable=true)
  55.      */
  56.     private $category;
  57.     /**
  58.      * @ORM\Column(type="string", length=50, nullable=true)
  59.      */
  60.     private $society;
  61.     /**
  62.      * @ORM\Column(type="string", length=50, nullable=true)
  63.      */
  64.     private $job;
  65.     /**
  66.      * @ORM\Column(type="string", length=255)
  67.      */
  68.     private $ask_object;
  69.     /**
  70.      * @ORM\Column(type="datetime")
  71.      */
  72.     private $created_At;
  73.     /**
  74.      * @ORM\Column(type="datetime",nullable=true)
  75.      */
  76.     private $updated_At;
  77.     /**
  78.      * @ORM\Column(type="datetime", nullable=true)
  79.      */
  80.     private $deleted_At;
  81.     /**
  82.      * @ORM\OneToMany(targetEntity=Booking::class, mappedBy="user")
  83.      */
  84.     private $bookings;
  85.     /**
  86.      * @ORM\OneToMany(targetEntity=Bill::class, mappedBy="user")
  87.      */
  88.     private $bills;
  89.     /**
  90.      * @ORM\OneToMany(targetEntity=Commentary::class, mappedBy="author")
  91.      */
  92.     private $commentaries;
  93.     /**
  94.      * @ORM\OneToMany(targetEntity=Contact::class, mappedBy="user")
  95.      */
  96.     private $contacts;
  97.     public function __construct()
  98.     {
  99.         $this->bookings = new ArrayCollection();
  100.         $this->bills = new ArrayCollection();
  101.         $this->articles = new ArrayCollection();
  102.         $this->commentaries = new ArrayCollection();
  103.         $this->contacts = new ArrayCollection();
  104.     }
  105.     public function getId(): ?int
  106.     {
  107.         return $this->id;
  108.     }
  109.     public function getEmail(): ?string
  110.     {
  111.         return $this->email;
  112.     }
  113.     public function setEmail(string $email): self
  114.     {
  115.         $this->email $email;
  116.         return $this;
  117.     }
  118.     /**
  119.      * A visual identifier that represents this user.
  120.      *
  121.      * @see UserInterface
  122.      */
  123.     public function getUserIdentifier(): string
  124.     {
  125.         return (string) $this->email;
  126.     }
  127.     /**
  128.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  129.      */
  130.     public function getUsername(): string
  131.     {
  132.         return (string) $this->email;
  133.     }
  134.     /**
  135.      * @see UserInterface
  136.      */
  137.     public function getRoles(): array
  138.     {
  139.         $roles $this->roles;
  140.         // guarantee every user at least has ROLE_USER
  141.         $roles[] = 'ROLE_USER';
  142.         return array_unique($roles);
  143.     }
  144.     public function setRoles(array $roles): self
  145.     {
  146.         $this->roles $roles;
  147.         return $this;
  148.     }
  149.     /**
  150.      * @see PasswordAuthenticatedUserInterface
  151.      */
  152.     public function getPassword(): string
  153.     {
  154.         return $this->password;
  155.     }
  156.     public function setPassword(string $password): self
  157.     {
  158.         $this->password $password;
  159.         return $this;
  160.     }
  161.     /**
  162.      * Returning a salt is only needed, if you are not using a modern
  163.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  164.      *
  165.      * @see UserInterface
  166.      */
  167.     public function getSalt(): ?string
  168.     {
  169.         return null;
  170.     }
  171.     /**
  172.      * @see UserInterface
  173.      */
  174.     public function eraseCredentials()
  175.     {
  176.         // If you store any temporary, sensitive data on the user, clear it here
  177.         // $this->plainPassword = null;
  178.     }
  179.     public function getFirstname(): ?string
  180.     {
  181.         return $this->firstname;
  182.     }
  183.     public function setFirstname(string $firstname): self
  184.     {
  185.         $this->firstname $firstname;
  186.         return $this;
  187.     }
  188.     public function getLastname(): ?string
  189.     {
  190.         return $this->lastname;
  191.     }
  192.     public function setLastname(string $lastname): self
  193.     {
  194.         $this->lastname $lastname;
  195.         return $this;
  196.     }
  197.     public function getPhone(): ?string
  198.     {
  199.         return $this->phone;
  200.     }
  201.     public function setPhone(string $phone): self
  202.     {
  203.         $this->phone $phone;
  204.         return $this;
  205.     }
  206.     public function getService(): ?Service
  207.     {
  208.         return $this->service;
  209.     }
  210.     public function setService(?Service $service): self
  211.     {
  212.         $this->service $service;
  213.         return $this;
  214.     }
  215.     public function getCategory(): ?Category
  216.     {
  217.         return $this->category;
  218.     }
  219.     public function setCategory(?Category $category): self
  220.     {
  221.         $this->category $category;
  222.         return $this;
  223.     }
  224.     public function getSociety(): ?string
  225.     {
  226.         return $this->society;
  227.     }
  228.     public function setSociety(?string $society): self
  229.     {
  230.         $this->society $society;
  231.         return $this;
  232.     }
  233.     public function getJob(): ?string
  234.     {
  235.         return $this->job;
  236.     }
  237.     public function setJob(?string $job): self
  238.     {
  239.         $this->job $job;
  240.         return $this;
  241.     }
  242.     public function getAskObject(): ?string
  243.     {
  244.         return $this->ask_object;
  245.     }
  246.     public function setAskObject(string $ask_object): self
  247.     {
  248.         $this->ask_object $ask_object;
  249.         return $this;
  250.     }
  251.     public function getCreatedAt(): ?\DateTimeInterface
  252.     {
  253.         return $this->created_At;
  254.     }
  255.     public function setCreatedAt(\DateTimeInterface $created_At): self
  256.     {
  257.         $this->created_At $created_At;
  258.         return $this;
  259.     }
  260.     public function getUpdatedAt(): ?\DateTimeInterface
  261.     {
  262.         return $this->updated_At;
  263.     }
  264.     public function setUpdatedAt(\DateTimeInterface $updated_At): self
  265.     {
  266.         $this->updated_At $updated_At;
  267.         return $this;
  268.     }
  269.     public function getDeletedAt(): ?\DateTimeInterface
  270.     {
  271.         return $this->deleted_At;
  272.     }
  273.     public function setDeletedAt(?\DateTimeInterface $deleted_At): self
  274.     {
  275.         $this->deleted_At $deleted_At;
  276.         return $this;
  277.     }
  278.     /**
  279.      * @return Collection<int, Booking>
  280.      */
  281.     public function getBookings(): Collection
  282.     {
  283.         return $this->bookings;
  284.     }
  285.     public function addBooking(Booking $booking): self
  286.     {
  287.         if (!$this->bookings->contains($booking)) {
  288.             $this->bookings[] = $booking;
  289.             $booking->setUser($this);
  290.         }
  291.         return $this;
  292.     }
  293.     public function removeBooking(Booking $booking): self
  294.     {
  295.         if ($this->bookings->removeElement($booking)) {
  296.             // set the owning side to null (unless already changed)
  297.             if ($booking->getUser() === $this) {
  298.                 $booking->setUser(null);
  299.             }
  300.         }
  301.         return $this;
  302.     }
  303.     /**
  304.      * @return Collection<int, Bill>
  305.      */
  306.     public function getBills(): Collection
  307.     {
  308.         return $this->bills;
  309.     }
  310.     public function addBill(Bill $bill): self
  311.     {
  312.         if (!$this->bills->contains($bill)) {
  313.             $this->bills[] = $bill;
  314.             $bill->setUser($this);
  315.         }
  316.         return $this;
  317.     }
  318.     public function removeBill(Bill $bill): self
  319.     {
  320.         if ($this->bills->removeElement($bill)) {
  321.             // set the owning side to null (unless already changed)
  322.             if ($bill->getUser() === $this) {
  323.                 $bill->setUser(null);
  324.             }
  325.         }
  326.         return $this;
  327.     }
  328.     /**
  329.      * @return Collection<int, Commentary>
  330.      */
  331.     public function getCommentaries(): Collection
  332.     {
  333.         return $this->commentaries;
  334.     }
  335.     public function addCommentary(Commentary $commentary): self
  336.     {
  337.         if (!$this->commentaries->contains($commentary)) {
  338.             $this->commentaries[] = $commentary;
  339.             $commentary->setAuthor($this);
  340.         }
  341.         return $this;
  342.     }
  343.     public function removeCommentary(Commentary $commentary): self
  344.     {
  345.         if ($this->commentaries->removeElement($commentary)) {
  346.             // set the owning side to null (unless already changed)
  347.             if ($commentary->getAuthor() === $this) {
  348.                 $commentary->setAuthor(null);
  349.             }
  350.         }
  351.         return $this;
  352.     }
  353.     /**
  354.      * @return Collection<int, Contact>
  355.      */
  356.     public function getContacts(): Collection
  357.     {
  358.         return $this->contacts;
  359.     }
  360.     public function addContact(Contact $contact): self
  361.     {
  362.         if (!$this->contacts->contains($contact)) {
  363.             $this->contacts[] = $contact;
  364.             $contact->setUser($this);
  365.         }
  366.         return $this;
  367.     }
  368.     public function removeContact(Contact $contact): self
  369.     {
  370.         if ($this->contacts->removeElement($contact)) {
  371.             // set the owning side to null (unless already changed)
  372.             if ($contact->getUser() === $this) {
  373.                 $contact->setUser(null);
  374.             }
  375.         }
  376.         return $this;
  377.     }
  378. }