<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: '`users`')]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 180, unique: true)]
protected ?string $email = null;
#[ORM\Column(type: 'json_document', options: ['jsonb' => true])]
private array $roles = ['ROLE_USER'];
/**
* @var string The hashed password
*/
#[ORM\Column (nullable: true)]
private ?string $password = null;
#[ORM\Column(length: 255, nullable: true)]
protected ?string $firstName = null;
#[ORM\Column(length: 255, nullable: true)]
protected ?string $lastName = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
protected ?\DateTimeInterface $created_at ;
#[ORM\Column(nullable: true)]
protected ?string $phoneNumber = null;
#[ORM\Column(type: Types::STRING, length: 255, nullable: true)]
protected ?string $user_address = null;
/*
const BROKER = 'broker';
const ACCOUNTANT = 'accountant';
const TENANT = 'tenant';
const LANDLORD = 'landlord';
const OTHER = 'other';
/*
//#[ORM\Column(length: 255, nullable: true)]
#[ORM\Column(nullable:true)]
private ?array $userType = null;
*/
#[ORM\OneToOne(inversedBy: 'users', cascade: ['persist', 'remove'])]
private ?Broker $broker = null;
#[ORM\OneToOne(inversedBy: 'users', cascade: ['persist', 'remove'])]
private ?Accounting $accountant = null;
#[ORM\OneToOne(inversedBy: 'users', cascade: ['persist', 'remove'])]
private ?Landlords $landlord = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $userCity = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $userPostcode = null;
#[ORM\OneToOne(inversedBy: 'users', cascade: ['persist', 'remove'])]
private ?Tenants $tenant = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $floor = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $bloque = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $escalera = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $province = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $property_number = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $postcode = null;
#[ORM\OneToMany(mappedBy: 'uploadedByUser', targetEntity: Documents::class, cascade: ['persist','remove'])]
private Collection $document;
#[ORM\OneToMany(mappedBy: 'uploadedByUser', targetEntity: DocsTenants::class, cascade: ['persist','remove'])]
private Collection $tenantDocument;
#[ORM\OneToMany(mappedBy: 'generatedBy', targetEntity: MonthlyReport::class, cascade: ['persist','remove'])]
private Collection $monthlyReports;
#[ORM\Column(length: 255, nullable: true)]
private ?string $flatNumber = null;
#[ORM\Column(type: Types::ARRAY, nullable: true)]
private ?array $userType = null;
#[ORM\OneToOne(inversedBy: 'users', cascade: ['persist', 'remove'])]
private ?PotentialClients $potentialClient = null;
#[ORM\OneToMany(mappedBy: 'uploadedBy', targetEntity: DocsLandlords::class)]
private Collection $docsLandlords;
#[ORM\OneToMany(mappedBy: 'admin', targetEntity: Minutes::class, cascade:['persist','remove'])]
private Collection $minutes;
#[ORM\OneToMany(mappedBy: 'uploadedBy', targetEntity: DocsPotentials::class, cascade:['persist','remove'])]
private Collection $docsPotentials;
#[ORM\ManyToMany(targetEntity: Event::class, mappedBy: 'users', cascade:['persist','remove'])]
private Collection $events;
public function __toString(): string
{
return $this->getFirstName().' '.$this->getLastname();
}
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
{
if (is_array($this->roles)) {
$roles = $this->roles;
} elseif (is_object($this->roles)) {
$roles = array_values((array) $this->roles);
} else {
$roles = [];
}
// Guarantee every user has at least ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
/*
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
//$roles[] = 'ROLE_ADMIN';
return array_unique($roles);
*/
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
if (!in_array('ROLE_USER', $roles)) {
$this->roles[] = 'ROLE_USER';
}
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 getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(?string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(?string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at ;
return $this;
}
public function __construct()
{
$this->created_at = new \DateTime();
$this->document = new ArrayCollection();
$this->tenantDocument = new ArrayCollection();
$this->roles = [];
$this->monthlyReports = new ArrayCollection();
$this->docsLandlords = new ArrayCollection();
$this->minutes = new ArrayCollection();
$this->docsPotentials = new ArrayCollection();
$this->events = new ArrayCollection();
}
public function getPhoneNumber(): ?string
{
return $this->phoneNumber;
}
public function setPhoneNumber(?string $phoneNumber): self
{
$this->phoneNumber = $phoneNumber;
return $this;
}
public function getUserAddress(): ?string
{
return $this->user_address;
}
public function setUserAddress(string $user_address): self
{
$this->user_address = $user_address;
return $this;
}
/*
public function getUserType(): array
{
return $this->userType;
}
public function setUserType(array $userType): void
{
$this->userType = $userType;
//return $this;
}
*/
//public static function getUserTypes(): array
//{
// return [
// self::BROKER,
// self::ACCOUNTANT,
// self::TENANT,
// self::LANDLORD,
// self::OTHER,
// ];
//}
public function getBroker(): ?Broker
{
return $this->broker;
}
public function setBroker(?Broker $broker): self
{
$this->broker = $broker;
return $this;
}
public function getAccountant(): ?Accounting
{
return $this->accountant;
}
public function setAccountant(?Accounting $accountant): self
{
$this->accountant = $accountant;
return $this;
}
public function getLandlord(): ?Landlords
{
return $this->landlord;
}
public function setLandlord(?Landlords $landlord): self
{
$this->landlord = $landlord;
return $this;
}
public function getUserCity(): ?string
{
return $this->userCity;
}
public function setUserCity(?string $userCity): self
{
$this->userCity = $userCity;
return $this;
}
public function getUserPostcode(): ?string
{
return $this->userPostcode;
}
public function setUserPostcode(?string $userPostcode): self
{
$this->userPostcode = $userPostcode;
return $this;
}
public function getTenant(): ?Tenants
{
return $this->tenant;
}
public function setTenant(?Tenants $tenant): self
{
$this->tenant = $tenant;
return $this;
}
public function getFloor(): ?string
{
return $this->floor;
}
public function setFloor(?string $floor): self
{
$this->floor = $floor;
return $this;
}
public function getBloque(): ?string
{
return $this->bloque;
}
public function setBloque(?string $bloque): self
{
$this->bloque = $bloque;
return $this;
}
public function getEscalera(): ?string
{
return $this->escalera;
}
public function setEscalera(?string $escalera): self
{
$this->escalera = $escalera;
return $this;
}
public function getProvince(): ?string
{
return $this->province;
}
public function setProvince(?string $province): self
{
$this->province = $province;
return $this;
}
public function getPropertyNumber(): ?string
{
return $this->property_number;
}
public function setPropertyNumber(?string $property_number): self
{
$this->property_number = $property_number;
return $this;
}
public function getPostcode(): ?string
{
return $this->postcode;
}
public function setPostcode(?string $postcode): self
{
$this->postcode = $postcode;
return $this;
}
/**
* @return Collection<int, Documents>
*/
public function getDocument(): Collection
{
return $this->document;
}
public function addDocument(Documents $document): self
{
if (!$this->document->contains($document)) {
$this->document->add($document);
$document->setUploadedByUser($this);
}
return $this;
}
public function removeDocument(Documents $document): self
{
if ($this->document->removeElement($document)) {
// set the owning side to null (unless already changed)
if ($document->getUploadedByUser() === $this) {
$document->setUploadedByUser(null);
}
}
return $this;
}
/**
* @return Collection<int, DocsTenants>
*/
public function getTenantDocument(): Collection
{
return $this->tenantDocument;
}
public function addTenantDocument(DocsTenants $tenantDocument): self
{
if (!$this->tenantDocument->contains($tenantDocument)) {
$this->tenantDocument->add($tenantDocument);
$tenantDocument->setUploadedByUser($this);
}
return $this;
}
public function removeTenantDocument(DocsTenants $tenantDocument): self
{
if ($this->tenantDocument->removeElement($tenantDocument)) {
// set the owning side to null (unless already changed)
if ($tenantDocument->getUploadedByUser() === $this) {
$tenantDocument->setUploadedByUser(null);
}
}
return $this;
}
/**
* @return Collection<int, MonthlyReport>
*/
public function getMonthlyReports(): Collection
{
return $this->monthlyReports;
}
public function addMonthlyReport(MonthlyReport $monthlyReport): self
{
if (!$this->monthlyReports->contains($monthlyReport)) {
$this->monthlyReports->add($monthlyReport);
$monthlyReport->setGeneratedBy($this);
}
return $this;
}
public function removeMonthlyReport(MonthlyReport $monthlyReport): self
{
if ($this->monthlyReports->removeElement($monthlyReport)) {
// set the owning side to null (unless already changed)
if ($monthlyReport->getGeneratedBy() === $this) {
$monthlyReport->setGeneratedBy(null);
}
}
return $this;
}
public function getFlatNumber(): ?string
{
return $this->flatNumber;
}
public function setFlatNumber(?string $flatNumber): self
{
$this->flatNumber = $flatNumber;
return $this;
}
public function getUserType(): ?array
{
return $this->userType ?? [];
}
public function setUserType(?array $userType): self
{
$this->userType = $userType;
return $this;
}
public function getPotentialClient(): ?PotentialClients
{
return $this->potentialClient;
}
public function setPotentialClient(?PotentialClients $potentialClient): self
{
$this->potentialClient = $potentialClient;
return $this;
}
/**
* @return Collection<int, DocsLandlords>
*/
public function getDocsLandlords(): Collection
{
return $this->docsLandlords;
}
public function addDocsLandlord(DocsLandlords $docsLandlord): self
{
if (!$this->docsLandlords->contains($docsLandlord)) {
$this->docsLandlords->add($docsLandlord);
$docsLandlord->setUploadedBy($this);
}
return $this;
}
public function removeDocsLandlord(DocsLandlords $docsLandlord): self
{
if ($this->docsLandlords->removeElement($docsLandlord)) {
// set the owning side to null (unless already changed)
if ($docsLandlord->getUploadedBy() === $this) {
$docsLandlord->setUploadedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, Minutes>
*/
public function getMinutes(): Collection
{
return $this->minutes;
}
public function addMinute(Minutes $minute): self
{
if (!$this->minutes->contains($minute)) {
$this->minutes->add($minute);
$minute->setAdmin($this);
}
return $this;
}
public function removeMinute(Minutes $minute): self
{
if ($this->minutes->removeElement($minute)) {
// set the owning side to null (unless already changed)
if ($minute->getAdmin() === $this) {
$minute->setAdmin(null);
}
}
return $this;
}
/**
* @return Collection<int, DocsPotentials>
*/
public function getDocsPotentials(): Collection
{
return $this->docsPotentials;
}
public function addDocsPotential(DocsPotentials $docsPotential): static
{
if (!$this->docsPotentials->contains($docsPotential)) {
$this->docsPotentials->add($docsPotential);
$docsPotential->setUploadedBy($this);
}
return $this;
}
public function removeDocsPotential(DocsPotentials $docsPotential): static
{
if ($this->docsPotentials->removeElement($docsPotential)) {
// set the owning side to null (unless already changed)
if ($docsPotential->getUploadedBy() === $this) {
$docsPotential->setUploadedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, Event>
*/
public function getEvents(): Collection
{
return $this->events;
}
public function addEvent(Event $event): static
{
if (!$this->events->contains($event)) {
$this->events->add($event);
$event->addUser($this);
}
return $this;
}
public function removeEvent(Event $event): static
{
if ($this->events->removeElement($event)) {
$event->removeUser($this);
}
return $this;
}
}