<?php
namespace App\Entity;
use App\Service\Helper\DateTimeHelper;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Exception;
/**
* Manager
*
* @ORM\Table(name="managers")
* @ORM\Entity(repositoryClass="App\Repository\ManagerRepository")
*/
class Manager
{
use IdTrait;
/**
* @ORM\Column(name="created_at", type="datetime", nullable=false)
*/
private DateTime $createdAt;
/**
* @ORM\OneToOne(targetEntity="User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
*/
private User $user;
/**
* @ORM\Column(name="visible", type="boolean", options={"default":1})
*/
private bool $visible = true;
/**
* @ORM\Column(name="first_name", type="string", nullable=true)
*/
private ?string $firstName = null;
/**
* @ORM\Column(name="last_name", type="string", nullable=true)
*/
private ?string $lastName = null;
/**
* @ORM\Column(name="father_name", type="string", nullable=true)
*/
private ?string $fatherName = null;
/**
* @ORM\Column(name="mango_extension_number", type="string", nullable=true, unique=true)
*/
private ?string $mangoExtensionNumber = null;
/**
* @throws Exception
*/
public function __construct(User $user)
{
$this->user = $user;
$this->createdAt = DateTimeHelper::getNowDateTime();
}
public function getUser(): User
{
return $this->user;
}
public function setVisible(bool $visible): Manager
{
$this->visible = $visible;
return $this;
}
public function isVisible(): bool
{
return $this->visible;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(?string $firstName): Manager
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(?string $lastName): Manager
{
$this->lastName = $lastName;
return $this;
}
public function getFatherName(): ?string
{
return $this->fatherName;
}
public function setFatherName(?string $fatherName): Manager
{
$this->fatherName = $fatherName;
return $this;
}
public function getFullName(): string
{
$fullName = $this->lastName;
$fullName .= $this->firstName ? ($fullName ? ' ' : null) . $this->firstName : null;
return $fullName;
}
public function getMangoExtensionNumber(): ?string
{
return $this->mangoExtensionNumber;
}
public function setMangoExtensionNumber(?string $mangoExtensionNumber): Manager
{
$this->mangoExtensionNumber = $mangoExtensionNumber;
return $this;
}
public function getShortName(): string
{
return preg_replace('~^(\S++)\s++(\S)\S++\s++(\S)\S++$~u', '$1 $2.', trim($this->getFullName()));
}
}