src/Entity/FileManager.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\FileManagerRepository;
  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 JMS\Serializer\Annotation as Serializer;
  11. /**
  12. * @ORM\Entity(repositoryClass=FileManagerRepository::class)
  13. * @Vich\Uploadable
  14. * @Serializer\ExclusionPolicy("ALL")
  15. */
  16. class FileManager
  17. {
  18. /**
  19. * @ORM\Id
  20. * @ORM\GeneratedValue
  21. * @ORM\Column(type="integer")
  22. */
  23. private $id;
  24. /**
  25. * NOTE: This is not a mapped field of entity metadata, just a simple property.
  26. *
  27. * @Vich\UploadableField(mapping="doc_file", fileNameProperty="fileName", size="fileSize")
  28. *
  29. * @var File|null
  30. */
  31. private $file;
  32. /**
  33. * @ORM\Column(type="string", length=255, nullable=true)
  34. * @Serializer\Expose
  35. */
  36. private $fileName;
  37. /**
  38. * @ORM\Column(type="integer", nullable=true)
  39. */
  40. private $fileSize;
  41. /**
  42. * @ORM\Column(type="datetime", nullable=true)
  43. */
  44. private $updatedAt;
  45. public function __construct()
  46. {
  47. $this->courses = new ArrayCollection();
  48. }
  49. public function getId(): ?int
  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|null $file
  61. * @throws \Exception
  62. */
  63. public function setFile(?File $file = null): void
  64. {
  65. $this->file = $file;
  66. if ($file) {
  67. $this->updatedAt = new \DateTime('now');
  68. }
  69. }
  70. public function getFile(): ?File
  71. {
  72. return $this->file;
  73. }
  74. public function getFileName(): ?string
  75. {
  76. return $this->fileName;
  77. }
  78. public function setFileName(?string $fileName): self
  79. {
  80. $this->fileName = $fileName;
  81. return $this;
  82. }
  83. public function getFileSize(): ?int
  84. {
  85. return $this->fileSize;
  86. }
  87. public function setFileSize(?int $fileSize): self
  88. {
  89. $this->fileSize = $fileSize;
  90. return $this;
  91. }
  92. public function getUpdatedAt(): ?\DateTimeInterface
  93. {
  94. return $this->updatedAt;
  95. }
  96. public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  97. {
  98. $this->updatedAt = $updatedAt;
  99. return $this;
  100. }
  101. }