src/Infrastructure/Persistence/Doctrine/Entity/User.php line 15

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Infrastructure\Persistence\Doctrine\Entity;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. /**
  8.  * @ORM\Entity
  9.  * @UniqueEntity(fields={"email"}, errorPath="email", message="Emailadres is al in gebruik.")
  10.  */
  11. class User implements UserInterface\Serializable
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\ManyToOne(targetEntity="Infrastructure\Persistence\Doctrine\Entity\Company", cascade={"persist"})
  21.      * @ORM\JoinColumn(onDelete="SET NULL")
  22.      */
  23.     private $company;
  24.     /**
  25.      * @ORM\Column(type="string", length=255, unique=true)
  26.      */
  27.     private $email;
  28.     /**
  29.      * @ORM\Column(type="string", length=255, nullable=true)
  30.      */
  31.     private $password;
  32.     /**
  33.      * @ORM\Column(type="simple_array", nullable=false)
  34.      */
  35.     private $role;
  36.     /**
  37.      * @ORM\Column(type="string", length=255)
  38.      */
  39.     private string $fullName;
  40.     /**
  41.      * @ORM\Column(type="boolean", length=255, nullable=true)
  42.      */
  43.     private bool $resetPasswordEmail;
  44.     /**
  45.      * @ORM\Column(type="boolean", nullable=true)
  46.      */
  47.     private bool $isColor;
  48.     public function __construct()
  49.     {
  50.         $this->isColor false;
  51.     }
  52.     public function getId(): ?int
  53.     {
  54.         return $this->id;
  55.     }
  56.     public function getCompany(): ?Company
  57.     {
  58.         return $this->company;
  59.     }
  60.     public function setCompany(?Company $companyId): void
  61.     {
  62.         $this->company $companyId;
  63.     }
  64.     public function getEmail(): ?string
  65.     {
  66.         return $this->email;
  67.     }
  68.     public function setEmail(string $email): self
  69.     {
  70.         $this->email $email;
  71.         return $this;
  72.     }
  73.     public function getPassword(): ?string
  74.     {
  75.         return $this->password;
  76.     }
  77.     public function setPassword(string $password)
  78.     {
  79.         $this->password $password;
  80.     }
  81.     /**
  82.      * {@inheritdoc}
  83.      */
  84.     public function getRoles(): array
  85.     {
  86.         return array_merge($this->role, ['ROLE_USER']);
  87.     }
  88.     /**
  89.      * {@inheritdoc}
  90.      */
  91.     public function getSalt()
  92.     {
  93.         return null;
  94.     }
  95.     /**
  96.      * {@inheritdoc}
  97.      */
  98.     public function getUsername(): string
  99.     {
  100.         return $this->email;
  101.     }
  102.     /**
  103.      * {@inheritdoc}
  104.      */
  105.     public function eraseCredentials()
  106.     {
  107.     }
  108.     public function addRole(string $role)
  109.     {
  110.         $this->role[] = $role;
  111.     }
  112.     public function setRole(array $role): void
  113.     {
  114.         $this->role $role;
  115.     }
  116.     public function setFullName(string $fullName): void
  117.     {
  118.         $this->fullName $fullName;
  119.     }
  120.     public function getFullName(): string
  121.     {
  122.         return $this->fullName;
  123.     }
  124.     public function setResetPasswordEmail(bool $resetPasswordEmail)
  125.     {
  126.         $this->resetPasswordEmail $resetPasswordEmail;
  127.     }
  128.     public function getResetPasswordEmail(): bool
  129.     {
  130.         return $this->resetPasswordEmail;
  131.     }
  132.     public function setIsColor(bool $isColor)
  133.     {
  134.         $this->isColor $isColor;
  135.     }
  136.     public function getIsColor(): bool
  137.     {
  138.         return $this->isColor;
  139.     }
  140.     public function __toString()
  141.     {
  142.         return $this->fullName;
  143.     }
  144.     /** @see \Serializable::serialize() */
  145.     public function serialize()
  146.     {
  147.         return serialize([
  148.             $this->id,
  149.             $this->email,
  150.             $this->password,
  151.             (string) $this->company,
  152.         ]);
  153.     }
  154.     /** @see \Serializable::unserialize() */
  155.     public function unserialize($serialized)
  156.     {
  157.         [$this->id$this->email$this->password$this->company] = unserialize($serialized, ['allowed_classes' => [__CLASS__]]);
  158.     }
  159.     public function isManager(): bool
  160.     {
  161.         return \in_array('ROLE_CFC_MANAGER'$this->getRoles(), true);
  162.     }
  163.     public function isClient(): bool
  164.     {
  165.         return \in_array('ROLE_CLIENT'$this->getRoles(), true);
  166.     }
  167.     public function isCleaner(): bool
  168.     {
  169.         return \in_array('ROLE_CFC_CLEANER_WORKER'$this->getRoles(), true);
  170.     }
  171. }