<?php
declare(strict_types=1);
namespace Infrastructure\Persistence\Doctrine\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity
* @UniqueEntity(fields={"email"}, errorPath="email", message="Emailadres is al in gebruik.")
*/
class User implements UserInterface, \Serializable
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Infrastructure\Persistence\Doctrine\Entity\Company", cascade={"persist"})
* @ORM\JoinColumn(onDelete="SET NULL")
*/
private $company;
/**
* @ORM\Column(type="string", length=255, unique=true)
*/
private $email;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $password;
/**
* @ORM\Column(type="simple_array", nullable=false)
*/
private $role;
/**
* @ORM\Column(type="string", length=255)
*/
private string $fullName;
/**
* @ORM\Column(type="boolean", length=255, nullable=true)
*/
private bool $resetPasswordEmail;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private bool $isColor;
public function __construct()
{
$this->isColor = false;
}
public function getId(): ?int
{
return $this->id;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $companyId): void
{
$this->company = $companyId;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password)
{
$this->password = $password;
}
/**
* {@inheritdoc}
*/
public function getRoles(): array
{
return array_merge($this->role, ['ROLE_USER']);
}
/**
* {@inheritdoc}
*/
public function getSalt()
{
return null;
}
/**
* {@inheritdoc}
*/
public function getUsername(): string
{
return $this->email;
}
/**
* {@inheritdoc}
*/
public function eraseCredentials()
{
}
public function addRole(string $role)
{
$this->role[] = $role;
}
public function setRole(array $role): void
{
$this->role = $role;
}
public function setFullName(string $fullName): void
{
$this->fullName = $fullName;
}
public function getFullName(): string
{
return $this->fullName;
}
public function setResetPasswordEmail(bool $resetPasswordEmail)
{
$this->resetPasswordEmail = $resetPasswordEmail;
}
public function getResetPasswordEmail(): bool
{
return $this->resetPasswordEmail;
}
public function setIsColor(bool $isColor)
{
$this->isColor = $isColor;
}
public function getIsColor(): bool
{
return $this->isColor;
}
public function __toString()
{
return $this->fullName;
}
/** @see \Serializable::serialize() */
public function serialize()
{
return serialize([
$this->id,
$this->email,
$this->password,
(string) $this->company,
]);
}
/** @see \Serializable::unserialize() */
public function unserialize($serialized)
{
[$this->id, $this->email, $this->password, $this->company] = unserialize($serialized, ['allowed_classes' => [__CLASS__]]);
}
public function isManager(): bool
{
return \in_array('ROLE_CFC_MANAGER', $this->getRoles(), true);
}
public function isClient(): bool
{
return \in_array('ROLE_CLIENT', $this->getRoles(), true);
}
public function isCleaner(): bool
{
return \in_array('ROLE_CFC_CLEANER_WORKER', $this->getRoles(), true);
}
}