<?php
namespace Products\NotificationsBundle\Entity;
use Cms\TenantBundle\Entity\TenantedEntity;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use JsonSerializable;
use Reinder83\BinaryFlags\Bits;
/**
* Class Recording
* @package Products\NotificationsBundle\Entity
*
* @ORM\Entity(
* repositoryClass = "Products\NotificationsBundle\Doctrine\Repository\RecordingRepository",
* )
* @ORM\Table(
* name = "notis__recording",
* )
*/
class Recording extends TenantedEntity implements JsonSerializable
{
const METHODS = [
'upload' => self::METHODS__UPLOAD,
'browser' => self::METHODS__BROWSER,
'speech' => self::METHODS__SPEECH,
'phone' => self::METHODS__PHONE,
];
const METHODS__NONE = 0;
const METHODS__UPLOAD = Bits::BIT_1;
const METHODS__BROWSER = Bits::BIT_2;
const METHODS__SPEECH = Bits::BIT_3;
const METHODS__PHONE = Bits::BIT_4;
/**
* @var int
*
* @ORM\Column(
* type = "integer",
* nullable = false,
* options = {
* "default" = self::METHODS__NONE,
* "unsigned" = true,
* },
* )
*/
protected int $method = self::METHODS__NONE;
/**
* @var DateTime|null
*
* @ORM\Column(
* type = "datetime",
* nullable = true,
* )
*/
protected ?DateTime $recordedAt = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "text",
* nullable = true,
* )
*/
protected ?string $speechText = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $speechTaskId = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $phoneCallId = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $phoneRecordingId = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $phoneRecordingUrl = null;
/**
* @var string|null
*
* @ORM\Column(
* type = "string",
* nullable = true,
* )
*/
protected ?string $phoneRecordingStatus = null;
/**
* @return string|null
*/
public function getSpeechTaskId(): ?string
{
return $this->speechTaskId;
}
/**
* @param string|null $speechTaskId
* @return $this
*/
public function setSpeechTaskId(?string $speechTaskId): self
{
$this->speechTaskId = $speechTaskId;
return $this;
}
/**
* @return string|null
*/
public function getSpeechText(): ?string
{
return $this->speechText;
}
/**
* @param string|null $speechText
* @return $this
*/
public function setSpeechText(?string $speechText): self
{
$this->speechText = $speechText;
return $this;
}
/**
* @return int
*/
public function getMethod(): int
{
return $this->method;
}
/**
* @return string
*/
public function getMethodName(): string
{
return array_search($this->getMethod(), self::METHODS) ?? 'none';
}
/**
* @param int $method
* @return $this
*/
public function setMethod(int $method): self
{
$this->method = $method;
return $this;
}
/**
* @return bool
*/
public function hasMethod(): bool
{
return ($this->getMethod() !== self::METHODS__NONE);
}
/**
* @param int|string $method
* @return bool
*/
public function isMethod($method): bool
{
if (is_string($method) && array_key_exists($method, self::METHODS)) {
$method = self::METHODS[$method];
}
if ( ! is_int($method) || ! in_array($method, self::METHODS)) {
throw new \Exception();
}
return ($this->getMethod() === $method);
}
/**
* @return bool
*/
public function isRecorded(): bool
{
return ( ! empty($this->getRecordedAt()));
}
/**
* @return DateTime|null
*/
public function getRecordedAt(): ?DateTime
{
return $this->recordedAt;
}
/**
* @param DateTime|null $recordedAt
* @return $this
*/
public function setRecordedAt(?DateTime $recordedAt): self
{
$this->recordedAt = $recordedAt;
return $this;
}
/**
* @return string|null
*/
public function getPhoneCallId(): ?string
{
return $this->phoneCallId;
}
/**
* @param string|null $phoneCallId
* @return $this
*/
public function setPhoneCallId(?string $phoneCallId): self
{
$this->phoneCallId = $phoneCallId;
return $this;
}
/**
* @return string|null
*/
public function getPhoneRecordingId(): ?string
{
return $this->phoneRecordingId;
}
/**
* @param string|null $phoneRecordingId
* @return $this
*/
public function setPhoneRecordingId(?string $phoneRecordingId): self
{
$this->phoneRecordingId = $phoneRecordingId;
return $this;
}
/**
* @return string|null
*/
public function getPhoneRecordingUrl(): ?string
{
return $this->phoneRecordingUrl;
}
/**
* @param string|null $phoneRecordingUrl
* @return $this
*/
public function setPhoneRecordingUrl(?string $phoneRecordingUrl): self
{
$this->phoneRecordingUrl = $phoneRecordingUrl;
return $this;
}
/**
* @return string|null
*/
public function getPhoneRecordingStatus(): ?string
{
return $this->phoneRecordingStatus;
}
/**
* @param string|null $phoneRecordingStatus
* @return $this
*/
public function setPhoneRecordingStatus(?string $phoneRecordingStatus): self
{
$this->phoneRecordingStatus = $phoneRecordingStatus;
return $this;
}
/**
* {@inheritDoc}
*/
public function jsonSerialize(): array
{
$data = [
'id' => $this->getId(),
'uid' => $this->getUid() ? $this->getUid()->toString() : null,
'method' => $this->getMethodName(),
];
switch ($this->getMethod()) {
case self::METHODS__SPEECH:
$data['speech'] = $this->getSpeechText();
break;
}
return $data;
}
}