app/Entity/Schema/ORM/Notification.php line 11

Open in your IDE?
  1. <?php
  2. namespace Sq\Entity\Schema\ORM;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Sq\Entity\Enum;
  5. use Sq\Entity\Schema\DocumentObject;
  6. #[ORM\Entity(repositoryClass\Sq\Service\Repository\ORM\NotificationRepository::class)]
  7. #[ORM\Table(name'notifications')]
  8. class Notification
  9. {
  10.     /**
  11.      * @var int
  12.      */
  13.     #[ORM\Column(name'n_id'type'integer'nullablefalseoptions: ['unsigned' => true])]
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue(strategy'IDENTITY')]
  16.     protected $id;
  17.     /**
  18.      * @var string
  19.      */
  20.     #[ORM\Column(name'n_name'type'string'length255nullablefalse)]
  21.     protected $name;
  22.     /**
  23.      * @var string
  24.      */
  25.     #[ORM\Column(name'n_message'type'string'length1000nullablefalse)]
  26.     protected $message;
  27.     /**
  28.      * @var string
  29.      */
  30.     #[ORM\Column(name'n_datetime'type'datetime'nullablefalse)]
  31.     protected $dateTime;
  32.     /**
  33.      * @var string
  34.      */
  35.     #[ORM\Column(name'n_scope'type'string'length255nullablefalse)]
  36.     protected $scope;
  37.     /**
  38.      * @var int
  39.      */
  40.     #[ORM\Column(name'n_read'type'boolean'nullablefalse)]
  41.     protected $isRead false;
  42.     /**
  43.      * @var User
  44.      */
  45.     #[ORM\ManyToOne(targetEntityUser::class)]
  46.     #[ORM\JoinColumn(name'n_user_id'referencedColumnName'u_id'nullablefalse)]
  47.     protected $user;
  48.     /**
  49.      * @var int|null
  50.      */
  51.     #[ORM\ManyToOne(targetEntityOrganization::class)]
  52.     #[ORM\JoinColumn(name'n_org_id'referencedColumnName'o_id'nullabletrue)]
  53.     private $organization;
  54.     /**
  55.      * @var int|null
  56.      */
  57.     #[ORM\ManyToOne(targetEntityWorkspace::class)]
  58.     #[ORM\JoinColumn(name'n_workspace_id'referencedColumnName'ws_id'nullabletrue)]
  59.     private $workspace;
  60.     /**
  61.      * @var array|null
  62.      */
  63.     #[ORM\Column(name'n_metadata'type'json'nullabletrue)]
  64.     private $metadata;
  65.     public function __construct(
  66.         Enum\Notification\NotificationName $name,
  67.         Enum\Notification\NotificationScope $scope,
  68.         string $message,
  69.         User $user,
  70.         ?Workspace $workspace null,
  71.         ?Organization $organization null
  72.     ) {
  73.         $this->name $name->getValue();
  74.         $this->scope $scope->getValue();
  75.         $this->message $message;
  76.         $this->user $user;
  77.         $this->organization $organization;
  78.         $this->workspace $workspace;
  79.         $this->dateTime = new \DateTimeImmutable();
  80.     }
  81.     public function getId(): ?int
  82.     {
  83.         return $this->id;
  84.     }
  85.     public function getName(): Enum\Notification\NotificationName
  86.     {
  87.         return Enum\Notification\NotificationName::from($this->name);
  88.     }
  89.     public function getScope(): Enum\Notification\NotificationScope
  90.     {
  91.         return Enum\Notification\NotificationScope::from($this->scope);
  92.     }
  93.     public function getMessage(): string
  94.     {
  95.         return $this->message;
  96.     }
  97.     public function isRead(): bool
  98.     {
  99.         return $this->isRead;
  100.     }
  101.     public function markAsRead(): self
  102.     {
  103.         $this->isRead true;
  104.         return $this;
  105.     }
  106.     public function getDateTime(): \DateTimeInterface
  107.     {
  108.         return $this->dateTime;
  109.     }
  110.     public function getUser(): User
  111.     {
  112.         return $this->user;
  113.     }
  114.     public function getOrganization(): ?Organization
  115.     {
  116.         return $this->organization;
  117.     }
  118.     public function getWorkspace(): ?Workspace
  119.     {
  120.         return $this->workspace;
  121.     }
  122.     public function getMetadata(): ?DocumentObject\Notification\Metadata
  123.     {
  124.         return DocumentObject\Notification\Metadata::createFromTypeAndData(
  125.             $this->getName(),
  126.             $this->metadata
  127.         );
  128.     }
  129.     public function setMetadata(?DocumentObject\Notification\Metadata $metadata): self
  130.     {
  131.         $this->metadata $metadata?->serialize();
  132.         return $this;
  133.     }
  134. }