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. /**
  11.  * @ORM\Entity(repositoryClass=UserRepository::class)
  12.  * @ORM\Table(name="`user`")
  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.      */
  26.     private $email;
  27.     /**
  28.      * @ORM\Column(type="json")
  29.      */
  30.     private $roles = [];
  31.     /**
  32.      * @var string The hashed password
  33.      * @ORM\Column(type="string")
  34.      */
  35.     private $password;
  36.     /**
  37.      * @ORM\Column(type="string", length=255)
  38.      */
  39.     private $name;
  40.         /**
  41.      * @ORM\Column(type="string", length=255)
  42.      */
  43.     private $firstName;
  44.     /**
  45.      * @ORM\Column(type="datetime_immutable")
  46.      */
  47.     private $createdAt;
  48.     /**
  49.      * @ORM\Column(type="string", length=255)
  50.      */
  51.     private $phone;
  52.     /**
  53.      * @ORM\OneToMany(targetEntity=Properties::class, mappedBy="user", cascade={"remove"})
  54.      */
  55.     private $properties;
  56.     /**
  57.      * @ORM\OneToOne(targetEntity=Rental::class, mappedBy="tenant", cascade={"persist", "remove"})
  58.      */
  59.     private $rental;
  60.     /**
  61.      * @ORM\ManyToOne(targetEntity=Address::class, inversedBy="users", cascade={"persist"})
  62.      * @ORM\JoinColumn(nullable=false)
  63.      */
  64.     private $address;
  65.     /**
  66.      * @ORM\OneToMany(targetEntity=HomeInterest::class, mappedBy="user", orphanRemoval=true)
  67.      */
  68.     private $homeInterests;
  69.     /**
  70.      * @ORM\OneToMany(targetEntity=RentalApplication::class, mappedBy="user")
  71.      */
  72.     private $rentalApplications;
  73.     /**
  74.      * @ORM\OneToMany(targetEntity=Appointment::class, mappedBy="user", orphanRemoval=true)
  75.      */
  76.     private Collection $appointments;
  77.     public function __construct()
  78.     {
  79.     $this->appointments = new ArrayCollection();
  80.         $this->properties = new ArrayCollection();
  81.         $this->address = new Address();
  82.         $this->homeInterests = new ArrayCollection();
  83.         $this->rentalApplications = new ArrayCollection();
  84.     }
  85.     public function getId(): ?int
  86.     {
  87.         return $this->id;
  88.     }
  89.     public function getEmail(): ?string
  90.     {
  91.         return $this->email;
  92.     }
  93.     public function setEmail(string $email): self
  94.     {
  95.         $this->email $email;
  96.         return $this;
  97.     }
  98.     /**
  99.      * A visual identifier that represents this user.
  100.      *
  101.      * @see UserInterface
  102.      */
  103.     public function getUserIdentifier(): string
  104.     {
  105.         return (string) $this->email;
  106.     }
  107.     /**
  108.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  109.      */
  110.     public function getUsername(): string
  111.     {
  112.         return (string) $this->email;
  113.     }
  114.     /**
  115.      * @see UserInterface
  116.      */
  117.     public function getRoles(): array
  118.     {
  119.         $roles $this->roles;
  120.         // guarantee every user at least has ROLE_USER
  121.         $roles[] = 'ROLE_USER';
  122.         return array_unique($roles);
  123.     }
  124.     public function setRoles(array $roles): self
  125.     {
  126.         $this->roles $roles;
  127.         return $this;
  128.     }
  129.     /**
  130.      * @see PasswordAuthenticatedUserInterface
  131.      */
  132.     public function getPassword(): string
  133.     {
  134.         return $this->password;
  135.     }
  136.     public function setPassword(string $password): self
  137.     {
  138.         $this->password $password;
  139.         return $this;
  140.     }
  141.     /**
  142.      * Returning a salt is only needed, if you are not using a modern
  143.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  144.      *
  145.      * @see UserInterface
  146.      */
  147.     public function getSalt(): ?string
  148.     {
  149.         return null;
  150.     }
  151.     /**
  152.      * @see UserInterface
  153.      */
  154.     public function eraseCredentials()
  155.     {
  156.         // If you store any temporary, sensitive data on the user, clear it here
  157.         // $this->plainPassword = null;
  158.     }
  159.     public function getName(): ?string
  160.     {
  161.         return $this->name;
  162.     }
  163.     public function setName(string $name): self
  164.     {
  165.         $this->name $name;
  166.         return $this;
  167.     }
  168.     public function getFirstName(): ?string
  169.     {
  170.         return $this->firstName;
  171.     }
  172.     public function setFirstName(string $firstName): self
  173.     {
  174.         $this->firstName $firstName;
  175.         return $this;
  176.     }
  177.     public function getCreatedAt(): ?\DateTimeImmutable
  178.     {
  179.         return $this->createdAt;
  180.     }
  181.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  182.     {
  183.         $this->createdAt $createdAt;
  184.         return $this;
  185.     }
  186.     public function getPhone(): ?string
  187.     {
  188.         return $this->phone;
  189.     }
  190.     public function setPhone(string $phone): self
  191.     {
  192.         $this->phone $phone;
  193.         return $this;
  194.     }
  195.     /**
  196.      * @return Collection<int, Properties>
  197.      */
  198.     public function getProperties(): Collection
  199.     {
  200.         return $this->properties;
  201.     }
  202.     public function addProperty(Properties $property): self
  203.     {
  204.         if (!$this->properties->contains($property)) {
  205.             $this->properties[] = $property;
  206.             $property->setUser($this);
  207.         }
  208.         return $this;
  209.     }
  210.     public function removeProperty(Properties $property): self
  211.     {
  212.         if ($this->properties->removeElement($property)) {
  213.             // set the owning side to null (unless already changed)
  214.             if ($property->getUser() === $this) {
  215.                 $property->setUser(null);
  216.             }
  217.         }
  218.         return $this;
  219.     }
  220.     public function getRental(): ?Rental
  221.     {
  222.         return $this->rental;
  223.     }
  224.     public function setRental(Rental $rental): self
  225.     {
  226.         // set the owning side of the relation if necessary
  227.         if ($rental->getTenant() !== $this) {
  228.             $rental->setTenant($this);
  229.         }
  230.         $this->rental $rental;
  231.         return $this;
  232.     }
  233.     public function getAddress(): ?Address
  234.     {
  235.         return $this->address;
  236.     }
  237.     public function setAddress(?Address $address): self
  238.     {
  239.         $this->address $address;
  240.         return $this;
  241.     }
  242.     /**
  243.      * @return Collection<int, RentalApplication>
  244.      */
  245.     public function getRentalApplications(): Collection
  246.     {
  247.         return $this->rentalApplications;
  248.     }
  249.     public function addRentalApplication(RentalApplication $rentalApplication): self
  250.     {
  251.         if (!$this->rentalApplications->contains($rentalApplication)) {
  252.             $this->rentalApplications[] = $rentalApplication;
  253.             $rentalApplication->setUser($this);
  254.         }
  255.         return $this;
  256.     }
  257.     public function removeRentalApplication(RentalApplication $rentalApplication): self
  258.     {
  259.         if ($this->rentalApplications->removeElement($rentalApplication)) {
  260.             // set the owning side to null (unless already changed)
  261.             if ($rentalApplication->getUser() === $this) {
  262.                 $rentalApplication->setUser(null);
  263.             }
  264.         }
  265.         return $this;
  266.     }
  267.     /**
  268.      * @return Collection<int, HomeInterest>
  269.      */
  270.     public function getHomeInterests(): Collection
  271.     {
  272.         return $this->homeInterests;
  273.     }
  274.     public function addHomeInterest(HomeInterest $homeInterest): static
  275.     {
  276.         if (!$this->homeInterests->contains($homeInterest)) {
  277.             $this->homeInterests->add($homeInterest);
  278.             $homeInterest->setUser($this);
  279.         }
  280.         return $this;
  281.     }
  282.     public function removeHomeInterest(HomeInterest $homeInterest): static
  283.     {
  284.         if ($this->homeInterests->removeElement($homeInterest)) {
  285.             // set the owning side to null (unless already changed)
  286.             if ($homeInterest->getUser() === $this) {
  287.                 $homeInterest->setUser(null);
  288.             }
  289.         }
  290.         return $this;
  291.     }
  292. /**
  293.      * @return Collection|Appointment[]
  294.      */
  295.     public function getAppointments(): Collection
  296.     {
  297.         return $this->appointments;
  298.     }
  299.     public function addAppointment(Appointment $appointment): self
  300.     {
  301.         if (!$this->appointments->contains($appointment)) {
  302.             $this->appointments[] = $appointment;
  303.             $appointment->setUser($this);
  304.         }
  305.         return $this;
  306.     }
  307.     public function removeAppointment(Appointment $appointment): self
  308.     {
  309.         if ($this->appointments->removeElement($appointment)) {
  310.             // set the owning side to null (unless already changed)
  311.             if ($appointment->getUser() === $this) {
  312.                 $appointment->setUser(null);
  313.             }
  314.         }
  315.         return $this;
  316.     }
  317. }