src/App/Entity/WhatsAppIntegration/OutgoingWhatsAppMessage.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity\WhatsAppIntegration;
  3. use App\Entity\Profile\JoboffererProfile;
  4. use App\Entity\Profile\JobseekerProfile;
  5. use App\Utility\DateTimeUtility;
  6. use App\Utility\ReflectionHelper;
  7. use DateTime;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Exception;
  10. use InvalidArgumentException;
  11. use JanusHercules\ApplicationAppointmentScheduling\Domain\Entity\ApplicationAppointmentScheduling;
  12. /**
  13. * @ORM\Entity
  14. *
  15. * @ORM\Table(
  16. * name="outgoing_whatsapp_messages"
  17. * )
  18. */
  19. class OutgoingWhatsAppMessage
  20. {
  21. public const MESSAGE_TYPE_NOTIFICATION_ABOUT_UNREAD_ORGANIC_CONVERSATION_MESSAGE = 0;
  22. public const MESSAGE_TYPE_NOTIFICATION_ABOUT_UNREAD_INTEGRATED_EXTERNAL_PARTNER_CUSTOMER_PREMIUM_RADAR_MESSAGE = 1;
  23. public const MESSAGE_TYPE_NOTIFICATION_ABOUT_GOOGLE_RATING_REQUEST = 2;
  24. public const MESSAGE_TYPE_NOTIFICATION_ABOUT_APPLICATION_APPOINTMENT_SCHEDULING = 3;
  25. /**
  26. * @throws Exception
  27. */
  28. public function __construct(
  29. int $messageType,
  30. string $receiverPhoneNumber,
  31. ?JobseekerProfile $receiverJobseekerProfile,
  32. ?JoboffererProfile $receiverJoboffererProfile,
  33. string $messageBody,
  34. ?string $businessName = null,
  35. ?string $customerInternalId = null
  36. ) {
  37. if (!ReflectionHelper::hasConstWithValue(
  38. self::class,
  39. 'MESSAGE_TYPE_',
  40. $messageType)
  41. ) {
  42. throw new InvalidArgumentException("Value '$messageType' not allowed for messageType.");
  43. }
  44. $this->messageType = $messageType;
  45. if (is_null($receiverJobseekerProfile)
  46. && is_null($receiverJoboffererProfile)
  47. ) {
  48. throw new InvalidArgumentException('Jobofferer Profile and Jobseeker Profile cannot both be null.');
  49. }
  50. if (!is_null($receiverJobseekerProfile)
  51. && !is_null($receiverJoboffererProfile)
  52. ) {
  53. throw new InvalidArgumentException('Jobofferer Profile and Jobseeker Profile cannot both be set.');
  54. }
  55. $this->jobseekerProfile = $receiverJobseekerProfile;
  56. $this->joboffererProfile = $receiverJoboffererProfile;
  57. $this->createdAt = DateTimeUtility::createDateTimeUtc();
  58. $this->receiverPhoneNumber = mb_substr($receiverPhoneNumber, 0, 32);
  59. $this->messageBody = mb_substr($messageBody, 0, 4096);
  60. if (!is_null($businessName)) {
  61. $this->businessName = mb_substr($businessName, 0, 128);
  62. }
  63. if (!is_null($customerInternalId)) {
  64. $this->customerInternalId = mb_substr($customerInternalId, 0, 255);
  65. }
  66. }
  67. /**
  68. * @ORM\GeneratedValue(strategy="CUSTOM")
  69. *
  70. * @ORM\CustomIdGenerator(class="App\Utility\DatabaseIdGenerator")
  71. *
  72. * @ORM\Column(name="id", type="guid")
  73. *
  74. * @ORM\Id
  75. */
  76. private ?string $id;
  77. public function getId(): ?string
  78. {
  79. return $this->id;
  80. }
  81. /**
  82. * @ORM\Column(name="created_at", type="datetime", nullable=false)
  83. */
  84. private DateTime $createdAt;
  85. public function getCreatedAt(): DateTime
  86. {
  87. return $this->createdAt;
  88. }
  89. /**
  90. * @ORM\Column(name="sent_at", type="datetime", nullable=true)
  91. */
  92. private DateTime $sentAt;
  93. public function getSentAt(): DateTime
  94. {
  95. return $this->sentAt;
  96. }
  97. public function setSentAt(DateTime $sentAt): void
  98. {
  99. $this->sentAt = $sentAt;
  100. }
  101. /**
  102. * @ORM\Column(type="smallint", name="message_type", nullable=false, options={"unsigned"=true})
  103. */
  104. private int $messageType;
  105. public function getMessageType(): int
  106. {
  107. return $this->messageType;
  108. }
  109. /**
  110. * @ORM\Column(name="receiver_phone_number", type="text", length=32, nullable=false)
  111. */
  112. private string $receiverPhoneNumber;
  113. public function getReceiverPhoneNumber(): string
  114. {
  115. return $this->receiverPhoneNumber;
  116. }
  117. /**
  118. * @ORM\ManyToOne(targetEntity="App\Entity\Profile\JobseekerProfile", inversedBy="conversationMessages", cascade={"persist"})
  119. *
  120. * @ORM\JoinColumn(name="jobseeker_profiles_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
  121. */
  122. private ?JobseekerProfile $jobseekerProfile;
  123. public function getJobseekerProfile(): ?JobseekerProfile
  124. {
  125. return $this->jobseekerProfile;
  126. }
  127. /**
  128. * @ORM\ManyToOne(targetEntity="App\Entity\Profile\JoboffererProfile", inversedBy="conversationMessages", cascade={"persist"})
  129. *
  130. * @ORM\JoinColumn(name="jobofferer_profiles_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
  131. */
  132. private ?JoboffererProfile $joboffererProfile;
  133. public function getJoboffererProfile(): ?JoboffererProfile
  134. {
  135. return $this->joboffererProfile;
  136. }
  137. /**
  138. * @ORM\Column(name="message_body", type="text", length=4096, nullable=false)
  139. */
  140. private string $messageBody;
  141. public function getMessageBody(): string
  142. {
  143. return $this->messageBody;
  144. }
  145. /**
  146. * @ORM\Column(name="business_name", type="text", length=128, nullable=true)
  147. */
  148. private ?string $businessName = null;
  149. public function getBusinessName(): ?string
  150. {
  151. return $this->businessName;
  152. }
  153. /**
  154. * @ORM\Column(name="integrated_external_partner_customers_internal_id", type="text", length=255, nullable=true)
  155. */
  156. private ?string $customerInternalId = null;
  157. public function getCustomerInternalId(): ?string
  158. {
  159. return $this->customerInternalId;
  160. }
  161. /**
  162. * @ORM\OneToOne(
  163. * targetEntity="JanusHercules\ApplicationAppointmentScheduling\Domain\Entity\ApplicationAppointmentScheduling",
  164. * mappedBy="outgoingWhatsAppMessage"
  165. * )
  166. */
  167. private ?ApplicationAppointmentScheduling $applicationAppointmentScheduling = null;
  168. public function getApplicationAppointmentScheduling(): ?ApplicationAppointmentScheduling
  169. {
  170. return $this->applicationAppointmentScheduling;
  171. }
  172. }