src/Entity/Document.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\Identifiable;
  4. use App\Repository\DocumentRepository;
  5. use DateTime;
  6. use DateTimeImmutable;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassDocumentRepository::class)]
  9. class Document
  10. {
  11.     use Identifiable;
  12.     #[ORM\Column(type'date_immutable'nullabletrue)]
  13.     private $validityDate;
  14.     #[ORM\ManyToOne(targetEntityDocumentModel::class, inversedBy'documents')]
  15.     #[ORM\JoinColumn(nullablefalse)]
  16.     private $model;
  17.     #[ORM\OneToOne(targetEntityFile::class, cascade: ['persist''remove'])]
  18. //    #[ORM\JoinColumn(nullable: false)]
  19.     private $file;
  20.     //TODO: rĂ©tablire nullable = false
  21.     #[ORM\ManyToOne(targetEntityRegistration::class, inversedBy'documents')]
  22.     private $registration;
  23.     #[ORM\OneToOne(mappedBy'document'targetEntityDiscount::class, cascade: ['persist''remove'])]
  24.     private $discount;
  25.     #[ORM\Column(type'boolean'nullabletrue)]
  26.     private $isValid;
  27.     public function getValidityDate(): ?DateTimeImmutable
  28.     {
  29.         return $this->validityDate;
  30.     }
  31.     public function setValidityDate(?DateTimeImmutable $validityDate): self
  32.     {
  33.         $this->validityDate $validityDate;
  34.         return $this;
  35.     }
  36.     public function isExpired(): ?bool
  37.     {
  38.         if ($this->getValidityDate()) {
  39.             return $this->getValidityDate() > new DateTime();
  40.         }
  41.         return null;
  42.     }
  43.     public function getModel(): ?DocumentModel
  44.     {
  45.         return $this->model;
  46.     }
  47.     public function setModel(?DocumentModel $model): self
  48.     {
  49.         $this->model $model;
  50.         return $this;
  51.     }
  52.     public function getFile(): ?File
  53.     {
  54.         return $this->file;
  55.     }
  56.     public function setFile(File $file): self
  57.     {
  58.         $this->file $file;
  59.         return $this;
  60.     }
  61.     public function getRegistration(): ?Registration
  62.     {
  63.         return $this->registration;
  64.     }
  65.     public function setRegistration(?Registration $registration): self
  66.     {
  67.         $this->registration $registration;
  68.         return $this;
  69.     }
  70.     public function getDiscount(): ?Discount
  71.     {
  72.         return $this->discount;
  73.     }
  74.     public function setDiscount(?Discount $discount): self
  75.     {
  76.         // unset the owning side of the relation if necessary
  77.         if ($discount === null && $this->discount !== null) {
  78.             $this->discount->setDocument(null);
  79.         }
  80.         // set the owning side of the relation if necessary
  81.         if ($discount !== null && $discount->getDocument() !== $this) {
  82.             $discount->setDocument($this);
  83.         }
  84.         $this->discount $discount;
  85.         return $this;
  86.     }
  87.     public function getIsValid(): ?bool
  88.     {
  89.         if ($this->isValid === true) {
  90.             $now = new DateTime();
  91.             if ($this->getValidityDate() === null || $this->getValidityDate() > $now) {
  92.                 return true;
  93.             }
  94.         }
  95.         return $this->isValid;
  96.     }
  97.     public function setIsValid(?bool $isValid): self
  98.     {
  99.         $this->isValid $isValid;
  100.         return $this;
  101.     }
  102.     public function __clone()
  103.     {
  104.         $this->id null;
  105.         $this->uuid null;
  106.         $this->registration null;
  107.         $this->discount null;
  108.         $this->validityDate null;
  109.         $this->model null;
  110.         $this->isValid null;
  111.         $this->file null;
  112.     }
  113. }