src/App/Entity/ImmediateApplication/ContactMessageCvFile.php line 29

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