src/Entity/Core/Worksheet/WorksheetSolutionFile.php line 16

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