<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Serializable;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\HttpFoundation\File\File as Ffile;
/**
* @ORM\Entity(repositoryClass="App\Repository\FileRepository")
* @Vich\Uploadable
*/
class File implements Serializable
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="upload_image", fileNameProperty="imageName", size="imageSize")
*
* @var File
*/
private $file;
/**
* @ORM\Column(type="string", length=255)
*
* @var string
*/
private $imageName;
/**
* @ORM\Column(type="datetime")
*
* @var \DateTime
*/
private $updatedAt;
/**
* @ORM\Column(type="integer")
*
* @var integer
*/
private $imageSize;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isSelected;
public function getId()
{
return $this->id;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile $image
*/
public function setFile(?Ffile $file = null): void
{
$this->file = $file;
if (null !== $file) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getFile(): ?Ffile
{
return $this->file;
}
public function setImageName(?string $imageName): void
{
$this->imageName = $imageName;
}
public function getImageName(): ?string
{
return $this->imageName;
}
public function setImageSize(?int $imageSize): void
{
$this->imageSize = $imageSize;
}
public function getImageSize(): ?int
{
return $this->imageSize;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getIsSelected(): ?bool
{
return $this->isSelected;
}
public function setIsSelected(?bool $isSelected): self
{
$this->isSelected = $isSelected;
return $this;
}
public function serialize() {
return serialize(array(
$this->id,
$this->imageName,
$this->updatedAt,
$this->imageSize,
$this->isSelected,
));
}
public function unserialize($serialized) {
list (
$this->id,
$this->imageName,
$this->updatedAt,
$this->imageSize,
$this->isSelected,
) = unserialize($serialized);
}
}