<?php
namespace App\Entity;
use App\Repository\WorkerCertificatesRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=WorkerCertificatesRepository::class)
* @ORM\HasLifecycleCallbacks
*/
class WorkerCertificates
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"worker.manage.base", "worker.certificate.manage"})
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Worker::class, inversedBy="workerCertificates")
* @ORM\JoinColumn(nullable=true, onDelete="CASCADE")
*/
private $worker;
/**
* @ORM\ManyToOne(targetEntity=Certificates::class, inversedBy="workerCertificates")
* @ORM\JoinColumn(nullable=false)
* @Groups({"worker.manage.base", "worker.certificate.manage"})
*/
private $certificate;
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
*/
private $created_at;
/**
* @ORM\OneToMany(targetEntity=WorkerCertificateHistories::class, mappedBy="worker_certificate", cascade={"persist", "remove"}, orphanRemoval=true, fetch="EXTRA_LAZY")
* @ORM\OrderBy({"valid_from_at"="DESC"})
* @Groups({"worker.manage.base"})
*/
private $worker_certificate_histories;
// private $workerCertificateLastHistory;
public function __construct()
{
$this->worker_certificate_histories = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getWorker(): ?Worker
{
return $this->worker;
}
public function setWorker(?Worker $worker): self
{
$this->worker = $worker;
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, WorkerCertificateHistories>
*/
public function getWorkerCertificateHistories(): ?Collection
{
return $this->worker_certificate_histories;
}
public function addWorkerCertificateHistory(WorkerCertificateHistories $workerCertificateHistory): self
{
if (!$this->worker_certificate_histories->contains($workerCertificateHistory)) {
$this->worker_certificate_histories[] = $workerCertificateHistory;
$workerCertificateHistory->setWorkerCertificate($this);
}
return $this;
}
public function removeWorkerCertificateHistory(WorkerCertificateHistories $workerCertificateHistory): self
{
if ($this->worker_certificate_histories->removeElement($workerCertificateHistory)) {
// set the owning side to null (unless already changed)
if ($workerCertificateHistory->getWorkerCertificate() === $this) {
$workerCertificateHistory->setWorkerCertificate(null);
}
}
return $this;
}
}