<?php
namespace App\Entity;
use App\Service\Helper\DateTimeHelper;
use App\Service\Helper\Generator;
use App\Service\Helper\PhoneHelper;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Exception;
/**
* @ORM\Entity(repositoryClass="App\Repository\CustomerRepository")
* @ORM\Table(name="customers__customers",
* indexes={
* @ORM\Index(name="phone_idx", columns={"phone"}),
* @ORM\Index(name="email_idx", columns={"email"}),
* })
*/
class Customer
{
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", onDelete="SET NULL", nullable=true)
**/
private ?User $user = null;
/**
* @ORM\Column(name="phone", type="string", unique=true)
*/
private string $phone;
/**
* @ORM\Column(name="first_name", type="string", nullable=true)
*/
private ?string $firstName = null;
/**
* @ORM\Column(name="sure_name", type="string", nullable=true)
*/
private ?string $sureName = null;
/**
* @ORM\Column(name="father_name", type="string", nullable=true)
*/
private ?string $fatherName = null;
/**
* @ORM\Column(name="farpost_login", type="string", nullable=true)
*/
private ?string $farpostLogin = null;
/**
* @ORM\Column(name="email", type="string", nullable=true)
*/
private ?string $email = null;
/**
* @ORM\Column(name="mango_contact_id", type="string", nullable=true)
*/
private ?string $mangoContactId = null;
/**
* @var ArrayCollection|CustomerGarage[]
* @ORM\OneToMany(targetEntity="CustomerGarage", mappedBy="customer")
*/
private $garages;
/**
* @throws Exception
*/
public function __construct(string $phone)
{
$this->phone = PhoneHelper::getNormalizePhone($phone);
$this->createdAt = DateTimeHelper::getNowDateTime();
}
/**
* @return User
*/
public function getUser()
{
return $this->user;
}
/**
* @param User $user
* @return Customer
*/
public function setUser($user)
{
$this->user = $user;
return $this;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(?string $firstName): Customer
{
$this->firstName = $firstName;
return $this;
}
public function getSureName(): ?string
{
return $this->sureName;
}
public function setSureName(?string $sureName): Customer
{
$this->sureName = $sureName;
return $this;
}
public function getFatherName(): ?string
{
return $this->fatherName;
}
public function setFatherName(?string $fatherName): Customer
{
$this->fatherName = $fatherName;
return $this;
}
public function getMangoContactId(): ?string
{
return $this->mangoContactId;
}
public function setMangoContactId(?string $mangoContactId): Customer
{
$this->mangoContactId = $mangoContactId;
return $this;
}
/**
* @return CustomerGarage[]
*/
public function getGarages()
{
return $this->garages;
}
/**
* @return string
*/
public function getFullName()
{
$fullName = $this->sureName;
$fullName .= $this->firstName ? ($fullName ? ' ' : null) . $this->firstName : null;
$fullName .= $this->fatherName ? ($fullName ? ' ' : null) . $this->fatherName : null;
if($fullName) return $fullName;
return '';
}
/**
* @return string
*/
public function getShortName()
{
$fullName = $this->getSureName();
$fullName .= $this->getFirstName() ? ($fullName ? ' ' : null) . mb_substr($this->getFirstName(), 0, 1) . '.' : null;
$fullName .= $this->getFatherName() ? ($fullName ? ' ' : null) . mb_substr($this->getFatherName(), 0, 1) . '.' : null;
if($fullName) return $fullName;
return '';
}
}