src/Entity/Core/Peer/PeerSolutionFile.php line 17

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