<?php
namespace App\Entity\Master;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="eposm_m_license")
* @ORM\Entity(repositoryClass="App\Repository\Master\LicenseRepository")
*/
class License
{
public function getIsActive()
{
$expirationDate = clone($this->getActivationDate());
date_modify($expirationDate, "+1 Years");
$now = new \DateTime();
if($this->isAdminActive && $expirationDate->format("Ymd") > $now->format("Ymd"))
return true;
return false;
}
public function getDisplayFeatures()
{
$result = '<table class="table table-sm b_none"><thead><tr><th class="td_w_300p"><ass="form_label m_b_none">Nome</label></th><th class="td_w_130p txt_a_c"><label class="form_label m_b_none">Data attivazione</label></th><th class="td_w_130p txt_a_c"><label class="form_label m_b_none">Data scadenza</label></th></tr></thead><tbody>';
foreach($this->getFeatures() as $jtlf){
$result.= '<tr><td>'.$jtlf->getFeature()->getName().'</td><td class="txt_a_c">'.$jtlf->getActivationDate()->format('d-m-Y').'</td><td class="txt_a_c">'.$jtlf->getExpirationDate()->format('d-m-Y').'</td></tr>';
}
$result.= '</tbody></table>';
return $result;
}
/**
* @ORM\Column(name="id", type="bigint")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="active", type="boolean")
*/
protected $active = true;
/**
* @ORM\Column(name="activation_date", type="date", nullable=true)
*/
protected $activationDate;
/**
* @ORM\Column(name="expiration_date", type="date", nullable=true)
*/
protected $expirationDate;
/**
* @ORM\Column(name="contract_path", type="string", length=191, nullable=true)
*/
protected $contractPath;
// ManyToOne
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Master\Company", inversedBy="licenses")
* @ORM\JoinColumn(name="company_id", referencedColumnName="id")
*/
private $company;
//
// OneToMany
/**
* @ORM\OneToMany(targetEntity="App\Entity\Master\JoinTableLicenseFeature", mappedBy="license")
*/
private $features;
//
public function __construct()
{
$this->features = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function isActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
public function getActivationDate(): ?\DateTimeInterface
{
return $this->activationDate;
}
public function setActivationDate(?\DateTimeInterface $activationDate): self
{
$this->activationDate = $activationDate;
return $this;
}
public function getExpirationDate(): ?\DateTimeInterface
{
return $this->expirationDate;
}
public function setExpirationDate(?\DateTimeInterface $expirationDate): self
{
$this->expirationDate = $expirationDate;
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
/**
* @return Collection<int, JoinTableLicenseFeature>
*/
public function getFeatures(): Collection
{
return $this->features;
}
public function addFeature(JoinTableLicenseFeature $feature): self
{
if (!$this->features->contains($feature)) {
$this->features->add($feature);
$feature->setLicense($this);
}
return $this;
}
public function removeFeature(JoinTableLicenseFeature $feature): self
{
if ($this->features->removeElement($feature)) {
// set the owning side to null (unless already changed)
if ($feature->getLicense() === $this) {
$feature->setLicense(null);
}
}
return $this;
}
public function getContractPath(): ?string
{
return $this->contractPath;
}
public function setContractPath(?string $contractPath): self
{
$this->contractPath = $contractPath;
return $this;
}
}