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.             || $sendStatus === SendStatus::SEND_STATUS_DELIVERY_CHECK) {
  112.             $this->setSentAt(new \DateTime());
  113.         }
  114.         return $this;
  115.     }
  116.     public function getCreatedAt(): ?\DateTimeInterface
  117.     {
  118.         return $this->createdAt;
  119.     }
  120.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  121.     {
  122.         $this->createdAt $createdAt;
  123.         return $this;
  124.     }
  125.     public function getSendStatusCssClass($prefix null): string
  126.     {
  127.         return SendStatus::getCssClass($this->sendStatus$prefix);
  128.     }
  129.     public function getResponseData(): ?array
  130.     {
  131.         return json_decode($this->responseData ?? "{}"true);
  132.     }
  133.     public function setResponseData(?array $responseData): self
  134.     {
  135.         $this->responseData json_encode($responseData,
  136.             JSON_UNESCAPED_SLASHES JSON_UNESCAPED_UNICODE);
  137.         return $this;
  138.     }
  139.     public function appendResponseDataItem(array $responseDataItem): self
  140.     {
  141.         $allData $this->getResponseData() ?? [];
  142.         $allData[] = $responseDataItem;
  143.         $this->setResponseData($allData);
  144.         return $this;
  145.     }
  146.     public function setResponseDataItem(array $responseDataItemint $key): self
  147.     {
  148.         $allData $this->getResponseData() ?? [];
  149.         $allData[$key] = $responseDataItem;
  150.         $this->setResponseData($allData);
  151.         return $this;
  152.     }
  153.     public function getSentAt(): ?\DateTimeInterface
  154.     {
  155.         return $this->sentAt;
  156.     }
  157.     public function setSentAt(?\DateTimeInterface $sentAt): self
  158.     {
  159.         $this->sentAt $sentAt;
  160.         return $this;
  161.     }
  162.     public function getPerson(): ?Person
  163.     {
  164.         if ($this->getCandidate() !== null) {
  165.             return $this->getCandidate()->getPerson();
  166.         }
  167.         return $this->person;
  168.     }
  169.     public function setPerson(?Person $person): self
  170.     {
  171.         $this->person $person;
  172.         return $this;
  173.     }
  174.     public function getErrorText(): ?string
  175.     {
  176.         if ($this->getSendStatus() != SendStatus::SEND_STATUS_ERROR) {
  177.             return null;
  178.         }
  179.         return $this->errorText;
  180.     }
  181.     private function setErrorText(?string $errorText): self
  182.     {
  183.         $this->errorText $errorText;
  184.         return $this;
  185.     }
  186.     public function appendErrorText(string $errorText): self
  187.     {
  188.         $currentErrorText $this->getErrorText();
  189.         if ($currentErrorText) {
  190.             $newErrorText rtrim($currentErrorText".") . ".\n" $errorText;
  191.         } else {
  192.             $newErrorText $errorText;
  193.         }
  194.         return $this->setErrorText($newErrorText);
  195.     }
  196.     public function getCheckDeliveryTrysCount(): ?int
  197.     {
  198.         return $this->checkDeliveryTrysCount;
  199.     }
  200.     public function setCheckDeliveryTrysCount(?int $checkDeliveryTrysCount): self
  201.     {
  202.         $this->checkDeliveryTrysCount $checkDeliveryTrysCount;
  203.         return $this;
  204.     }
  205.     public function increaseCheckDeliveryTrysCount(): self
  206.     {
  207.         $this->checkDeliveryTrysCount = ($this->checkDeliveryTrysCount ?? 0) + 1;
  208.         return $this;
  209.     }
  210.     public function isMaxCheckDeliveryTrysCount(int $maxTrys 3): bool
  211.     {
  212.         return $this->checkDeliveryTrysCount !== null && $this->checkDeliveryTrysCount >= $maxTrys;
  213.     }
  214. }