Repository URL to install this package:
|
Version:
6.2.6 ▾
|
<?php
namespace DigitalAscetic\NotificationsBundle\Entity;
use DigitalAscetic\BaseEntityBundle\Entity\BaseEntity;
use DigitalAscetic\BaseEntityBundle\Entity\CreatedTrait;
use DigitalAscetic\BaseEntityBundle\Entity\UpdatedTrait;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* Class Notification
*
* This class relate a NotificationObject with a Receiver.
* This is required to be able to handle each status change of notification for each receiver.
* Otherwise we won't be able to know the status of the notification per user.
*
* @package DigitalAscetic\NotificationsBundle\Entity
*
* @ORM\Table(name="notification",
* indexes={
* @ORM\Index(name="not_receiver", columns={"receiver_id"})
* })
* @ORM\Entity()
*/
#[ORM\Table(name: "notification")]
#[ORM\Index(columns: ["receiver_id"], name: "not_receiver")]
#[ORM\Entity]
class Notification extends BaseEntity
{
use CreatedTrait;
use UpdatedTrait;
const ALIAS = 'notify';
const VIEW_COMPLETE = 'complete';
const VIEW_DEFAULT = 'default';
const STATUS_PENDING = 'PENDING';
const STATUS_PROCESSING = 'PROCESSING';
const STATUS_SENT = 'SENT';
const STATUS_RECEIVED = 'RECEIVED';
const STATUS_READ = 'READ';
const TYPE_IN_APP = 'INAPP';
const TYPE_SMS = 'SMS';
const TYPE_MAIL = 'MAIL';
public static function getSerializationGroups($viewName)
{
switch ($viewName) {
case 'default':
$result = [
'ascetic.notification.default',
'ascetic.notification.object',
'ascetic.notification.receiver'
];
$result = array_merge($result, NotificationObject::getSerializationGroups(NotificationObject::VIEW_DEFAULT));
break;
case 'complete':
$result = [
'ascetic.notification.default',
'ascetic.notification.object',
'ascetic.notification.receiver'
];
$result = array_merge($result, NotificationObject::getSerializationGroups(NotificationObject::VIEW_COMPLETE));
break;
default:
$result = [
'ascetic.notification.default',
'ascetic.notification.object',
'ascetic.notification.receiver'
];
break;
}
return $result;
}
/**
* @var NotificationObject
*
* @ORM\ManyToOne(targetEntity="DigitalAscetic\NotificationsBundle\Entity\NotificationObject")
* @ORM\JoinColumn(name="notification_obj_id", referencedColumnName="id", nullable=false)
* @Groups({"ascetic.notification.object"})
*/
#[ORM\ManyToOne(targetEntity: "DigitalAscetic\NotificationsBundle\Entity\NotificationObject")]
#[ORM\JoinColumn(name: "notification_obj_id", referencedColumnName: "id", nullable: false)]
#[Groups("ascetic.notification.object")]
private NotificationObject $notificationObject;
/**
* @var string
*
* @ORM\Column(name="status", type="string", nullable=false)
* @Groups({"ascetic.notification.default"})
*/
#[ORM\Column(name: "status", type: "string", nullable: false)]
#[Groups("ascetic.notification.default")]
private string $status;
/**
* @var string
*
* @ORM\Column(name="type", type="string", nullable=false)
* @Groups({"ascetic.notification.default"})
*/
#[ORM\Column(name: "type", type: "string", nullable: false)]
#[Groups("ascetic.notification.default")]
private string $type;
/**
* @var Receiver
*
* @ORM\Embedded(class="DigitalAscetic\NotificationsBundle\Entity\Receiver")
* @Groups({"ascetic.notification.receiver"})
*/
#[ORM\Embedded(class: "DigitalAscetic\NotificationsBundle\Entity\Receiver")]
#[Groups("ascetic.notification.receiver")]
private ?Receiver $receiver = null;
/**
* @var mixed|null
*
* @ORM\Column(name="data", type="text", length=10000, nullable=true)
* @Groups({"ascetic.notification.default"})
*/
#[ORM\Column(name: "data", type: "text", length: 10000, nullable: true)]
#[Groups("ascetic.notification.default")]
private \stdClass|string|null $data = null;
/**
* Notification constructor.
* @param NotificationObject $notificationObject
* @param Receiver $receiver
* @param string $type
* @param string $status
*/
public function __construct(NotificationObject $notificationObject,
Receiver $receiver,
string $type = Notification::TYPE_IN_APP,
string $status = Notification::STATUS_PENDING)
{
$this->notificationObject = $notificationObject;
$this->receiver = $receiver;
$this->type = $type;
$this->status = $status;
}
/**
* @return NotificationObject
*/
public function getNotificationObject(): NotificationObject
{
return $this->notificationObject;
}
/**
* @return Receiver
*/
public function getReceiver(): Receiver
{
return $this->receiver;
}
/**
* @return string
*/
public function getStatus(): string
{
return $this->status;
}
/**
* @param string $status
*/
public function setStatus(string $status): void
{
$this->status = $status;
}
/**
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* @param string $type
*/
public function setType(string $type): void
{
$this->type = $type;
}
/**
* @return \stdClass|string|null
*/
public function getData()
{
return json_decode($this->data);
}
/**
* @param mixed $data
*/
public function setData($data): void
{
$this->data = json_encode($data);
}
}