<?phpnamespace App\Entity;use App\Entity\Traits\Identifiable;use App\Repository\DocumentRepository;use DateTime;use DateTimeImmutable;use Doctrine\ORM\Mapping as ORM;#[ORM\Entity(repositoryClass: DocumentRepository::class)]class Document{ use Identifiable; #[ORM\Column(type: 'date_immutable', nullable: true)] private $validityDate; #[ORM\ManyToOne(targetEntity: DocumentModel::class, inversedBy: 'documents')] #[ORM\JoinColumn(nullable: false)] private $model; #[ORM\OneToOne(targetEntity: File::class, cascade: ['persist', 'remove'])]// #[ORM\JoinColumn(nullable: false)] private $file; //TODO: rétablire nullable = false #[ORM\ManyToOne(targetEntity: Registration::class, inversedBy: 'documents')] private $registration; #[ORM\OneToOne(mappedBy: 'document', targetEntity: Discount::class, cascade: ['persist', 'remove'])] private $discount; #[ORM\Column(type: 'boolean', nullable: true)] private $isValid; public function getValidityDate(): ?DateTimeImmutable { return $this->validityDate; } public function setValidityDate(?DateTimeImmutable $validityDate): self { $this->validityDate = $validityDate; return $this; } public function isExpired(): ?bool { if ($this->getValidityDate()) { return $this->getValidityDate() > new DateTime(); } return null; } public function getModel(): ?DocumentModel { return $this->model; } public function setModel(?DocumentModel $model): self { $this->model = $model; return $this; } public function getFile(): ?File { return $this->file; } public function setFile(File $file): self { $this->file = $file; return $this; } public function getRegistration(): ?Registration { return $this->registration; } public function setRegistration(?Registration $registration): self { $this->registration = $registration; return $this; } public function getDiscount(): ?Discount { return $this->discount; } public function setDiscount(?Discount $discount): self { // unset the owning side of the relation if necessary if ($discount === null && $this->discount !== null) { $this->discount->setDocument(null); } // set the owning side of the relation if necessary if ($discount !== null && $discount->getDocument() !== $this) { $discount->setDocument($this); } $this->discount = $discount; return $this; } public function getIsValid(): ?bool { if ($this->isValid === true) { $now = new DateTime(); if ($this->getValidityDate() === null || $this->getValidityDate() > $now) { return true; } } return $this->isValid; } public function setIsValid(?bool $isValid): self { $this->isValid = $isValid; return $this; } public function __clone() { $this->id = null; $this->uuid = null; $this->registration = null; $this->discount = null; $this->validityDate = null; $this->model = null; $this->isValid = null; $this->file = null; }}