Repository URL to install this package:
|
Version:
6.2.3 ▾
|
<?php
/**
* Created by PhpStorm.
* User: eduarddezacastellano
* Date: 08/10/2018
* Time: 11:32
*/
namespace DigitalAscetic\GoogleApiClientBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class GoogleApiNotificationsChannel
* @package Bluplat\ApiBundle\Entity\Agency
*
* @ORM\Table(name="google_notifications_channel",
* indexes={
* @ORM\Index(name="google_notifications_channel_idx", columns={"channel_id"}),
* @ORM\Index(name="google_notifications_last_notified_idx", columns={"lastNotificationHandledDate"})
* })
* @ORM\Entity()
*/
#[ORM\Table(name: "google_notifications_channel")]
#[ORM\Index(columns: ["channel_id"], name: "google_notifications_channel_idx")]
#[ORM\Index(columns: ["lastNotificationHandledDate"], name: "google_notifications_last_notified_idx")]
#[ORM\Entity]
class GoogleApiNotificationsChannel
{
const TYPE_WEB_HOOK = 'web_hook';
const CALENDAR_TOKEN = 'calendar';
const ALIAS = 'goo_not_ch';
/**
* @var int|null
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
#[ORM\Column(name: "id", type: "integer")]
#[ORM\Id]
#[ORM\GeneratedValue(strategy: "IDENTITY")]
private ?int $id = null;
/**
* Property string that uniquely identifies this new notification channel within your project
*
* @var string
*
* @ORM\Column(name="channel_id", type="string", length=64, nullable=false)
*/
#[ORM\Column(name: "channel_id", type: "string", length: 64, nullable: false)]
private string $channelId;
/**
* Property string set to the value web_hook
*
* @var string
*
* @ORM\Column(name="type", type="string", length=20, nullable=false)
*/
#[ORM\Column(name: "type", type: "string", length: 20, nullable: false)]
private string $type;
/**
* That specifies an arbitrary string value to use as a channel token, for ex: channel type calendar
*
* @var string
*
* @ORM\Column(name="token", type="string", length=20, nullable=false)
*/
#[ORM\Column(name: "token", type: "string", length: 20, nullable: false)]
private string $token;
/**
* Identifier for the watched resource (for example calendar events)
*
* @var string
*
* @ORM\Column(name="resourceId", type="string", length=64, nullable=false)
*/
#[ORM\Column(name: "resourceId", type: "string", length: 64, nullable: false)]
private string $resourceId;
/**
* Can be used for example to store nextSyncToken of Google Calendar Events
*
* @var string|null
*
* @ORM\Column(name="syncToken", type="string", length=64, nullable=true)
*/
#[ORM\Column(name: "syncToken", type: "string", length: 64, nullable: true)]
private ?string $syncToken = null;
/**
* Channel expiration time in Timestamp
*
* @var string|null
*
* @ORM\Column(name="expiration", type="string", length=20, nullable=true)
*/
#[ORM\Column(name: "expiration", type: "string", length: 20, nullable: true)]
private ?string $expiration = null;
/** @var IGoogleApiUser|null $user */
private ?IGoogleApiUser $user = null;
/**
* @var \DateTime|null
*
* @ORM\Column(name="lastNotificationHandledDate", type="datetime", nullable=true)
*/
#[ORM\Column(name: "lastNotificationHandledDate", type: "datetime", nullable: true)]
private ?\DateTime $lastNotificationHandledDate = null;
/**
* @var \DateTime|null
*
* @ORM\Column(name="lastSyncNotificationDate", type="datetime", nullable=true)
*/
#[ORM\Column(name: "lastSyncNotificationDate", type: "datetime", nullable: true)]
private ?\DateTime $lastSyncNotificationDate = null;
/**
* Can be used for example to store nextSyncToken of Google Calendar Events
*
* @var string|null
*
* @ORM\Column(name="channelHostname", type="string", length=255, nullable=true)
*/
#[ORM\Column(name: "channelHostname", type: "string", length: 255, nullable: true)]
private ?string $host = null;
/**
* GoogleApiNotificationsChannel constructor.
* @param string $type
* @param string $token
* @param IGoogleApiUser $user
*/
public function __construct(string $type, string $token, IGoogleApiUser $user)
{
$this->channelId = uniqid();
$this->type = $type;
$this->token = $token;
$this->user = $user;
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @return string
*/
public function getChannelId(): string
{
return $this->channelId;
}
/**
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* @return string
*/
public function getToken(): string
{
return $this->token;
}
/**
* @return IGoogleApiUser
*/
public function getUser(): IGoogleApiUser
{
return $this->user;
}
/**
* @return string
*/
public function getResourceId(): string
{
return $this->resourceId;
}
/**
* @param string $resourceId
*/
public function setResourceId(string $resourceId): void
{
$this->resourceId = $resourceId;
}
/**
* @return null|string
*/
public function getSyncToken(): ?string
{
return $this->syncToken;
}
/**
* @param null|string $syncToken
*/
public function setSyncToken(?string $syncToken): void
{
$this->syncToken = $syncToken;
}
/**
* @return null|string
*/
public function getExpiration(): ?string
{
return $this->expiration;
}
/**
* @param null|string $expiration
*/
public function setExpiration(?string $expiration): void
{
$this->expiration = $expiration;
}
/**
* Method to check if Channel has expired (timestamp is in milliseconds)
*
* @return bool
* @throws \Exception
*/
public function isExpired()
{
$currentDateTime = new \DateTime();
$currentTimesTampMs = $currentDateTime->getTimestamp() * 1000;
return $this->expiration <= $currentTimesTampMs;
}
/**
* @return \DateTime|null
*/
public function getLastNotificationHandledDate(): ?\DateTime
{
return $this->lastNotificationHandledDate;
}
/**
* @param \DateTime|null $lastNotificationHandledDate
*/
public function setLastNotificationHandledDate(?\DateTime $lastNotificationHandledDate): void
{
$this->lastNotificationHandledDate = $lastNotificationHandledDate;
}
/**
* @return \DateTime|null
*/
public function getLastSyncNotificationDate(): ?\DateTime
{
return $this->lastSyncNotificationDate;
}
/**
* @param \DateTime|null $lastSyncNotificationDate
*/
public function setLastSyncNotificationDate(?\DateTime $lastSyncNotificationDate): void
{
$this->lastSyncNotificationDate = $lastSyncNotificationDate;
}
/**
* @return string|null
*/
public function getHost(): ?string
{
return $this->host;
}
/**
* @param string|null $host
*/
public function setHost(?string $host): void
{
$this->host = $host;
}
}