<?php
namespace App\Entity;
use App\Entity\Generic\User;
use App\Repository\CampaignRepository;
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: CampaignRepository::class)]
class Campaign extends BaseEntity
{
#[ORM\Id]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
#[ORM\Column(type: 'guid', unique: true)]
private ?string $id = null;
#[ORM\Column(length: 255)]
private ?string $slug = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\Column(nullable: true)]
private ?int $count = null;
#[ORM\OneToMany(mappedBy: 'campaign', targetEntity: User::class)]
private Collection $users;
#[ORM\Column(nullable: true)]
private ?int $views = null;
public function __construct()
{
parent::__construct();
$this->users = new ArrayCollection();
}
public function __toString()
{
return $this->getName();
}
public function getId(): ?string
{
return $this->id;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): static
{
$this->slug = $slug;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getCount(): ?int
{
return count($this->getUsers());
}
public function setCount(?int $count): static
{
$this->count = $count;
return $this;
}
/**
* @return Collection<int, User>
*/
public function getUsers(): Collection
{
return $this->users;
}
public function addUser(User $user): static
{
if (!$this->users->contains($user)) {
$this->users->add($user);
$user->setCampaign($this);
}
return $this;
}
public function removeUser(User $user): static
{
if ($this->users->removeElement($user)) {
// set the owning side to null (unless already changed)
if ($user->getCampaign() === $this) {
$user->setCampaign(null);
}
}
return $this;
}
public function getViews(): ?int
{
return $this->views;
}
public function setViews(?int $views): static
{
$this->views = $views;
return $this;
}
}