<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=UserRepository::class)
* @UniqueEntity(fields={"email"}, message="There is already an account with this email")
*/
class User implements UserInterface, PasswordAuthenticatedUserInterface, \Serializable
{
const ROLE_CANDIDATE = 'ROLE_CANDIDATE';
const ROLE_ADMIN = 'ROLE_ADMIN';
const ROLE_COMPANY = 'ROLE_COMPANY';
const ROLE_TERRITORY = 'ROLE_TERRITORY';
const ROLE_USER_REAL_ESTATE = 'ROLE_USER_REAL_ESTATE';
const ROLE_ADMIN_REAL_ESTATE = 'ROLE_ADMIN_REAL_ESTATE';
const ROLE_PROJECT_OPPORTUNITY = 'ROLE_PROJECT_OPPORTUNITY';
const ROLE_PROJECT_ESTATE = 'ROLE_PROJECT_ESTATE';
const REGISTER_PAGE = 'register';
const LANDING_PAGE = 'landing';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=180, unique=true)
*/
private $email;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private $password;
/**
* @ORM\OneToOne(targetEntity=Person::class, cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*/
private $person;
/**
* @ORM\Column(type="datetime_immutable")
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime_immutable")
* @Gedmo\Timestampable(on="update")
*/
private $updatedAt;
/**
* @ORM\OneToOne(targetEntity=ProfessionalProfile::class, inversedBy="user", cascade={"persist", "remove"})
*/
private $professionalProfile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $token;
/**
* @ORM\Column(type="boolean")
*/
private $isVerified = false;
/**
* @ORM\OneToOne(targetEntity=NotificationParameter::class, cascade={"persist", "remove"})
*/
private $notificationParameter;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $oldAccount;
/**
* @ORM\ManyToOne(targetEntity=Territory::class, inversedBy="users")
* @ORM\JoinColumn(referencedColumnName="id", onDelete="SET NULL")
*/
private $territory;
/**
* @ORM\ManyToOne(targetEntity=CompanyProfile::class, inversedBy="users")
* @ORM\JoinColumn(referencedColumnName="id", onDelete="SET NULL")
*/
private $companyProfile;
/**
* @ORM\ManyToOne(targetEntity=RealEstateProfile::class, inversedBy="users")
* @ORM\JoinColumn(referencedColumnName="id", onDelete="SET NULL")
*/
private $realEstateProfile;
/**
* @ORM\OneToMany(targetEntity=RealEstateAd::class, mappedBy="user")
*/
private $realEstateAds;
/**
* @ORM\OneToMany(targetEntity=Opportunity::class, mappedBy="user")
*/
private $opportunities;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $registerPage;
public function __construct()
{
$this->realEstateAds = new ArrayCollection();
$this->opportunities = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @deprecated since Symfony 5.3, use getUserIdentifier instead
*/
public function getUsername(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* Returning a salt is only needed, if you are not using a modern
* hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
*
* @see UserInterface
*/
public function getSalt(): ?string
{
return null;
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getPerson(): ?Person
{
return $this->person;
}
public function setPerson(Person $person): self
{
$this->person = $person;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getProfessionalProfile(): ?ProfessionalProfile
{
return $this->professionalProfile;
}
public function setProfessionalProfile(?ProfessionalProfile $professionalProfile): self
{
$this->professionalProfile = $professionalProfile;
return $this;
}
public function getToken(): ?string
{
return $this->token;
}
public function setToken(?string $token): self
{
$this->token = $token;
return $this;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function serialize() {
return serialize(array(
$this->id,
$this->email,
$this->password,
));
}
public function unserialize($serialized) {
list (
$this->id,
$this->email,
$this->password,
) = unserialize($serialized);
}
public function getNotificationParameter(): ?NotificationParameter
{
return $this->notificationParameter;
}
public function setNotificationParameter(?NotificationParameter $notificationParameter): self
{
$this->notificationParameter = $notificationParameter;
return $this;
}
public function getOldAccount(): ?bool
{
return $this->oldAccount;
}
public function setOldAccount(?bool $oldAccount): self
{
$this->oldAccount = $oldAccount;
return $this;
}
public function getTerritory(): ?Territory
{
return $this->territory;
}
public function setTerritory(?Territory $territory): self
{
$this->territory = $territory;
return $this;
}
public function getCompanyProfile(): ?CompanyProfile
{
return $this->companyProfile;
}
public function setCompanyProfile(?CompanyProfile $companyProfile): self
{
$this->companyProfile = $companyProfile;
return $this;
}
public function getRealEstateProfile(): ?RealEstateProfile
{
return $this->realEstateProfile;
}
public function setRealEstateProfile(?RealEstateProfile $realEstateProfile): self
{
$this->realEstateProfile = $realEstateProfile;
return $this;
}
/**
* @return Collection|RealEstateAd[]
*/
public function getRealEstateAds(): Collection
{
return $this->realEstateAds;
}
public function getRealEstateAdIds(): array
{
return array_map(function(RealEstateAd $ad) {
return $ad->getId();
}, $this->realEstateAds->toArray());
}
public function addRealEstateAd(RealEstateAd $realEstateAd): self
{
if (!$this->realEstateAds->contains($realEstateAd)) {
$this->realEstateAds[] = $realEstateAd;
$realEstateAd->setUser($this);
}
return $this;
}
public function removeRealEstateAd(RealEstateAd $realEstateAd): self
{
if ($this->realEstateAds->removeElement($realEstateAd)) {
// set the owning side to null (unless already changed)
if ($realEstateAd->getUser() === $this) {
$realEstateAd->setUser(null);
}
}
return $this;
}
/**
* @return Collection|ProjectLeader[]
*/
public function getOpportunities(): Collection
{
return $this->opportunities;
}
public function getOpportunityIds(): array
{
return array_map(function(Opportunity $opportunity) {
return $opportunity->getId();
}, $this->opportunities->toArray());
}
public function addOpportunity(ProjectLeader $opportunity): self
{
if (!$this->opportunities->contains($opportunity)) {
$this->opportunities[] = $opportunity;
$opportunity->setUser($this);
}
return $this;
}
public function removeOpportunity(ProjectLeader $opportunity): self
{
if ($this->opportunities->removeElement($opportunity)) {
// set the owning side to null (unless already changed)
if ($opportunity->getUser() === $this) {
$opportunity->setUser(null);
}
}
return $this;
}
public function getRegisterPage(): ?string
{
return $this->registerPage;
}
public function setRegisterPage(?string $registerPage): self
{
$this->registerPage = $registerPage;
return $this;
}
}