src/Products/NotificationsBundle/Entity/Recording.php line 22

Open in your IDE?
  1. <?php
  2. namespace Products\NotificationsBundle\Entity;
  3. use Cms\TenantBundle\Entity\TenantedEntity;
  4. use DateTime;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use JsonSerializable;
  7. use Reinder83\BinaryFlags\Bits;
  8. /**
  9.  * Class Recording
  10.  * @package Products\NotificationsBundle\Entity
  11.  *
  12.  * @ORM\Entity(
  13.  *     repositoryClass = "Products\NotificationsBundle\Doctrine\Repository\RecordingRepository",
  14.  * )
  15.  * @ORM\Table(
  16.  *     name = "notis__recording",
  17.  * )
  18.  */
  19. class Recording extends TenantedEntity implements JsonSerializable
  20. {
  21.     const METHODS = [
  22.         'upload' => self::METHODS__UPLOAD,
  23.         'browser' => self::METHODS__BROWSER,
  24.         'speech' => self::METHODS__SPEECH,
  25.         'phone' => self::METHODS__PHONE,
  26.     ];
  27.     const METHODS__NONE 0;
  28.     const METHODS__UPLOAD Bits::BIT_1;
  29.     const METHODS__BROWSER Bits::BIT_2;
  30.     const METHODS__SPEECH Bits::BIT_3;
  31.     const METHODS__PHONE Bits::BIT_4;
  32.     /**
  33.      * @var int
  34.      *
  35.      * @ORM\Column(
  36.      *     type = "integer",
  37.      *     nullable = false,
  38.      *     options = {
  39.      *         "default" = self::METHODS__NONE,
  40.      *         "unsigned" = true,
  41.      *     },
  42.      * )
  43.      */
  44.     protected int $method self::METHODS__NONE;
  45.     /**
  46.      * @var DateTime|null
  47.      *
  48.      * @ORM\Column(
  49.      *     type = "datetime",
  50.      *     nullable = true,
  51.      * )
  52.      */
  53.     protected ?DateTime $recordedAt null;
  54.     /**
  55.      * @var string|null
  56.      *
  57.      * @ORM\Column(
  58.      *     type = "text",
  59.      *     nullable = true,
  60.      * )
  61.      */
  62.     protected ?string $speechText null;
  63.     /**
  64.      * @var string|null
  65.      *
  66.      * @ORM\Column(
  67.      *     type = "string",
  68.      *     nullable = true,
  69.      * )
  70.      */
  71.     protected ?string $speechTaskId null;
  72.     /**
  73.      * @var string|null
  74.      *
  75.      * @ORM\Column(
  76.      *     type = "string",
  77.      *     nullable = true,
  78.      * )
  79.      */
  80.     protected ?string $phoneCallId null;
  81.     /**
  82.      * @var string|null
  83.      *
  84.      * @ORM\Column(
  85.      *     type = "string",
  86.      *     nullable = true,
  87.      * )
  88.      */
  89.     protected ?string $phoneRecordingId null;
  90.     /**
  91.      * @var string|null
  92.      *
  93.      * @ORM\Column(
  94.      *     type = "string",
  95.      *     nullable = true,
  96.      * )
  97.      */
  98.     protected ?string $phoneRecordingUrl null;
  99.     /**
  100.      * @var string|null
  101.      *
  102.      * @ORM\Column(
  103.      *     type = "string",
  104.      *     nullable = true,
  105.      * )
  106.      */
  107.     protected ?string $phoneRecordingStatus null;
  108.     /**
  109.      * @return string|null
  110.      */
  111.     public function getSpeechTaskId(): ?string
  112.     {
  113.         return $this->speechTaskId;
  114.     }
  115.     /**
  116.      * @param string|null $speechTaskId
  117.      * @return $this
  118.      */
  119.     public function setSpeechTaskId(?string $speechTaskId): self
  120.     {
  121.         $this->speechTaskId $speechTaskId;
  122.         return $this;
  123.     }
  124.     /**
  125.      * @return string|null
  126.      */
  127.     public function getSpeechText(): ?string
  128.     {
  129.         return $this->speechText;
  130.     }
  131.     /**
  132.      * @param string|null $speechText
  133.      * @return $this
  134.      */
  135.     public function setSpeechText(?string $speechText): self
  136.     {
  137.         $this->speechText $speechText;
  138.         return $this;
  139.     }
  140.     /**
  141.      * @return int
  142.      */
  143.     public function getMethod(): int
  144.     {
  145.         return $this->method;
  146.     }
  147.     /**
  148.      * @return string
  149.      */
  150.     public function getMethodName(): string
  151.     {
  152.         return array_search($this->getMethod(), self::METHODS) ?? 'none';
  153.     }
  154.     /**
  155.      * @param int $method
  156.      * @return $this
  157.      */
  158.     public function setMethod(int $method): self
  159.     {
  160.         $this->method $method;
  161.         return $this;
  162.     }
  163.     /**
  164.      * @return bool
  165.      */
  166.     public function hasMethod(): bool
  167.     {
  168.         return ($this->getMethod() !== self::METHODS__NONE);
  169.     }
  170.     /**
  171.      * @param int|string $method
  172.      * @return bool
  173.      */
  174.     public function isMethod($method): bool
  175.     {
  176.         if (is_string($method) && array_key_exists($methodself::METHODS)) {
  177.             $method self::METHODS[$method];
  178.         }
  179.         if ( ! is_int($method) || ! in_array($methodself::METHODS)) {
  180.             throw new \Exception();
  181.         }
  182.         return ($this->getMethod() === $method);
  183.     }
  184.     /**
  185.      * @return bool
  186.      */
  187.     public function isRecorded(): bool
  188.     {
  189.         return ( ! empty($this->getRecordedAt()));
  190.     }
  191.     /**
  192.      * @return DateTime|null
  193.      */
  194.     public function getRecordedAt(): ?DateTime
  195.     {
  196.         return $this->recordedAt;
  197.     }
  198.     /**
  199.      * @param DateTime|null $recordedAt
  200.      * @return $this
  201.      */
  202.     public function setRecordedAt(?DateTime $recordedAt): self
  203.     {
  204.         $this->recordedAt $recordedAt;
  205.         return $this;
  206.     }
  207.     /**
  208.      * @return string|null
  209.      */
  210.     public function getPhoneCallId(): ?string
  211.     {
  212.         return $this->phoneCallId;
  213.     }
  214.     /**
  215.      * @param string|null $phoneCallId
  216.      * @return $this
  217.      */
  218.     public function setPhoneCallId(?string $phoneCallId): self
  219.     {
  220.         $this->phoneCallId $phoneCallId;
  221.         return $this;
  222.     }
  223.     /**
  224.      * @return string|null
  225.      */
  226.     public function getPhoneRecordingId(): ?string
  227.     {
  228.         return $this->phoneRecordingId;
  229.     }
  230.     /**
  231.      * @param string|null $phoneRecordingId
  232.      * @return $this
  233.      */
  234.     public function setPhoneRecordingId(?string $phoneRecordingId): self
  235.     {
  236.         $this->phoneRecordingId $phoneRecordingId;
  237.         return $this;
  238.     }
  239.     /**
  240.      * @return string|null
  241.      */
  242.     public function getPhoneRecordingUrl(): ?string
  243.     {
  244.         return $this->phoneRecordingUrl;
  245.     }
  246.     /**
  247.      * @param string|null $phoneRecordingUrl
  248.      * @return $this
  249.      */
  250.     public function setPhoneRecordingUrl(?string $phoneRecordingUrl): self
  251.     {
  252.         $this->phoneRecordingUrl $phoneRecordingUrl;
  253.         return $this;
  254.     }
  255.     /**
  256.      * @return string|null
  257.      */
  258.     public function getPhoneRecordingStatus(): ?string
  259.     {
  260.         return $this->phoneRecordingStatus;
  261.     }
  262.     /**
  263.      * @param string|null $phoneRecordingStatus
  264.      * @return $this
  265.      */
  266.     public function setPhoneRecordingStatus(?string $phoneRecordingStatus): self
  267.     {
  268.         $this->phoneRecordingStatus $phoneRecordingStatus;
  269.         return $this;
  270.     }
  271.     /**
  272.      * {@inheritDoc}
  273.      */
  274.     public function jsonSerialize(): array
  275.     {
  276.         $data = [
  277.             'id' => $this->getId(),
  278.             'uid' => $this->getUid() ? $this->getUid()->toString() : null,
  279.             'method' => $this->getMethodName(),
  280.         ];
  281.         switch ($this->getMethod()) {
  282.             case self::METHODS__SPEECH:
  283.                 $data['speech'] = $this->getSpeechText();
  284.                 break;
  285.         }
  286.         return $data;
  287.     }
  288. }