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 Gedmo\Mapping\Annotation as Gedmo;
  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, \Serializable
  16. {
  17.     const ROLE_CANDIDATE 'ROLE_CANDIDATE';
  18.     const ROLE_ADMIN 'ROLE_ADMIN';
  19.     const ROLE_COMPANY 'ROLE_COMPANY';
  20.     const ROLE_TERRITORY 'ROLE_TERRITORY';
  21.     const ROLE_USER_REAL_ESTATE 'ROLE_USER_REAL_ESTATE';
  22.     const ROLE_ADMIN_REAL_ESTATE 'ROLE_ADMIN_REAL_ESTATE';
  23.     const ROLE_PROJECT_OPPORTUNITY 'ROLE_PROJECT_OPPORTUNITY';
  24.     const ROLE_PROJECT_ESTATE 'ROLE_PROJECT_ESTATE';
  25.     const REGISTER_PAGE 'register';
  26.     const LANDING_PAGE 'landing';
  27.     /**
  28.      * @ORM\Id
  29.      * @ORM\GeneratedValue
  30.      * @ORM\Column(type="integer")
  31.      */
  32.     private $id;
  33.     /**
  34.      * @ORM\Column(type="string", length=180, unique=true)
  35.      */
  36.     private $email;
  37.     /**
  38.      * @ORM\Column(type="json")
  39.      */
  40.     private $roles = [];
  41.     /**
  42.      * @var string The hashed password
  43.      * @ORM\Column(type="string")
  44.      */
  45.     private $password;
  46.     /**
  47.      * @ORM\OneToOne(targetEntity=Person::class, cascade={"persist", "remove"})
  48.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  49.      */
  50.     private $person;
  51.     /**
  52.      * @ORM\Column(type="datetime_immutable")
  53.      * @Gedmo\Timestampable(on="create")
  54.      */
  55.     private $createdAt;
  56.     /**
  57.      * @ORM\Column(type="datetime_immutable")
  58.      * @Gedmo\Timestampable(on="update")
  59.      */
  60.     private $updatedAt;
  61.     /**
  62.      * @ORM\OneToOne(targetEntity=ProfessionalProfile::class, inversedBy="user", cascade={"persist", "remove"})
  63.      */
  64.     private $professionalProfile;
  65.     /**
  66.      * @ORM\Column(type="string", length=255, nullable=true)
  67.      */
  68.     private $token;
  69.     /**
  70.      * @ORM\Column(type="boolean")
  71.      */
  72.     private $isVerified false;
  73.     /**
  74.      * @ORM\OneToOne(targetEntity=NotificationParameter::class, cascade={"persist", "remove"})
  75.      */
  76.     private $notificationParameter;
  77.     /**
  78.      * @ORM\Column(type="boolean", nullable=true)
  79.      */
  80.     private $oldAccount;
  81.     /**
  82.      * @ORM\ManyToOne(targetEntity=Territory::class, inversedBy="users")
  83.      * @ORM\JoinColumn(referencedColumnName="id", onDelete="SET NULL")
  84.      */
  85.     private $territory;
  86.     /**
  87.      * @ORM\ManyToOne(targetEntity=CompanyProfile::class, inversedBy="users")
  88.      * @ORM\JoinColumn(referencedColumnName="id", onDelete="SET NULL")
  89.      */
  90.     private $companyProfile;
  91.     /**
  92.      * @ORM\ManyToOne(targetEntity=RealEstateProfile::class, inversedBy="users")
  93.      * @ORM\JoinColumn(referencedColumnName="id", onDelete="SET NULL")
  94.      */
  95.     private $realEstateProfile;
  96.     /**
  97.      * @ORM\OneToMany(targetEntity=RealEstateAd::class, mappedBy="user")
  98.      */
  99.     private $realEstateAds;
  100.     /**
  101.      * @ORM\OneToMany(targetEntity=Opportunity::class, mappedBy="user")
  102.      */
  103.     private $opportunities;
  104.     /**
  105.      * @ORM\Column(type="string", length=255, nullable=true)
  106.      */
  107.     private $registerPage;
  108.     public function __construct()
  109.     {
  110.         $this->realEstateAds = new ArrayCollection();
  111.         $this->opportunities = new ArrayCollection();
  112.     }
  113.     public function getId(): ?int
  114.     {
  115.         return $this->id;
  116.     }
  117.     public function getEmail(): ?string
  118.     {
  119.         return $this->email;
  120.     }
  121.     public function setEmail(string $email): self
  122.     {
  123.         $this->email $email;
  124.         return $this;
  125.     }
  126.     /**
  127.      * A visual identifier that represents this user.
  128.      *
  129.      * @see UserInterface
  130.      */
  131.     public function getUserIdentifier(): string
  132.     {
  133.         return (string) $this->email;
  134.     }
  135.     /**
  136.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  137.      */
  138.     public function getUsername(): string
  139.     {
  140.         return (string) $this->email;
  141.     }
  142.     /**
  143.      * @see UserInterface
  144.      */
  145.     public function getRoles(): array
  146.     {
  147.         $roles $this->roles;
  148.         // guarantee every user at least has ROLE_USER
  149.         $roles[] = 'ROLE_USER';
  150.         return array_unique($roles);
  151.     }
  152.     public function setRoles(array $roles): self
  153.     {
  154.         $this->roles $roles;
  155.         return $this;
  156.     }
  157.     /**
  158.      * @see PasswordAuthenticatedUserInterface
  159.      */
  160.     public function getPassword(): string
  161.     {
  162.         return $this->password;
  163.     }
  164.     public function setPassword(string $password): self
  165.     {
  166.         $this->password $password;
  167.         return $this;
  168.     }
  169.     /**
  170.      * Returning a salt is only needed, if you are not using a modern
  171.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  172.      *
  173.      * @see UserInterface
  174.      */
  175.     public function getSalt(): ?string
  176.     {
  177.         return null;
  178.     }
  179.     /**
  180.      * @see UserInterface
  181.      */
  182.     public function eraseCredentials()
  183.     {
  184.         // If you store any temporary, sensitive data on the user, clear it here
  185.         // $this->plainPassword = null;
  186.     }
  187.     public function getPerson(): ?Person
  188.     {
  189.         return $this->person;
  190.     }
  191.     public function setPerson(Person $person): self
  192.     {
  193.         $this->person $person;
  194.         return $this;
  195.     }
  196.     public function getCreatedAt(): ?\DateTimeImmutable
  197.     {
  198.         return $this->createdAt;
  199.     }
  200.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  201.     {
  202.         $this->createdAt $createdAt;
  203.         return $this;
  204.     }
  205.     public function getUpdatedAt(): ?\DateTimeImmutable
  206.     {
  207.         return $this->updatedAt;
  208.     }
  209.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  210.     {
  211.         $this->updatedAt $updatedAt;
  212.         return $this;
  213.     }
  214.     public function getProfessionalProfile(): ?ProfessionalProfile
  215.     {
  216.         return $this->professionalProfile;
  217.     }
  218.     public function setProfessionalProfile(?ProfessionalProfile $professionalProfile): self
  219.     {
  220.         $this->professionalProfile $professionalProfile;
  221.         return $this;
  222.     }
  223.     public function getToken(): ?string
  224.     {
  225.         return $this->token;
  226.     }
  227.     public function setToken(?string $token): self
  228.     {
  229.         $this->token $token;
  230.         return $this;
  231.     }
  232.     public function isVerified(): bool
  233.     {
  234.         return $this->isVerified;
  235.     }
  236.     public function setIsVerified(bool $isVerified): self
  237.     {
  238.         $this->isVerified $isVerified;
  239.         return $this;
  240.     }
  241.     public function serialize() {
  242.         return serialize(array(
  243.             $this->id,
  244.             $this->email,
  245.             $this->password,
  246.         ));
  247.     }
  248.     public function unserialize($serialized) {
  249.         list (
  250.             $this->id,
  251.             $this->email,
  252.             $this->password,
  253.             ) = unserialize($serialized);
  254.     }
  255.     public function getNotificationParameter(): ?NotificationParameter
  256.     {
  257.         return $this->notificationParameter;
  258.     }
  259.     public function setNotificationParameter(?NotificationParameter $notificationParameter): self
  260.     {
  261.         $this->notificationParameter $notificationParameter;
  262.         return $this;
  263.     }
  264.     public function getOldAccount(): ?bool
  265.     {
  266.         return $this->oldAccount;
  267.     }
  268.     public function setOldAccount(?bool $oldAccount): self
  269.     {
  270.         $this->oldAccount $oldAccount;
  271.         return $this;
  272.     }
  273.     public function getTerritory(): ?Territory
  274.     {
  275.         return $this->territory;
  276.     }
  277.     public function setTerritory(?Territory $territory): self
  278.     {
  279.         $this->territory $territory;
  280.         return $this;
  281.     }
  282.     public function getCompanyProfile(): ?CompanyProfile
  283.     {
  284.         return $this->companyProfile;
  285.     }
  286.     public function setCompanyProfile(?CompanyProfile $companyProfile): self
  287.     {
  288.         $this->companyProfile $companyProfile;
  289.         return $this;
  290.     }
  291.     public function getRealEstateProfile(): ?RealEstateProfile
  292.     {
  293.         return $this->realEstateProfile;
  294.     }
  295.     public function setRealEstateProfile(?RealEstateProfile $realEstateProfile): self
  296.     {
  297.         $this->realEstateProfile $realEstateProfile;
  298.         return $this;
  299.     }
  300.     /**
  301.      * @return Collection|RealEstateAd[]
  302.      */
  303.     public function getRealEstateAds(): Collection
  304.     {
  305.         return $this->realEstateAds;
  306.     }
  307.     public function getRealEstateAdIds(): array
  308.     {
  309.         return array_map(function(RealEstateAd $ad) {
  310.             return $ad->getId();
  311.         }, $this->realEstateAds->toArray());
  312.     }
  313.     public function addRealEstateAd(RealEstateAd $realEstateAd): self
  314.     {
  315.         if (!$this->realEstateAds->contains($realEstateAd)) {
  316.             $this->realEstateAds[] = $realEstateAd;
  317.             $realEstateAd->setUser($this);
  318.         }
  319.         return $this;
  320.     }
  321.     public function removeRealEstateAd(RealEstateAd $realEstateAd): self
  322.     {
  323.         if ($this->realEstateAds->removeElement($realEstateAd)) {
  324.             // set the owning side to null (unless already changed)
  325.             if ($realEstateAd->getUser() === $this) {
  326.                 $realEstateAd->setUser(null);
  327.             }
  328.         }
  329.         return $this;
  330.     }
  331.     /**
  332.      * @return Collection|ProjectLeader[]
  333.      */
  334.     public function getOpportunities(): Collection
  335.     {
  336.         return $this->opportunities;
  337.     }
  338.     public function getOpportunityIds(): array
  339.     {
  340.         return array_map(function(Opportunity $opportunity) {
  341.             return $opportunity->getId();
  342.         }, $this->opportunities->toArray());
  343.     }
  344.     public function addOpportunity(ProjectLeader $opportunity): self
  345.     {
  346.         if (!$this->opportunities->contains($opportunity)) {
  347.             $this->opportunities[] = $opportunity;
  348.             $opportunity->setUser($this);
  349.         }
  350.         return $this;
  351.     }
  352.     public function removeOpportunity(ProjectLeader $opportunity): self
  353.     {
  354.         if ($this->opportunities->removeElement($opportunity)) {
  355.             // set the owning side to null (unless already changed)
  356.             if ($opportunity->getUser() === $this) {
  357.                 $opportunity->setUser(null);
  358.             }
  359.         }
  360.         return $this;
  361.     }
  362.     public function getRegisterPage(): ?string
  363.     {
  364.         return $this->registerPage;
  365.     }
  366.     public function setRegisterPage(?string $registerPage): self
  367.     {
  368.         $this->registerPage $registerPage;
  369.         return $this;
  370.     }
  371. }