src/Entity/TelegramCampaign.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\TelegramCampaign\Status;
  4. use App\Enum\TelegramCampaign\Type;
  5. use App\Enum\TelegramCampaignMessage\Insert;
  6. use App\Repository\TelegramCampaignRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. /**
  11.  * @ORM\Entity(repositoryClass=TelegramCampaignRepository::class)
  12.  */
  13. class TelegramCampaign
  14. {
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.     /**
  22.      * @ORM\Column(type="enum", nullable=true, options={"values": "telegram_campaign_enum"})
  23.      */
  24.     private $type;
  25.     /**
  26.      * @ORM\ManyToOne(targetEntity=CalendarEvent::class)
  27.      */
  28.     private $calendarEvent;
  29.     /**
  30.      * @ORM\Column(type="string", length=255, nullable=true)
  31.      */
  32.     private $title;
  33.     /**
  34.      * @ORM\OneToMany(targetEntity=TelegramCampaignParticipant::class, mappedBy="telegramCampaign")
  35.      */
  36.     private $participants;
  37.     /**
  38.      * @ORM\Column(type="enum", options={"values"="telegram_campaign_enum", "default"="active"})
  39.      */
  40.     private $status Status::STATUS_ACTIVE;
  41.     /**
  42.      * @ORM\OneToMany(targetEntity=TelegramCampaignMessage::class, mappedBy="telegramCampaign")
  43.      */
  44.     private $messages;
  45.     /**
  46.      * Должен быть явно указан.
  47.      * @ORM\Column(type="boolean")
  48.      */
  49.     private $isAutoCampaignMessages;
  50.     public function __construct()
  51.     {
  52.         $this->participants = new ArrayCollection();
  53.         $this->messages = new ArrayCollection();
  54.     }
  55.     public function getId(): ?int
  56.     {
  57.         return $this->id;
  58.     }
  59.     public function getType()
  60.     {
  61.         return $this->type;
  62.     }
  63.     public function setType($type): self
  64.     {
  65.         $this->type $type;
  66.         return $this;
  67.     }
  68.     public function getTypeText(): string
  69.     {
  70.         if ($this->type) {
  71.             return Type::getText($this->type);
  72.         }
  73.         return 'Информационная рассылка';
  74.     }
  75.     public function getCalendarEvent(): ?CalendarEvent
  76.     {
  77.         return $this->calendarEvent;
  78.     }
  79.     public function setCalendarEvent(?CalendarEvent $calendarEvent): self
  80.     {
  81.         $this->calendarEvent $calendarEvent;
  82.         return $this;
  83.     }
  84.     public function getTitle(): ?string
  85.     {
  86.         return $this->title;
  87.     }
  88.     public function setTitle(?string $title): self
  89.     {
  90.         $this->title $title;
  91.         return $this;
  92.     }
  93.     /**
  94.      * @return Collection<int, TelegramCampaignParticipant>
  95.      */
  96.     public function getParticipants(): Collection
  97.     {
  98.         return $this->participants;
  99.     }
  100.     public function addParticipant(TelegramCampaignParticipant $participant): self
  101.     {
  102.         if (!$this->participants->contains($participant)) {
  103.             $this->participants[] = $participant;
  104.             $participant->setTelegramCampaign($this);
  105.         }
  106.         return $this;
  107.     }
  108.     public function removeParticipant(TelegramCampaignParticipant $participant): self
  109.     {
  110.         if ($this->participants->removeElement($participant)) {
  111.             // set the owning side to null (unless already changed)
  112.             if ($participant->getTelegramCampaign() === $this) {
  113.                 $participant->setTelegramCampaign(null);
  114.             }
  115.         }
  116.         return $this;
  117.     }
  118.     public function hasParticipantCandidate(Candidate $candidate): bool
  119.     {
  120.         foreach ($this->getParticipants() as $participant) {
  121.             if ($participant->getCandidate()->getId() === $candidate->getId()) {
  122.                 return true;
  123.             }
  124.         }
  125.         return false;
  126.     }
  127.     public function hasParticipantPerson(Person $person): bool
  128.     {
  129.         foreach ($this->getParticipants() as $participant) {
  130.             if (($participant->getCandidate() !== null && $participant->getCandidate()->getPerson()->getId() == $person->getId())
  131.                 || $participant->getPerson()->getId() == $person->getId()) {
  132.                 return true;
  133.             }
  134.         }
  135.         return false;
  136.     }
  137.     public function getStatus()
  138.     {
  139.         return $this->status;
  140.     }
  141.     public function setStatus($status): self
  142.     {
  143.         $this->status $status;
  144.         return $this;
  145.     }
  146.     public function isActive(): bool
  147.     {
  148.         return $this->getStatus() === Status::STATUS_ACTIVE;
  149.     }
  150.     public function isPaused(): bool
  151.     {
  152.         return $this->getStatus() === Status::STATUS_PAUSE;
  153.     }
  154.     public function isDeleted(): bool
  155.     {
  156.         return $this->getStatus() === Status::STATUS_DELETED;
  157.     }
  158.     /**
  159.      * @return Collection<int, TelegramCampaignMessage>
  160.      */
  161.     public function getMessages(): Collection
  162.     {
  163.         return $this->messages;
  164.     }
  165.     public function addMessage(TelegramCampaignMessage $message): self
  166.     {
  167.         if (!$this->messages->contains($message)) {
  168.             $this->messages[] = $message;
  169.             $message->setTelegramCampaign($this);
  170.         }
  171.         return $this;
  172.     }
  173.     public function removeMessage(TelegramCampaignMessage $message): self
  174.     {
  175.         if ($this->messages->removeElement($message)) {
  176.             // set the owning side to null (unless already changed)
  177.             if ($message->getTelegramCampaign() === $this) {
  178.                 $message->setTelegramCampaign(null);
  179.             }
  180.         }
  181.         return $this;
  182.     }
  183.     public function hasMessageWithPaymentRequisites(): bool
  184.     {
  185.         /**@var TelegramCampaignMessage $message */
  186.         foreach ($this->messages as $message) {
  187.             if ($message->isSendPaymentRequisites()) {
  188.                 return true;
  189.             }
  190.         }
  191.         return false;
  192.     }
  193.     public function hasMessageWithCalendarEventPriceInsert(): bool
  194.     {
  195.         /**@var TelegramCampaignMessage $message */
  196.         foreach ($this->messages as $message) {
  197.             if (str_contains($message->getText(), "[" Insert::INSERT_CALENDAR_EVENT_PRICE "]")) {
  198.                 return true;
  199.             }
  200.         }
  201.         return false;
  202.     }
  203.     public function isIsAutoCampaignMessages(): ?bool
  204.     {
  205.         return $this->isAutoCampaignMessages;
  206.     }
  207.     public function setIsAutoCampaignMessages(?bool $isAutoCampaignMessages): self
  208.     {
  209.         $this->isAutoCampaignMessages $isAutoCampaignMessages;
  210.         return $this;
  211.     }
  212. }