src/CoreBundle/Entity/PeerSolutionFile.php line 16

Open in your IDE?
  1. <?php
  2. namespace CoreBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use JsonSerializable;
  5. use Symfony\Component\HttpFoundation\File\File as File;
  6. use Symfony\Component\HttpFoundation\File\UploadedFile;
  7. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  8. /**
  9. * @ORM\Entity
  10. * @ORM\Table("peer_solution_file")
  11. * @Vich\Uploadable
  12. */
  13. class PeerSolutionFile extends SolutionFile implements JsonSerializable
  14. {
  15. /**
  16. * @var PeerSolution
  17. *
  18. * @ORM\ManyToOne(targetEntity="PeerSolution", inversedBy="peerSolutionFiles")
  19. */
  20. private $peerSolution;
  21. /**
  22. * NOTE: This is not a mapped field of entity metadata, just a simple property.
  23. *
  24. * @Vich\UploadableField(mapping="peer_solution_file", fileNameProperty="fileName", originalName="originalName", size="fileSize", mimeType="mimeType")
  25. *
  26. * @var File
  27. */
  28. private $file;
  29. public function getPeerSolution(): PeerSolution
  30. {
  31. return $this->peerSolution;
  32. }
  33. public function setPeerSolution(PeerSolution $peerSolution)
  34. {
  35. $this->peerSolution = $peerSolution;
  36. }
  37. /**
  38. * @param File|UploadedFile $file
  39. * @throws \Exception
  40. */
  41. public function setFile(?File $file = null): void
  42. {
  43. $this->file = $file;
  44. if (null !== $file) {
  45. // It is required that at least one field changes if you are using doctrine
  46. // otherwise the event listeners won't be called and the file is lost
  47. $this->updatedAt = new \DateTimeImmutable();
  48. }
  49. }
  50. public function getFile(): ?File
  51. {
  52. return $this->file;
  53. }
  54. public function jsonSerialize(): mixed
  55. {
  56. return [
  57. "fileName" => $this->fileName,
  58. "originalName" => $this->originalName,
  59. "fileSize" => $this->fileSize,
  60. "mimeType" => $this->mimeType,
  61. ];
  62. }
  63. }