<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\ModuleLicenseRepository;
use App\Enums\ModuleLicenseType;
#[ORM\Table('module_license')]
#[ORM\Entity(ModuleLicenseRepository::class)]
class ModuleLicense implements \JsonSerializable
{
#[ORM\Column('id', 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue('IDENTITY')]
private ?int $id;
#[ORM\ManyToOne(Customer::class, inversedBy: 'moduleLicense')]
#[ORM\JoinColumn('customer')]
private Customer $customer;
#[ORM\ManyToOne(Module::class)]
#[ORM\JoinColumn('module')]
private ?Module $module;
#[ORM\Column('type', 'string', enumType: ModuleLicenseType::class, nullable: true)]
private ?ModuleLicenseType $type = null;
#[ORM\Column('license_date_limit', 'datetime_immutable', nullable: true)]
private ?\DateTimeImmutable $dateLimit = null;
#[ORM\Column('active', 'boolean')]
private bool $active = false;
public function __construct(Customer $customer)
{
$this->customer = $customer;
}
public function getId(): ?int
{
return $this->id;
}
public function setId(int $id): ModuleLicense
{
$this->id = $id;
return $this;
}
public function getCustomer(): Customer
{
return $this->customer;
}
public function setCustomer(Customer $customer): ModuleLicense
{
$this->customer = $customer;
return $this;
}
public function getDateLimit(): ?\DateTimeImmutable
{
return $this->dateLimit;
}
public function setDateLimit(?\DateTimeImmutable $dateLimit): ModuleLicense
{
if ($dateLimit) {
$dateLimit->setTime(23, 59, 59);
}
$this->dateLimit = $dateLimit;
return $this;
}
public function getModule(): ?Module
{
return $this->module;
}
public function setModule(?Module $module): ModuleLicense
{
$this->module = $module;
return $this;
}
public function getType(): ?ModuleLicenseType
{
return $this->type;
}
public function setType(?ModuleLicenseType $type): ModuleLicense
{
$this->type = $type;
return $this;
}
public function isActive(): bool
{
return $this->active;
}
public function setActive(bool $active): ModuleLicense
{
$this->active = $active;
return $this;
}
public function jsonSerialize(): array
{
return [
'id' => $this->getModule()->getId(),
'title' => $this->getModule()->getTitle(),
'systemName' => $this->getModule()->getSystemName(),
'dateLimit' => $this->getDateLimit()?->format('Y-m-d'),
'customer' => $this->getCustomer(),
'module' => $this->getModule(),
'active' => $this->isActive(),
'type' => $this->getType()?->value,
];
}
}