src/Entity/BatchResult.php line 19

  1. <?php
  2. namespace App\Entity;
  3. use DateTimeImmutable;
  4. use App\Enum\BatchResultType;
  5. use App\Repository\BatchResultRepository;
  6. use Symfony\Component\HttpFoundation\File\File;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Gedmo\Timestampable\Traits\TimestampableEntity;
  12. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  13. use Symfony\Component\HttpFoundation\File\UploadedFile;
  14. #[ORM\Entity(repositoryClassBatchResultRepository::class)]
  15. #[Vich\Uploadable]
  16. class BatchResult
  17. {
  18.     use TimestampableEntity;
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue]
  21.     #[ORM\Column]
  22.     private ?int $id null;
  23.     #[ORM\Column(length255)]
  24.     private ?BatchResultType $type null;
  25.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  26.     private ?string $content null;
  27.     #[ORM\OneToMany(mappedBy'batchResult'targetEntityBatchResultItem::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  28.     private Collection $batchResultItems;
  29.     #[ORM\Column(type'string'length255nullabletrue)]
  30.     private $file;
  31.     #[Vich\UploadableField(mapping"batch_result"fileNameProperty"file")]
  32.     private $uploadedFile;
  33.     public function __construct()
  34.     {
  35.         $this->batchResultItems = new ArrayCollection();
  36.     }
  37.     public function getId(): ?int
  38.     {
  39.         return $this->id;
  40.     }
  41.     public function getType(): ?BatchResultType
  42.     {
  43.         return $this->type;
  44.     }
  45.     public function setType(BatchResultType $type): static
  46.     {
  47.         $this->type $type;
  48.         return $this;
  49.     }
  50.     public function getContent(): ?string
  51.     {
  52.         return $this->content;
  53.     }
  54.     public function setContent(?string $content): static
  55.     {
  56.         $this->content $content;
  57.         return $this;
  58.     }
  59.     /**
  60.      * @return Collection<int, BatchResultItem>
  61.      */
  62.     public function getBatchResultItems(): Collection
  63.     {
  64.         return $this->batchResultItems;
  65.     }
  66.     public function addBatchResultItem(BatchResultItem $batchResultItem): static
  67.     {
  68.         if (!$this->batchResultItems->contains($batchResultItem)) {
  69.             $this->batchResultItems->add($batchResultItem);
  70.             $batchResultItem->setBatchResult($this);
  71.         }
  72.         return $this;
  73.     }
  74.     public function removeBatchResultItem(BatchResultItem $batchResultItem): static
  75.     {
  76.         if ($this->batchResultItems->removeElement($batchResultItem)) {
  77.             // set the owning side to null (unless already changed)
  78.             if ($batchResultItem->getBatchResult() === $this) {
  79.                 $batchResultItem->setBatchResult(null);
  80.             }
  81.         }
  82.         return $this;
  83.     }
  84.     public function getFile(): ?string
  85.     {
  86.         return $this->file;
  87.     }
  88.     public function setFile(?string $file): self
  89.     {
  90.         $this->file $file;
  91.         return $this;
  92.     }
  93.     /**
  94.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  95.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  96.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  97.      * must be able to accept an instance of 'File' as the bundle will inject one here
  98.      * during Doctrine hydration.
  99.      *
  100.      * @param File|UploadedFile|null $uploadedFile
  101.      */
  102.     public function setUploadedFile(?File $uploadedFile null): void
  103.     {
  104.         $this->uploadedFile $uploadedFile;
  105.         if (null !== $uploadedFile) {
  106.             // It is required that at least one field changes if you are using doctrine
  107.             // otherwise the event listeners won't be called and the file is lost
  108.             $this->updatedAt = new DateTimeImmutable();
  109.         }
  110.     }
  111.     /**
  112.      * @return File|null
  113.      */
  114.     public function getUploadedFile(): ?File
  115.     {
  116.         return $this->uploadedFile;
  117.     }
  118. }