src/Entity/Campaign.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Generic\User;
  4. use App\Repository\CampaignRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  9. #[ORM\Entity(repositoryClassCampaignRepository::class)]
  10. class Campaign extends BaseEntity
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue(strategy'CUSTOM')]
  14.     #[ORM\CustomIdGenerator(class: UuidGenerator::class)]
  15.     #[ORM\Column(type'guid'uniquetrue)]
  16.     private ?string $id null;
  17.     #[ORM\Column(length255)]
  18.     private ?string $slug null;
  19.     #[ORM\Column(length255)]
  20.     private ?string $name null;
  21.     #[ORM\Column(nullabletrue)]
  22.     private ?int $count null;
  23.     #[ORM\OneToMany(mappedBy'campaign'targetEntityUser::class)]
  24.     private Collection $users;
  25.     #[ORM\Column(nullabletrue)]
  26.     private ?int $views null;
  27.     public function __construct()
  28.     {
  29.         parent::__construct();
  30.         $this->users = new ArrayCollection();
  31.     }
  32.     public function __toString()
  33.     {
  34.         return $this->getName();
  35.     }
  36.     public function getId(): ?string
  37.     {
  38.         return $this->id;
  39.     }
  40.     public function getSlug(): ?string
  41.     {
  42.         return $this->slug;
  43.     }
  44.     public function setSlug(string $slug): static
  45.     {
  46.         $this->slug $slug;
  47.         return $this;
  48.     }
  49.     public function getName(): ?string
  50.     {
  51.         return $this->name;
  52.     }
  53.     public function setName(string $name): static
  54.     {
  55.         $this->name $name;
  56.         return $this;
  57.     }
  58.     public function getCount(): ?int
  59.     {
  60.         return count($this->getUsers());
  61.     }
  62.     public function setCount(?int $count): static
  63.     {
  64.         $this->count $count;
  65.         return $this;
  66.     }
  67.     /**
  68.      * @return Collection<int, User>
  69.      */
  70.     public function getUsers(): Collection
  71.     {
  72.         return $this->users;
  73.     }
  74.     public function addUser(User $user): static
  75.     {
  76.         if (!$this->users->contains($user)) {
  77.             $this->users->add($user);
  78.             $user->setCampaign($this);
  79.         }
  80.         return $this;
  81.     }
  82.     public function removeUser(User $user): static
  83.     {
  84.         if ($this->users->removeElement($user)) {
  85.             // set the owning side to null (unless already changed)
  86.             if ($user->getCampaign() === $this) {
  87.                 $user->setCampaign(null);
  88.             }
  89.         }
  90.         return $this;
  91.     }
  92.     public function getViews(): ?int
  93.     {
  94.         return $this->views;
  95.     }
  96.     public function setViews(?int $views): static
  97.     {
  98.         $this->views $views;
  99.         return $this;
  100.     }
  101. }