src/Entity/CustomerCertificates.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CustomerCertificatesRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. /**
  9.  * @ORM\Entity(repositoryClass=CustomerCertificatesRepository::class)
  10.  */
  11. class CustomerCertificates
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      * @Groups({"customer.manage.base", "customer.certificate.manage"})
  18.      */
  19.     private $id;
  20.     /**
  21.      * @ORM\ManyToOne(targetEntity=Customer::class, inversedBy="customerCertificates")
  22.      */
  23.     private $customer;
  24.     /**
  25.      * @ORM\ManyToOne(targetEntity=Certificates::class, inversedBy="customerCertificates")
  26.      * @Groups({"customer.manage.base", "customer.certificate.manage"})
  27.      */
  28.     private $certificate;
  29.     /**
  30.      * @ORM\Column(type="datetime_immutable")
  31.      */
  32.     private $created_at;
  33.     /**
  34.      * @ORM\OneToMany(targetEntity=CustomerCertificateHistories::class, mappedBy="customer_certificate", cascade={"persist", "remove"}, fetch="EXTRA_LAZY")
  35.      * @ORM\OrderBy({"valid_from_at": "DESC"})
  36.      * @Groups({"customer.manage.base", "customer.certificate.manage"})
  37.      */
  38.     private $customer_certificate_histories;
  39.     // private $customerCertificateLastHistory;
  40.     public function __construct()
  41.     {
  42.         $this->customer_certificate_histories = new ArrayCollection();
  43.     }
  44.     public function getId(): ?int
  45.     {
  46.         return $this->id;
  47.     }
  48.     public function getCustomer(): ?Customer
  49.     {
  50.         return $this->customer;
  51.     }
  52.     public function setCustomer(?Customer $customer): self
  53.     {
  54.         $this->customer $customer;
  55.         return $this;
  56.     }
  57.     public function getCertificate(): ?Certificates
  58.     {
  59.         return $this->certificate;
  60.     }
  61.     public function setCertificate(?Certificates $certificate): self
  62.     {
  63.         $this->certificate $certificate;
  64.         return $this;
  65.     }
  66.     public function getCreatedAt(): ?\DateTimeImmutable
  67.     {
  68.         return $this->created_at;
  69.     }
  70.     public function setCreatedAt(\DateTimeImmutable $created_at): self
  71.     {
  72.         $this->created_at $created_at;
  73.         return $this;
  74.     }
  75.     /**
  76.      * @return Collection<int, CustomerCertificateHistories>
  77.      */
  78.     public function getCustomerCertificatehistories(): Collection
  79.     {
  80.         return $this->customer_certificate_histories;
  81.         return $this->customer_certificate_histories->map( function( /**@var $customerCertificateHistory CustomerCertificateHistories*/ $customerCertificateHistory ){
  82.             return [
  83.                 'id' => $customerCertificateHistory->getId(),
  84.                 'createdAt' => $customerCertificateHistory->getCreatedAt(),
  85.                 'customerCertificateDocuments' => $customerCertificateHistory->getCustomerCertificatedocuments()
  86.             ];
  87.         });
  88.     }
  89.     // public function getCustomerCertificateLastHistory(): ?CustomerCertificateHistories  {
  90.     //    if( $this->customerCertificateHistories->first() instanceof CustomerCertificateHistories ){
  91.     //        $this->customerCertificateLastHistory = $this->customerCertificateHistories->first();
  92.     //        return $this->customerCertificateLastHistory;
  93.     //    }
  94.     //    return null;
  95.     // }
  96.     public function addCustomerCertificateHistory(CustomerCertificateHistories $customerCertificateHistory): self
  97.     {
  98.         if (!$this->customer_certificate_histories->contains($customerCertificateHistory)) {
  99.             $this->customer_certificate_histories[] = $customerCertificateHistory;
  100.             $customerCertificateHistory->setCustomerCertificate($this);
  101.         }
  102.         return $this;
  103.     }
  104.     public function removeCustomerCertificateHistory(CustomerCertificateHistories $customerCertificateHistory): self
  105.     {
  106.         if ($this->customer_certificate_histories->removeElement($customerCertificateHistory)) {
  107.             // set the owning side to null (unless already changed)
  108.             if ($customerCertificateHistory->getCustomerCertificate() === $this) {
  109.                 $customerCertificateHistory->setCustomerCertificate(null);
  110.             }
  111.         }
  112.         return $this;
  113.     }
  114. }