src/Entity/TelegramCampaignParticipant.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\TelegramCampaignParticipant\SendStatus;
  4. use App\Repository\TelegramCampaignParticipantRepository;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Entity(repositoryClass=TelegramCampaignParticipantRepository::class)
  8.  */
  9. class TelegramCampaignParticipant
  10. {
  11.     /**
  12.      * @ORM\Id
  13.      * @ORM\GeneratedValue
  14.      * @ORM\Column(type="integer")
  15.      */
  16.     private $id;
  17.     /**
  18.      * @ORM\ManyToOne(targetEntity=Candidate::class)
  19.      */
  20.     private $candidate;
  21.     /**
  22.      * @ORM\ManyToOne(targetEntity=TelegramCampaign::class, inversedBy="participants")
  23.      */
  24.     private $telegramCampaign;
  25.     /**
  26.      * @ORM\Column(type="enum", options={"values": "telegram_campaign_participant_enum"})
  27.      */
  28.     private $sendStatus SendStatus::SEND_STATUS_NOT_SENT;
  29.     /**
  30.      * @ORM\Column(type="datetime")
  31.      */
  32.     private $createdAt;
  33.     /**
  34.      * @ORM\Column(type="text", nullable=true)
  35.      */
  36.     private $responseData;
  37.     /**
  38.      * @ORM\Column(type="datetime", nullable=true)
  39.      */
  40.     private $sentAt;
  41.     /**
  42.      * @ORM\ManyToOne(targetEntity=Person::class)
  43.      */
  44.     private $person;
  45.     /**
  46.      * @ORM\Column(type="text", nullable=true)
  47.      */
  48.     private $errorText;
  49.     /**
  50.      * @ORM\Column(type="smallint", nullable=true)
  51.      */
  52.     private $checkDeliveryTrysCount;
  53.     public function __construct()
  54.     {
  55.         $this->createdAt = new \DateTime();
  56.     }
  57.     public function getId(): ?int
  58.     {
  59.         return $this->id;
  60.     }
  61.     public function getCandidate(): ?Candidate
  62.     {
  63.         return $this->candidate;
  64.     }
  65.     public function setCandidate(?Candidate $candidate): self
  66.     {
  67.         $this->candidate $candidate;
  68.         return $this;
  69.     }
  70.     public function getTelegramCampaign(): ?TelegramCampaign
  71.     {
  72.         return $this->telegramCampaign;
  73.     }
  74.     public function setTelegramCampaign(?TelegramCampaign $telegramCampaign): self
  75.     {
  76.         $this->telegramCampaign $telegramCampaign;
  77.         return $this;
  78.     }
  79.     public function getSendStatus()
  80.     {
  81.         return $this->sendStatus;
  82.     }
  83.     public function isSendStatusCanceled(): bool
  84.     {
  85.         return $this->getSendStatus() === SendStatus::SEND_STATUS_CANCELED;
  86.     }
  87.     public function isSendStatusNotSent(): bool
  88.     {
  89.         return $this->getSendStatus() === SendStatus::SEND_STATUS_NOT_SENT;
  90.     }
  91.     public function isSendStatusDeliveryCheck(): bool
  92.     {
  93.         return $this->getSendStatus() === SendStatus::SEND_STATUS_DELIVERY_CHECK;
  94.     }
  95.     public function canRemoveFromCampaign(): bool
  96.     {
  97.         return in_array($this->getSendStatus(), SendStatus::getCampaignRemovableStatuses());
  98.     }
  99.     public function canCancelFromCampaign(): bool
  100.     {
  101.         return in_array($this->getSendStatus(), SendStatus::getCampaignCancelableStatuses());
  102.     }
  103.     public function getSendStatusText(): string
  104.     {
  105.         return SendStatus::getText($this->sendStatus);
  106.     }
  107.     public function setSendStatus($sendStatus): self
  108.     {
  109.         $this->sendStatus $sendStatus;
  110.         if ($sendStatus === SendStatus::SEND_STATUS_SENT) {
  111.             $this->setSentAt(new \DateTime());
  112.         }
  113.         return $this;
  114.     }
  115.     public function getCreatedAt(): ?\DateTimeInterface
  116.     {
  117.         return $this->createdAt;
  118.     }
  119.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  120.     {
  121.         $this->createdAt $createdAt;
  122.         return $this;
  123.     }
  124.     public function getSendStatusCssClass($prefix null): string
  125.     {
  126.         return SendStatus::getCssClass($this->sendStatus$prefix);
  127.     }
  128.     public function getResponseData(): ?array
  129.     {
  130.         return json_decode($this->responseData ?? "{}"true);
  131.     }
  132.     public function setResponseData(?array $responseData): self
  133.     {
  134.         $this->responseData json_encode($responseData,
  135.             JSON_UNESCAPED_SLASHES JSON_UNESCAPED_UNICODE);
  136.         return $this;
  137.     }
  138.     public function appendResponseDataItem(array $responseDataItem): self
  139.     {
  140.         $allData $this->getResponseData() ?? [];
  141.         $allData[] = $responseDataItem;
  142.         $this->setResponseData($allData);
  143.         return $this;
  144.     }
  145.     public function setResponseDataItem(array $responseDataItemint $key): self
  146.     {
  147.         $allData $this->getResponseData() ?? [];
  148.         $allData[$key] = $responseDataItem;
  149.         $this->setResponseData($allData);
  150.         return $this;
  151.     }
  152.     public function getSentAt(): ?\DateTimeInterface
  153.     {
  154.         return $this->sentAt;
  155.     }
  156.     public function setSentAt(?\DateTimeInterface $sentAt): self
  157.     {
  158.         $this->sentAt $sentAt;
  159.         return $this;
  160.     }
  161.     public function getPerson(): ?Person
  162.     {
  163.         if ($this->getCandidate() !== null) {
  164.             return $this->getCandidate()->getPerson();
  165.         }
  166.         return $this->person;
  167.     }
  168.     public function setPerson(?Person $person): self
  169.     {
  170.         $this->person $person;
  171.         return $this;
  172.     }
  173.     public function getErrorText(): ?string
  174.     {
  175.         if ($this->getSendStatus() != SendStatus::SEND_STATUS_ERROR) {
  176.             return null;
  177.         }
  178.         return $this->errorText;
  179.     }
  180.     private function setErrorText(?string $errorText): self
  181.     {
  182.         $this->errorText $errorText;
  183.         return $this;
  184.     }
  185.     public function appendErrorText(string $errorText): self
  186.     {
  187.         $currentErrorText $this->getErrorText();
  188.         if ($currentErrorText) {
  189.             $newErrorText rtrim($currentErrorText".") . ".\n" $errorText;
  190.         } else {
  191.             $newErrorText $errorText;
  192.         }
  193.         return $this->setErrorText($newErrorText);
  194.     }
  195.     public function getCheckDeliveryTrysCount(): ?int
  196.     {
  197.         return $this->checkDeliveryTrysCount;
  198.     }
  199.     public function setCheckDeliveryTrysCount(?int $checkDeliveryTrysCount): self
  200.     {
  201.         $this->checkDeliveryTrysCount $checkDeliveryTrysCount;
  202.         return $this;
  203.     }
  204.     public function increaseCheckDeliveryTrysCount(): self
  205.     {
  206.         $this->checkDeliveryTrysCount = ($this->checkDeliveryTrysCount ?? 0) + 1;
  207.         return $this;
  208.     }
  209.     public function isMaxCheckDeliveryTrysCount(int $maxTrys 3): bool
  210.     {
  211.         return $this->checkDeliveryTrysCount !== null && $this->checkDeliveryTrysCount >= $maxTrys;
  212.     }
  213. }