src/Entity/File.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Serializable;
  5. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  6. use Symfony\Component\HttpFoundation\File\File as Ffile;
  7. /**
  8.  * @ORM\Entity(repositoryClass="App\Repository\FileRepository")
  9.  * @Vich\Uploadable
  10.  */
  11. class File implements Serializable
  12. {
  13.     /**
  14.      * @ORM\Id()
  15.      * @ORM\GeneratedValue()
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  21.      *
  22.      * @Vich\UploadableField(mapping="upload_image", fileNameProperty="imageName", size="imageSize")
  23.      *
  24.      * @var File
  25.      */
  26.     private $file;
  27.     /**
  28.      * @ORM\Column(type="string", length=255)
  29.      *
  30.      * @var string
  31.      */
  32.     private $imageName;
  33.     /**
  34.      * @ORM\Column(type="datetime")
  35.      *
  36.      * @var \DateTime
  37.      */
  38.     private $updatedAt;
  39.     /**
  40.      * @ORM\Column(type="integer")
  41.      *
  42.      * @var integer
  43.      */
  44.     private $imageSize;
  45.     /**
  46.      * @ORM\Column(type="boolean", nullable=true)
  47.      */
  48.     private $isSelected;
  49.     public function getId()
  50.     {
  51.         return $this->id;
  52.     }
  53.     /**
  54.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  55.      * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  56.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  57.      * must be able to accept an instance of 'File' as the bundle will inject one here
  58.      * during Doctrine hydration.
  59.      *
  60.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
  61.      */
  62.     public function setFile(?Ffile $file null): void
  63.     {
  64.         $this->file $file;
  65.         if (null !== $file) {
  66.             // It is required that at least one field changes if you are using doctrine
  67.             // otherwise the event listeners won't be called and the file is lost
  68.             $this->updatedAt = new \DateTimeImmutable();
  69.         }
  70.     }
  71.     public function getFile(): ?Ffile
  72.     {
  73.         return $this->file;
  74.     }
  75.     public function setImageName(?string $imageName): void
  76.     {
  77.         $this->imageName $imageName;
  78.     }
  79.     public function getImageName(): ?string
  80.     {
  81.         return $this->imageName;
  82.     }
  83.     public function setImageSize(?int $imageSize): void
  84.     {
  85.         $this->imageSize $imageSize;
  86.     }
  87.     public function getImageSize(): ?int
  88.     {
  89.         return $this->imageSize;
  90.     }
  91.     public function getUpdatedAt(): ?\DateTimeInterface
  92.     {
  93.         return $this->updatedAt;
  94.     }
  95.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  96.     {
  97.         $this->updatedAt $updatedAt;
  98.         return $this;
  99.     }
  100.     public function getIsSelected(): ?bool
  101.     {
  102.         return $this->isSelected;
  103.     }
  104.     public function setIsSelected(?bool $isSelected): self
  105.     {
  106.         $this->isSelected $isSelected;
  107.         return $this;
  108.     }
  109.     public function serialize() {
  110.         return serialize(array(
  111.             $this->id,
  112.             $this->imageName,
  113.             $this->updatedAt,
  114.             $this->imageSize,
  115.             $this->isSelected,
  116.         ));
  117.     }
  118.     public function unserialize($serialized) {
  119.         list (
  120.             $this->id,
  121.             $this->imageName,
  122.             $this->updatedAt,
  123.             $this->imageSize,
  124.             $this->isSelected,
  125.             ) = unserialize($serialized);
  126.     }
  127. }