src/App/Entity/ExtendedApplication/ExtendedApplicationCvFile.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Entity\ExtendedApplication;
  3. use App\Entity\User;
  4. use App\Entity\UserUploadedFile;
  5. use DateTime;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Exception;
  8. use Symfony\Component\HttpFoundation\File\File;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. /**
  11. * @ORM\Entity()
  12. *
  13. * @ORM\Table(
  14. * name="extended_application_cv_files",
  15. * uniqueConstraints={
  16. *
  17. * @ORM\UniqueConstraint(name="file_name_unique_idx", columns={"file_name"})
  18. * },
  19. * indexes={
  20. *
  21. * @ORM\Index(name="batch_id_idx", columns={"batch_id"}),
  22. * }
  23. * )
  24. *
  25. * @Vich\Uploadable
  26. */
  27. class ExtendedApplicationCvFile extends UserUploadedFile
  28. {
  29. /**
  30. * @var string
  31. *
  32. * @ORM\GeneratedValue(strategy="CUSTOM")
  33. *
  34. * @ORM\CustomIdGenerator(class="App\Utility\DatabaseIdGenerator")
  35. *
  36. * @ORM\Column(name="id", type="guid")
  37. *
  38. * @ORM\Id
  39. */
  40. protected $id;
  41. /**
  42. * @ORM\ManyToOne(targetEntity="App\Entity\ExtendedApplication\ExtendedApplication", inversedBy="extendedApplicationCvFiles", cascade={"persist"})
  43. *
  44. * @ORM\JoinColumn(name="extended_application_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
  45. */
  46. protected ExtendedApplication $extendedApplication;
  47. /**
  48. * @var File|null
  49. *
  50. * @Vich\UploadableField(mapping="extended_application_cv_file", fileNameProperty="fileName")
  51. */
  52. protected $file;
  53. /**
  54. * @var string|null
  55. *
  56. * @ORM\Column(name="file_name", type="string", length=255, nullable=false)
  57. */
  58. protected $fileName;
  59. public function getFileName(): string
  60. {
  61. if (is_null($this->fileName)) {
  62. return '';
  63. }
  64. return $this->fileName;
  65. }
  66. /**
  67. * @var string
  68. *
  69. * @ORM\Column(name="original_file_name", type="string", length=255, nullable=false)
  70. */
  71. protected $originalFileName;
  72. /**
  73. * @var string
  74. *
  75. * @ORM\Column(name="mime_type", type="string", length=255, nullable=false)
  76. */
  77. protected $mimeType;
  78. /**
  79. * @var string
  80. *
  81. * @ORM\Column(name="batch_id", type="string", length=64, nullable=false)
  82. */
  83. protected $batchId;
  84. /**
  85. * @var bool
  86. *
  87. * @ORM\Column(name="is_primary", type="boolean", nullable=false)
  88. */
  89. protected $isPrimary;
  90. public function setIsPrimary(bool $isPrimary): void
  91. {
  92. $this->isPrimary = $isPrimary;
  93. }
  94. /**
  95. * @var DateTime
  96. *
  97. * @ORM\Column(name="updated_at", type="datetime", nullable=false)
  98. */
  99. protected $updatedAt;
  100. public function setExtendedApplication(ExtendedApplication $extendedApplication): void
  101. {
  102. $this->extendedApplication = $extendedApplication;
  103. }
  104. /** @throws Exception */
  105. public function getUser(): User
  106. {
  107. if (is_null($this->extendedApplication)) {
  108. $file = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['file'];
  109. $line = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['line'];
  110. $function = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'];
  111. throw new Exception("Connected extended application is null. Called from file '$file', line '$line', function '$function.");
  112. }
  113. if (is_null($this->extendedApplication->getJobseekerProfile()) || is_null($this->extendedApplication->getJobseekerProfile()->getUser())) {
  114. throw new Exception("Connected extended application {$this->extendedApplication->getId()} does not have a user or jobseekerProfile set.");
  115. }
  116. return $this->extendedApplication->getJobseekerProfile()->getUser();
  117. }
  118. }