<?php
namespace App\Entity\Telegram\AgentPublicBot;
use App\Entity\BaseEntity;
use App\Repository\Telegram\AgentPublicBot\BotCampaignRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
#[ORM\Entity(repositoryClass: BotCampaignRepository::class)]
class BotCampaign extends BaseEntity
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private ?string $id = null;
#[ORM\Column(length: 255)]
private ?string $title = null;
#[ORM\ManyToOne(inversedBy: 'botCampaigns')]
#[ORM\JoinColumn(nullable: false)]
private ?Bot $bot = null;
#[ORM\OneToMany(mappedBy: 'campaign', targetEntity: BotUser::class)]
private Collection $botUsers;
public function __toString()
{
return $this->getTitle();
}
public function botUsersCount()
{
return count($this->botUsers);
}
public function __construct()
{
parent::__construct();
$this->botUsers = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
public function getBot(): ?Bot
{
return $this->bot;
}
public function setBot(?Bot $bot): static
{
$this->bot = $bot;
return $this;
}
/**
* @return Collection<int, BotUser>
*/
public function getBotUsers(): Collection
{
return $this->botUsers;
}
public function addBotUser(BotUser $botUser): static
{
if (!$this->botUsers->contains($botUser)) {
$this->botUsers->add($botUser);
$botUser->setCampaign($this);
}
return $this;
}
public function removeBotUser(BotUser $botUser): static
{
if ($this->botUsers->removeElement($botUser)) {
// set the owning side to null (unless already changed)
if ($botUser->getCampaign() === $this) {
$botUser->setCampaign(null);
}
}
return $this;
}
}