<?php
namespace App\Entity;
use App\Service\NotificationService;
use App\Utility\GuidUtility;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Exception;
/**
* @ORM\Entity
*
* @ORM\Table(
* name="notification_states",
* uniqueConstraints={
*
* @ORM\UniqueConstraint(name="notification_type_user_idx", columns={"notification_type", "users_id"})
* }
* )
*/
class NotificationState
{
/**
* @var string
*
* @ORM\GeneratedValue(strategy="CUSTOM")
*
* @ORM\CustomIdGenerator(class="App\Utility\DatabaseIdGenerator")
*
* @ORM\Column(name="id", type="guid")
*
* @ORM\Id
*/
protected $id;
public function setId(string $id): void
{
GuidUtility::validOrThrow($id);
$this->id = $id;
}
public function getId()
{
return $this->id;
}
/**
* @var User
*
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="notificationStates", cascade={"persist"})
*
* @ORM\JoinColumn(name="users_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
protected $user;
public function setUser(User $user): void
{
$this->user = $user;
}
public function getUser(): User
{
return $this->user;
}
/**
* @var int
*
* @ORM\Column(name="notification_type", type="smallint", nullable=false)
*/
protected $notificationType;
/**
* @throws Exception
*/
public function setNotificationType(int $notificationType): void
{
if (!in_array($notificationType, NotificationService::NOTIFICATION_TYPES)) {
throw new Exception('Value ' . $notificationType . ' not allowed for notificationType.');
}
$this->notificationType = $notificationType;
}
public function getNotificationType(): int
{
return $this->notificationType;
}
/**
* @var int
*
* @ORM\Column(name="number_of_sent_notifications", type="smallint", nullable=false)
*
* @throws Exception
*/
protected $numberOfSentNotifications;
public function setNumberOfSentNotifications(int $numberOfSentNotifications): void
{
if ($numberOfSentNotifications < 0) {
throw new Exception('Value ' . $numberOfSentNotifications . ' not allowed for numberOfSentNotifications.');
}
$this->numberOfSentNotifications = $numberOfSentNotifications;
}
public function getNumberOfSentNotifications(): int
{
return $this->numberOfSentNotifications;
}
/**
* @var DateTime
*
* @ORM\Column(name="latest_notification_sent_at", type="datetime", nullable=false)
*/
protected $latestNotificationSentAt;
public function setLatestNotificationSentAt(DateTime $latestNotificationSentAt): void
{
$this->latestNotificationSentAt = $latestNotificationSentAt;
}
public function getLatestNotificationSentAt(): DateTime
{
return $this->latestNotificationSentAt;
}
/**
* This is a field which can be filled with arbitrary string data, with content specific
* to each notification type.
*
* @var string|null
*
* @ORM\Column(name="notification_details", type="text", length=4096, nullable=true)
*/
protected $notificationDetails;
public function setNotificationDetails(?string $notificationDetails): void
{
$this->notificationDetails = $notificationDetails;
}
public function getNotificationDetails(): ?string
{
return $this->notificationDetails;
}
}