<?php
namespace App\Entity;
use App\Repository\CustomerCertificatesRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=CustomerCertificatesRepository::class)
*/
class CustomerCertificates
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"customer.manage.base", "customer.certificate.manage"})
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Customer::class, inversedBy="customerCertificates")
*/
private $customer;
/**
* @ORM\ManyToOne(targetEntity=Certificates::class, inversedBy="customerCertificates")
* @Groups({"customer.manage.base", "customer.certificate.manage"})
*/
private $certificate;
/**
* @ORM\Column(type="datetime_immutable")
*/
private $created_at;
/**
* @ORM\OneToMany(targetEntity=CustomerCertificateHistories::class, mappedBy="customer_certificate", cascade={"persist", "remove"}, fetch="EXTRA_LAZY")
* @ORM\OrderBy({"valid_from_at": "DESC"})
* @Groups({"customer.manage.base", "customer.certificate.manage"})
*/
private $customer_certificate_histories;
// private $customerCertificateLastHistory;
public function __construct()
{
$this->customer_certificate_histories = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCustomer(): ?Customer
{
return $this->customer;
}
public function setCustomer(?Customer $customer): self
{
$this->customer = $customer;
return $this;
}
public function getCertificate(): ?Certificates
{
return $this->certificate;
}
public function setCertificate(?Certificates $certificate): self
{
$this->certificate = $certificate;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeImmutable $created_at): self
{
$this->created_at = $created_at;
return $this;
}
/**
* @return Collection<int, CustomerCertificateHistories>
*/
public function getCustomerCertificatehistories(): Collection
{
return $this->customer_certificate_histories;
return $this->customer_certificate_histories->map( function( /**@var $customerCertificateHistory CustomerCertificateHistories*/ $customerCertificateHistory ){
return [
'id' => $customerCertificateHistory->getId(),
'createdAt' => $customerCertificateHistory->getCreatedAt(),
'customerCertificateDocuments' => $customerCertificateHistory->getCustomerCertificatedocuments()
];
});
}
// public function getCustomerCertificateLastHistory(): ?CustomerCertificateHistories {
// if( $this->customerCertificateHistories->first() instanceof CustomerCertificateHistories ){
// $this->customerCertificateLastHistory = $this->customerCertificateHistories->first();
// return $this->customerCertificateLastHistory;
// }
// return null;
// }
public function addCustomerCertificateHistory(CustomerCertificateHistories $customerCertificateHistory): self
{
if (!$this->customer_certificate_histories->contains($customerCertificateHistory)) {
$this->customer_certificate_histories[] = $customerCertificateHistory;
$customerCertificateHistory->setCustomerCertificate($this);
}
return $this;
}
public function removeCustomerCertificateHistory(CustomerCertificateHistories $customerCertificateHistory): self
{
if ($this->customer_certificate_histories->removeElement($customerCertificateHistory)) {
// set the owning side to null (unless already changed)
if ($customerCertificateHistory->getCustomerCertificate() === $this) {
$customerCertificateHistory->setCustomerCertificate(null);
}
}
return $this;
}
}