<?php
namespace App\Entity;
use App\Enum\TelegramCampaignParticipant\SendStatus;
use App\Repository\TelegramCampaignParticipantRepository;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=TelegramCampaignParticipantRepository::class)
*/
class TelegramCampaignParticipant
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=Candidate::class)
*/
private $candidate;
/**
* @ORM\ManyToOne(targetEntity=TelegramCampaign::class, inversedBy="participants")
*/
private $telegramCampaign;
/**
* @ORM\Column(type="enum", options={"values": "telegram_campaign_participant_enum"})
*/
private $sendStatus = SendStatus::SEND_STATUS_NOT_SENT;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $responseData;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $sentAt;
public function __construct()
{
$this->createdAt = new \DateTime();
}
public function getId(): ?int
{
return $this->id;
}
public function getCandidate(): ?Candidate
{
return $this->candidate;
}
public function setCandidate(?Candidate $candidate): self
{
$this->candidate = $candidate;
return $this;
}
public function getTelegramCampaign(): ?TelegramCampaign
{
return $this->telegramCampaign;
}
public function setTelegramCampaign(?TelegramCampaign $telegramCampaign): self
{
$this->telegramCampaign = $telegramCampaign;
return $this;
}
public function getSendStatus()
{
return $this->sendStatus;
}
public function isSendStatusCanceled(): bool
{
return $this->getSendStatus() === SendStatus::SEND_STATUS_CANCELED;
}
public function isSendStatusNotSent(): bool
{
return $this->getSendStatus() === SendStatus::SEND_STATUS_NOT_SENT;
}
public function canRemoveFromCampaign(): bool
{
return in_array($this->getSendStatus(), SendStatus::getCampaignRemovableStatuses());
}
public function canCancelFromCampaign(): bool
{
return in_array($this->getSendStatus(), SendStatus::getCampaignCancelableStatuses());
}
public function getSendStatusText(): string
{
return SendStatus::getText($this->sendStatus);
}
public function setSendStatus($sendStatus): self
{
$this->sendStatus = $sendStatus;
if ($sendStatus === SendStatus::SEND_STATUS_SENT) {
$this->setSentAt(new \DateTime());
}
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getSendStatusCssClass($prefix = null): string
{
return SendStatus::getCssClass($this->sendStatus, $prefix);
}
public function getResponseData(): ?array
{
return json_decode($this->responseData ?? "{}", true);
}
public function setResponseData(?array $responseData): self
{
$this->responseData = json_encode($responseData,
JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
return $this;
}
public function appendResponseDataItem(array $responseDataItem): self
{
$allData = $this->getResponseData() ?? [];
$allData[] = $responseDataItem;
$this->setResponseData($allData);
return $this;
}
public function setResponseDataItem(array $responseDataItem, int $key): self
{
$allData = $this->getResponseData() ?? [];
$allData[$key] = $responseDataItem;
$this->setResponseData($allData);
return $this;
}
public function getSentAt(): ?\DateTimeInterface
{
return $this->sentAt;
}
public function setSentAt(?\DateTimeInterface $sentAt): self
{
$this->sentAt = $sentAt;
return $this;
}
}