src/Entity/ImageManager.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ImageManagerRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Symfony\Component\HttpFoundation\File\UploadedFile;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. /**
  13.  * @ORM\Entity(repositoryClass=ImageManagerRepository::class)
  14.  * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=true)
  15.  * @Vich\Uploadable
  16.  */
  17. class ImageManager
  18. {
  19.     use SoftDeleteableEntity;
  20.     /**
  21.      * @ORM\Id
  22.      * @ORM\GeneratedValue
  23.      * @ORM\Column(type="integer")
  24.      */
  25.     private $id;
  26.     /**
  27.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  28.      *
  29.      * @Vich\UploadableField(mapping="image_file", fileNameProperty="fileName", size="fileSize")
  30.      * 
  31.      * @var File|null
  32.      */
  33.     private $file;
  34.     /**
  35.      * @ORM\Column(type="string", length=255, nullable=true)
  36.      */
  37.     private $fileName;
  38.     /**
  39.      * @ORM\Column(type="integer", nullable=true)
  40.      */
  41.     private $fileSize;
  42.     /**
  43.      * @ORM\Column(type="datetime", nullable=true)
  44.      */
  45.     private $updatedAt;
  46.     public function getId(): ?int
  47.     {
  48.         return $this->id;
  49.     }
  50.     /**
  51.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  52.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  53.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  54.      * must be able to accept an instance of 'File' as the bundle will inject one here
  55.      * during Doctrine hydration.
  56.      *
  57.      * @param File|null $file
  58.      * @throws \Exception
  59.      */
  60.     public function setFile(?File $file null): void
  61.     {
  62.         $this->file $file;
  63.         if ($file) {
  64.             $this->updatedAt = new \DateTime('now');
  65.         }
  66.     }
  67.     public function getFile(): ?File
  68.     {
  69.         return $this->file;
  70.     }
  71.     public function getFileName(): ?string
  72.     {
  73.         return $this->fileName;
  74.     }
  75.     public function setFileName(?string $fileName): self
  76.     {
  77.         $this->fileName $fileName;
  78.         return $this;
  79.     }
  80.     public function getFileSize(): ?int
  81.     {
  82.         return $this->fileSize;
  83.     }
  84.     public function setFileSize(?int $fileSize): self
  85.     {
  86.         $this->fileSize $fileSize;
  87.         return $this;
  88.     }
  89.     public function getUpdatedAt(): ?\DateTimeInterface
  90.     {
  91.         return $this->updatedAt;
  92.     }
  93.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  94.     {
  95.         $this->updatedAt $updatedAt;
  96.         return $this;
  97.     }
  98.     public function resetId(): void
  99.     {
  100.         $this->id null;
  101.     }
  102. }