<?php
namespace App\Entity;
use DateTime;
use App\Entity\Enum\BusinessModelEnum;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* Fichier
*
* @ORM\Table(name="administrator")
* @ORM\Entity(repositoryClass="App\Repository\AdministratorRepository")
*
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorMap(
* {
* "freelancer" = "App\Entity\Freelancer",
* "partner" = "App\Entity\Partner",
* })
*/
abstract class Administrator
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\OneToOne(targetEntity="App\Entity\User", inversedBy="administrator", cascade={"persist", "remove"})
*/
private $user;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Store", mappedBy="administrator")
*/
private $stores;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $dailyCapping;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $monthlyCapping;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $leadCost;
/**
* @var boolean
* @ORM\Column(type="boolean", options={"default" : false})
*/
private $isCustomer;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $numberOfLeadMonthly;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Gedmo\Timestampable(on="create")
*/
private ?DateTime $registrationDate = null;
/**
* @ORM\Column(type="integer", nullable=true)
*/
protected ?int $businessModel = null;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private ?DateTime $businessModelSince;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected ?DateTime $businessModelDeadline = null;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private ?int $ageCapping;
public function __construct()
{
$this->stores = new ArrayCollection();
$this->isCustomer = false;
}
/**
* Représente l'entité par défault
* @return string
*/
public function __toString()
{
return 'Administrator ' . $this->getName() . ' [' . $this->getId() . ']';
}
/**
* Représente l'entité dans le BO
* @return string
*/
public function getLabel()
{
return $this->getName();
}
/**
* Représente l'entité par son nom et son type (admin ou freelance)
* @return string
*/
public function getLabelWithType()
{
return $this->getName() . ' [Administrateur]';
}
public function getId(): ?int
{
return $this->id;
}
public function getNameAndEmailUser()
{
if ($this->isFreelancer() === true && $this->getUser() !== null) {
return $this->getNameAndEmailUser();
} else {
return $this->getName() . ' [Partenaire]';
}
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
/**
* @return Collection|Store[]
*/
public function getStores(): Collection
{
return $this->stores;
}
public function addStore(Store $store): self
{
if (!$this->stores->contains($store)) {
$this->stores[] = $store;
$store->setAdministrator($this);
}
return $this;
}
public function removeStore(Store $store): self
{
if ($this->stores->contains($store)) {
$this->stores->removeElement($store);
// set the owning side to null (unless already changed)
if ($store->getAdministrator() === $this) {
$store->setAdministrator(null);
}
}
return $this;
}
/**
* Does this admin ca buy credit.
* he can if he is NOT "perf" business model
* @return bool
*/
public function canBuyCredit(): bool
{
return $this->getBusinessModel() !== BusinessModelEnum::PERFORMANCE;
}
/**
* Indicate if the administrator (freelance or parnter is a customer of MCA)
* @return bool|null
*/
public function isCustomer(): ?bool
{
return $this->isCustomer;
}
public function getDailyCapping(): ?int
{
return $this->dailyCapping;
}
public function setDailyCapping(int $dailyCapping): self
{
$this->dailyCapping = $dailyCapping;
return $this;
}
public function getMonthlyCapping(): ?int
{
return $this->monthlyCapping;
}
public function setMonthlyCapping(int $monthlyCapping): self
{
$this->monthlyCapping = $monthlyCapping;
return $this;
}
public function getLeadCost(): ?float
{
return $this->leadCost;
}
public function setLeadCost(float $leadCost): self
{
$this->leadCost = $leadCost;
return $this;
}
/**
* Est-ce que cet Administrateur est un partenaire
* @return bool
*/
public function isPartner()
{
return $this instanceof Partner;
}
/**
* Est-ce que cet Administrateur est un freelance
* @return bool
*/
public function isFreelancer()
{
return $this instanceof Freelancer;
}
/**
* @return bool|null
* @deprecated use IsCustomer instead
*/
public function getIsCustomer(): bool
{
return $this->isCustomer;
}
public function setIsCustomer(bool $isCustomer): self
{
$this->isCustomer = $isCustomer;
return $this;
}
public function getNumberOfLeadMonthly(): ?int
{
return $this->numberOfLeadMonthly;
}
public function setNumberOfLeadMonthly(?int $numberOfLeadMonthly): self
{
$this->numberOfLeadMonthly = $numberOfLeadMonthly;
return $this;
}
public function getRegistrationDate(): ?DateTime
{
return $this->registrationDate;
}
public function setRegistrationDate(?DateTime $registrationDate): void
{
$this->registrationDate = $registrationDate;
}
public function getBusinessModel(): ?int
{
return $this->businessModel;
}
public function hasBusinessModel(): bool
{
return $this->businessModel !== BusinessModelEnum::NONE;
}
public function getBusinessModelLabel(): string
{
return 'business_model.' . $this->businessModel;
}
public function getBusinessModelName(): string
{
return BusinessModelEnum::toString($this->businessModel);
}
public function setBusinessModel(int $businessModel): void
{
if ($this->businessModel !== $businessModel) {
$this->setBusinessModelSince(new DateTime());
}
$this->businessModel = $businessModel;
}
public function isPayAsYouGo(): ?bool
{
return $this->businessModel === BusinessModelEnum::PAY_AS_YOU_GO;
}
public function isCredit(): ?bool
{
return $this->businessModel === BusinessModelEnum::CREDIT;
}
public function isPerformance(): ?bool
{
return $this->businessModel === BusinessModelEnum::PERFORMANCE;
}
public function getBusinessModelSince(): ?DateTimeInterface
{
return $this->businessModelSince;
}
public function setBusinessModelSince(?DateTimeInterface $businessModelSince): self
{
$this->businessModelSince = $businessModelSince;
return $this;
}
public function getBusinessModelDeadline(): ?DateTime
{
return $this->businessModelDeadline;
}
public function setBusinessModelDeadline(?DateTime $businessModelDeadline): void
{
$this->businessModelDeadline = $businessModelDeadline;
}
public function hasBusinessModelDeadline(): bool
{
return $this->businessModelDeadline !== null;
}
public function hasFakeBusinessModelDeadline(): bool
{
//compare businessModelDeadline with BUSINESS_MODEL_FAKE_DEADLINE
return $this->businessModelDeadline && $this->businessModelDeadline->format('Y-m-d H:i:s') === Freelancer::BUSINESS_MODEL_FAKE_DEADLINE;
}
public function getAgeCapping(): ?int
{
return $this->ageCapping;
}
public function setAgeCapping(?int $ageCapping): void
{
$this->ageCapping = $ageCapping;
}
}