src/App/Entity/NotificationState.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Service\NotificationService;
  4. use App\Utility\GuidUtility;
  5. use DateTime;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Exception;
  8. /**
  9. * @ORM\Entity
  10. *
  11. * @ORM\Table(
  12. * name="notification_states",
  13. * uniqueConstraints={
  14. *
  15. * @ORM\UniqueConstraint(name="notification_type_user_idx", columns={"notification_type", "users_id"})
  16. * }
  17. * )
  18. */
  19. class NotificationState
  20. {
  21. /**
  22. * @var string
  23. *
  24. * @ORM\GeneratedValue(strategy="CUSTOM")
  25. *
  26. * @ORM\CustomIdGenerator(class="App\Utility\DatabaseIdGenerator")
  27. *
  28. * @ORM\Column(name="id", type="guid")
  29. *
  30. * @ORM\Id
  31. */
  32. protected $id;
  33. public function setId(string $id): void
  34. {
  35. GuidUtility::validOrThrow($id);
  36. $this->id = $id;
  37. }
  38. public function getId()
  39. {
  40. return $this->id;
  41. }
  42. /**
  43. * @var User
  44. *
  45. * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="notificationStates", cascade={"persist"})
  46. *
  47. * @ORM\JoinColumn(name="users_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
  48. */
  49. protected $user;
  50. public function setUser(User $user): void
  51. {
  52. $this->user = $user;
  53. }
  54. public function getUser(): User
  55. {
  56. return $this->user;
  57. }
  58. /**
  59. * @var int
  60. *
  61. * @ORM\Column(name="notification_type", type="smallint", nullable=false)
  62. */
  63. protected $notificationType;
  64. /**
  65. * @throws Exception
  66. */
  67. public function setNotificationType(int $notificationType): void
  68. {
  69. if (!in_array($notificationType, NotificationService::NOTIFICATION_TYPES)) {
  70. throw new Exception('Value ' . $notificationType . ' not allowed for notificationType.');
  71. }
  72. $this->notificationType = $notificationType;
  73. }
  74. public function getNotificationType(): int
  75. {
  76. return $this->notificationType;
  77. }
  78. /**
  79. * @var int
  80. *
  81. * @ORM\Column(name="number_of_sent_notifications", type="smallint", nullable=false)
  82. *
  83. * @throws Exception
  84. */
  85. protected $numberOfSentNotifications;
  86. public function setNumberOfSentNotifications(int $numberOfSentNotifications): void
  87. {
  88. if ($numberOfSentNotifications < 0) {
  89. throw new Exception('Value ' . $numberOfSentNotifications . ' not allowed for numberOfSentNotifications.');
  90. }
  91. $this->numberOfSentNotifications = $numberOfSentNotifications;
  92. }
  93. public function getNumberOfSentNotifications(): int
  94. {
  95. return $this->numberOfSentNotifications;
  96. }
  97. /**
  98. * @var DateTime
  99. *
  100. * @ORM\Column(name="latest_notification_sent_at", type="datetime", nullable=false)
  101. */
  102. protected $latestNotificationSentAt;
  103. public function setLatestNotificationSentAt(DateTime $latestNotificationSentAt): void
  104. {
  105. $this->latestNotificationSentAt = $latestNotificationSentAt;
  106. }
  107. public function getLatestNotificationSentAt(): DateTime
  108. {
  109. return $this->latestNotificationSentAt;
  110. }
  111. /**
  112. * This is a field which can be filled with arbitrary string data, with content specific
  113. * to each notification type.
  114. *
  115. * @var string|null
  116. *
  117. * @ORM\Column(name="notification_details", type="text", length=4096, nullable=true)
  118. */
  119. protected $notificationDetails;
  120. public function setNotificationDetails(?string $notificationDetails): void
  121. {
  122. $this->notificationDetails = $notificationDetails;
  123. }
  124. public function getNotificationDetails(): ?string
  125. {
  126. return $this->notificationDetails;
  127. }
  128. }