<?php
namespace App\Entity;
use App\Service\NotificationService;
use App\Utility\GuidUtility;
use Doctrine\ORM\Mapping as ORM;
use Exception;
/**
* @ORM\Entity
*
* @ORM\Table(
* name="notification_settings",
* uniqueConstraints={
*
* @ORM\UniqueConstraint(name="notification_type_setting_type_user_idx", columns={"notification_type", "setting_type", "users_id"})
* }
* )
*
* If required, this entity can grow using different value types ("setting_int_value", "setting_string_value" etc.), but
* for now we keep it simple
*/
class NotificationSetting
{
public const SETTING_TYPE_CANCELED = 0;
/**
* @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="notificationSettings", 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="setting_type", type="smallint", nullable=false)
*/
protected $settingType;
public function setSettingType(int $settingType): void
{
if ($settingType != self::SETTING_TYPE_CANCELED) {
throw new Exception('Value ' . $settingType . ' not allowed for settingType.');
}
$this->settingType = $settingType;
}
public function getSettingType(): int
{
return $this->settingType;
}
}